Skip to content

Commit f9b1c7b

Browse files
committed
- support refering to view root with name @.
- support multiple arguments in `render` function.
1 parent 616dd51 commit f9b1c7b

File tree

11 files changed

+59
-16
lines changed

11 files changed

+59
-16
lines changed

CHANGELOG.md

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

3+
## v0.2.1
4+
5+
- support refering to view root with name `@`.
6+
- support multiple arguments in `render` function.
7+
8+
39
## v0.2.0
410

511
- only check direct parent instead of ancestor to verify if ld-each node has been processed.

dist/index.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@
183183
});
184184
this.nodes = this.nodes.concat(nodes);
185185
prefixRE = this.prefix ? new RegExp("^" + this.prefix + "\\$") : null;
186-
return nodes.map(function(node){
186+
nodes.map(function(node){
187187
var names;
188188
names = (node.getAttribute(this$.ld) || "").split(' ');
189189
if (this$.prefix) {
@@ -201,6 +201,14 @@
201201
});
202202
});
203203
});
204+
if (!this.map.nodes['@']) {
205+
return this.map.nodes['@'] = [{
206+
node: this.root,
207+
names: '@',
208+
local: {},
209+
evts: {}
210+
}];
211+
}
204212
},
205213
procEach: function(name, data, key){
206214
var list, getkey, hash, items, nodes, proxyIndex, ns, i$, i, n, j, node, idx, expectedIdx, _, this$ = this;
@@ -413,7 +421,12 @@
413421
return obj.nodes.splice(idx, 1);
414422
},
415423
render: function(names){
416-
var _, i$, ref$, len$, k, this$ = this;
424+
var args, res$, i$, to$, _, ref$, len$, k, this$ = this;
425+
res$ = [];
426+
for (i$ = 1, to$ = arguments.length; i$ < to$; ++i$) {
427+
res$.push(arguments[i$]);
428+
}
429+
args = res$;
417430
this.fire('beforeRender');
418431
_ = function(n){
419432
var ref$, key;
@@ -437,9 +450,9 @@
437450
}
438451
};
439452
if (names) {
440-
(Array.isArray(names)
453+
((Array.isArray(names)
441454
? names
442-
: [names]).map(function(it){
455+
: [names]).concat(args)).map(function(it){
443456
return _(it);
444457
});
445458
} else {

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: 1 addition & 1 deletion
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
@@ -4,7 +4,7 @@
44
"license": "MIT",
55
"main": "dist/ldview.min.js",
66
"description": "view template micro framework",
7-
"version": "0.2.0",
7+
"version": "0.2.1",
88
"files": [
99
"dist/**/*"
1010
],

src/ldview.ls

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ ldview.prototype = Object.create(Object.prototype) <<< do
100100
names = (node.getAttribute(@ld) or "").split(' ')
101101
if @prefix => names = names.map -> it.replace(prefixRE,"").trim!
102102
names.map ~> @map.nodes[][it].push {node, names, local: {}, evts: {}}
103+
if !@map.nodes['@'] => @map.nodes['@'] = [{node: @root, names: '@', local: {}, evts: {}}]
103104

104105
# TODO
105106
# we should remove nodes from @map if they are updated and have ld/ld-each attribute removed.
@@ -205,7 +206,8 @@ ldview.prototype = Object.create(Object.prototype) <<< do
205206
if node and !idx => idx = obj.nodes.indexOf(node)
206207
return obj.nodes.splice idx, 1
207208

208-
render: (names) ->
209+
render: (names, ...args) ->
210+
209211
@fire \beforeRender
210212
_ = (n) ~>
211213
if typeof(n) == \object =>
@@ -216,7 +218,7 @@ ldview.prototype = Object.create(Object.prototype) <<< do
216218
@_render n,d,i
217219
if @map.eaches[n] and @handler[n] => @map.eaches[n].map ~> @proc-each n, it, key
218220

219-
if names => (if Array.isArray(names) => names else [names]).map -> _ it
221+
if names => ((if Array.isArray(names) => names else [names]) ++ args).map -> _ it
220222
else for k in @names => _(k)
221223
@fire \afterRender
222224

web/src/ls/index.ls

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
data.slice start, end
1515
view:
1616
handler:
17+
'@': ({node, ctx, ctxs}) ->
18+
node.style
19+
..background = <[#ecb #bfc #bcf]>[Math.floor(Math.random! * 3)]
1720
title: ({node, ctx, ctxs}) -> node.innerText = ctx.title
1821
description: ({node, ctx, ctxs}) -> node.innerText = ctx.description
1922
date:({node, ctx, ctxs, views}) -> node.innerText = ctxs.0.time

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@
183183
});
184184
this.nodes = this.nodes.concat(nodes);
185185
prefixRE = this.prefix ? new RegExp("^" + this.prefix + "\\$") : null;
186-
return nodes.map(function(node){
186+
nodes.map(function(node){
187187
var names;
188188
names = (node.getAttribute(this$.ld) || "").split(' ');
189189
if (this$.prefix) {
@@ -201,6 +201,14 @@
201201
});
202202
});
203203
});
204+
if (!this.map.nodes['@']) {
205+
return this.map.nodes['@'] = [{
206+
node: this.root,
207+
names: '@',
208+
local: {},
209+
evts: {}
210+
}];
211+
}
204212
},
205213
procEach: function(name, data, key){
206214
var list, getkey, hash, items, nodes, proxyIndex, ns, i$, i, n, j, node, idx, expectedIdx, _, this$ = this;
@@ -413,7 +421,12 @@
413421
return obj.nodes.splice(idx, 1);
414422
},
415423
render: function(names){
416-
var _, i$, ref$, len$, k, this$ = this;
424+
var args, res$, i$, to$, _, ref$, len$, k, this$ = this;
425+
res$ = [];
426+
for (i$ = 1, to$ = arguments.length; i$ < to$; ++i$) {
427+
res$.push(arguments[i$]);
428+
}
429+
args = res$;
417430
this.fire('beforeRender');
418431
_ = function(n){
419432
var ref$, key;
@@ -437,9 +450,9 @@
437450
}
438451
};
439452
if (names) {
440-
(Array.isArray(names)
453+
((Array.isArray(names)
441454
? names
442-
: [names]).map(function(it){
455+
: [names]).concat(args)).map(function(it){
443456
return _(it);
444457
});
445458
} else {

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.

web/static/js/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// Generated by LiveScript 1.3.1
21
(function(){
32
var ctx, data, view;
43
ctx = {
@@ -23,6 +22,13 @@
2322
},
2423
view: {
2524
handler: {
25+
'@': function(arg$){
26+
var node, ctx, ctxs, x$;
27+
node = arg$.node, ctx = arg$.ctx, ctxs = arg$.ctxs;
28+
x$ = node.style;
29+
x$.background = ['#ecb', '#bfc', '#bcf'][Math.floor(Math.random() * 3)];
30+
return x$;
31+
},
2632
title: function(arg$){
2733
var node, ctx, ctxs;
2834
node = arg$.node, ctx = arg$.ctx, ctxs = arg$.ctxs;

0 commit comments

Comments
 (0)