Skip to content

Commit 78d8fb2

Browse files
committed
regen
1 parent defd70c commit 78d8fb2

File tree

5 files changed

+37
-9
lines changed

5 files changed

+37
-9
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
- remove `setContext()` and `setCtx()`, in favor of `ctx()`.
88

99

10-
## v1.5.2 (upcoming)
10+
## v1.6.0
11+
12+
- support ctx in nested view with parameters as handlers
13+
14+
15+
## v1.5.2
1116

1217
- remove @loadingio/ldquery dependency
1318
- upgrade dependencies

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,17 @@ It can also be accomplished via `template`, which is by default scoped:
449449
handler: ...
450450
});
451451

452+
You can also define a ctx function, with parent ctx in its parameter:
453+
454+
new ldview({
455+
ctx: -> { node: { name: "something" }}
456+
handler: localView:
457+
template: ...
458+
ctx: ({ctx}) -> ctx.node
459+
handler: ...
460+
});
461+
462+
452463
check `web/src/pug/scope/index.ls` for a working example of template-based local views.
453464

454465

index.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -389,20 +389,32 @@
389389
if (b) {
390390
if (b.view) {
391391
init = function(arg$){
392-
var node, local, data, ctx, ctxs, views, ref$;
392+
var node, local, data, ctx, ctxs, views, _cfg, ref$, _ctx;
393393
node = arg$.node, local = arg$.local, data = arg$.data, ctx = arg$.ctx, ctxs = arg$.ctxs, views = arg$.views;
394-
local._view = new ldview((ref$ = import$({
394+
_cfg = (ref$ = import$({
395395
ctx: data
396396
}, b.view), ref$.initRender = false, ref$.root = node, ref$.baseViews = views, ref$.ctxs = ctxs
397397
? [ctx].concat(ctxs)
398-
: [ctx], ref$));
398+
: [ctx], ref$);
399+
if (typeof _cfg.ctx === 'function') {
400+
_ctx = _cfg.ctx;
401+
_cfg.ctx = function(opt){
402+
return _ctx(import$({
403+
ctx: data || ctx
404+
}, opt));
405+
};
406+
local._ctx = _ctx;
407+
}
408+
local._view = new ldview(_cfg);
399409
return local._view.init();
400410
};
401-
handler = function(arg$){
411+
handler = function(opt){
402412
var local, data, ctx, ctxs;
403-
local = arg$.local, data = arg$.data, ctx = arg$.ctx, ctxs = arg$.ctxs;
413+
local = opt.local, data = opt.data, ctx = opt.ctx, ctxs = opt.ctxs;
404414
if (e) {
405-
local._view.ctx(data);
415+
local._view.ctx(data || ctx);
416+
} else if (local._ctx) {
417+
local._view.ctx(local._ctx(opt));
406418
}
407419
local._view.ctxs(ctxs
408420
? [ctx].concat(ctxs)

0 commit comments

Comments
 (0)