Skip to content

Commit 1f6fea5

Browse files
committed
- fix bug: proc-each should return Promise, instead of list of Promises
- fix bug: ensure correct initialization order by waiting for init Promise to resolve before render when `init-render` is enabled. - fix bug: nested view initialization should return Promise returned by its own init function call. - bump version
1 parent bc1f3b0 commit 1f6fea5

File tree

8 files changed

+31
-15
lines changed

8 files changed

+31
-15
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Change Logs
22

3+
## v1.1.1
4+
5+
- fix bug: proc-each should return Promise, instead of list of Promises
6+
- fix bug: ensure correct initialization order by waiting for init Promise to resolve before render when `init-render` is enabled.
7+
- fix bug: nested view initialization should return Promise returned by its own init function call.
8+
9+
310
## v1.1.0
411

512
- support promise in `init` ( but not yet support render after init resolve )

dist/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
});
99
};
1010
ldview = function(opt){
11-
var names, i$, ref$, k, v, len$, list, j$, len1$, it, res$;
11+
var names, i$, ref$, k, v, len$, list, j$, len1$, it, res$, this$ = this;
1212
opt == null && (opt = {});
1313
this.evtHandler = {};
1414
this.ctxs = opt.ctxs || null;
@@ -56,7 +56,9 @@
5656
}
5757
this.names = res$;
5858
if (this.initRender) {
59-
this.render();
59+
this.init().then(function(){
60+
return this$.render();
61+
});
6062
}
6163
return this;
6264
function fn$(){
@@ -325,7 +327,7 @@
325327
data.container.update();
326328
}
327329
data.nodes = ns;
328-
return ps;
330+
return Promise.all(ps);
329331
},
330332
get: function(n){
331333
return ((this.map.nodes[n] || [])[0] || {}).node;
@@ -346,11 +348,12 @@
346348
init = function(arg$){
347349
var node, local, data, ctx, ctxs, views, ref$;
348350
node = arg$.node, local = arg$.local, data = arg$.data, ctx = arg$.ctx, ctxs = arg$.ctxs, views = arg$.views;
349-
return local._view = new ldview((ref$ = import$({
351+
local._view = new ldview((ref$ = import$({
350352
ctx: data
351353
}, b.view), ref$.initRender = false, ref$.root = node, ref$.baseViews = views, ref$.ctxs = ctxs
352354
? [ctx].concat(ctxs)
353355
: [ctx], ref$));
356+
return local._view.init();
354357
};
355358
handler = function(arg$){
356359
var local, data;

dist/index.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"browser": "dist/index.min.js",
66
"main": "dist/index.min.js",
77
"description": "view template micro framework",
8-
"version": "1.1.0",
8+
"version": "1.1.1",
99
"files": [
1010
"dist/**/*"
1111
],

src/ldview.ls

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ ldview = (opt = {}) ->
3636
for list in ([[k for k of @initer]] ++ [[k for k of @attr]] ++ [[k for k of @style]] ++ [[k for k of @text]] ++ [[k for k of @handler]] ++ [v for k,v of @action].map (it) -> [k for k of it]) =>
3737
for it in list => names[it] = true
3838
@names = [k for k of names]
39-
if @init-render => @render!
39+
# TODO we don't yet support proxise.once in @init.
40+
# Thus, to be able to wait until init, we have to set init-render to false.
41+
if @init-render => @init!then ~> @render!
4042
@
4143

4244
ldview.prototype = Object.create(Object.prototype) <<< do
@@ -173,7 +175,7 @@ ldview.prototype = Object.create(Object.prototype) <<< do
173175
ps = _.map (it,i) ~> @_render name, it._obj, i, @handler[name], true, init-only
174176
if data.container.update => data.container.update!
175177
data.nodes = ns
176-
return ps
178+
return Promise.all(ps)
177179

178180
get: (n) -> ((@map.nodes[n] or []).0 or {}).node
179181
getAll: (n) -> (@map.nodes[n] or []).map -> it.node
@@ -192,6 +194,7 @@ ldview.prototype = Object.create(Object.prototype) <<< do
192194
init-render: false, root: node, base-views: views
193195
ctxs: (if ctxs => [ctx] ++ ctxs else [ctx])
194196
})
197+
local._view.init!
195198
handler = ({local,data}) ->
196199
if e => local._view.setCtx(data)
197200
local._view.render!

web/static/assets/lib/ldview/dev/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
});
99
};
1010
ldview = function(opt){
11-
var names, i$, ref$, k, v, len$, list, j$, len1$, it, res$;
11+
var names, i$, ref$, k, v, len$, list, j$, len1$, it, res$, this$ = this;
1212
opt == null && (opt = {});
1313
this.evtHandler = {};
1414
this.ctxs = opt.ctxs || null;
@@ -56,7 +56,9 @@
5656
}
5757
this.names = res$;
5858
if (this.initRender) {
59-
this.render();
59+
this.init().then(function(){
60+
return this$.render();
61+
});
6062
}
6163
return this;
6264
function fn$(){
@@ -325,7 +327,7 @@
325327
data.container.update();
326328
}
327329
data.nodes = ns;
328-
return ps;
330+
return Promise.all(ps);
329331
},
330332
get: function(n){
331333
return ((this.map.nodes[n] || [])[0] || {}).node;
@@ -346,11 +348,12 @@
346348
init = function(arg$){
347349
var node, local, data, ctx, ctxs, views, ref$;
348350
node = arg$.node, local = arg$.local, data = arg$.data, ctx = arg$.ctx, ctxs = arg$.ctxs, views = arg$.views;
349-
return local._view = new ldview((ref$ = import$({
351+
local._view = new ldview((ref$ = import$({
350352
ctx: data
351353
}, b.view), ref$.initRender = false, ref$.root = node, ref$.baseViews = views, ref$.ctxs = ctxs
352354
? [ctx].concat(ctxs)
353355
: [ctx], ref$));
356+
return local._view.init();
354357
};
355358
handler = function(arg$){
356359
var local, data;

web/static/assets/lib/ldview/dev/index.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)