Skip to content

Commit dbc4c76

Browse files
committed
fix (+each) component bindings
1 parent db35336 commit dbc4c76

File tree

6 files changed

+28
-72
lines changed

6 files changed

+28
-72
lines changed

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "maskjs",
3-
"version": "0.72.43",
3+
"version": "0.72.46",
44
"homepage": "https://github.com/atmajs/MaskJS",
55
"authors": [
66
"Alex Kit <[email protected]>"

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "maskjs",
33
"description": "Template / Markup / HMVC Engine",
4-
"version": "0.72.43",
4+
"version": "0.72.46",
55
"homepage": "http://atmajs.com/mask",
66
"contributors": [
77
{

projects/mask-binding/src/statements/loop/each.ts

+21-25
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,17 @@ const EachBinded = {
1414
meta: {
1515
serializeNodes: true
1616
},
17-
serializeNodes: function(node){
17+
serializeNodes (node){
1818
return mask_stringify(node);
1919
},
2020
//modelRef: null,
21-
render: function(model, ctx, container, ctr, children){
21+
render (model, ctx, container, ctr, children){
2222
//this.modelRef = this.expression;
23-
var array = expression_eval(this.expression, model, ctx, ctr);
24-
if (array == null)
23+
let array = expression_eval(this.expression, model, ctx, ctr);
24+
if (array == null) {
2525
return;
26-
26+
}
2727
arr_createRefs(array);
28-
2928
build(
3029
this.nodes,
3130
array,
@@ -36,8 +35,8 @@ const EachBinded = {
3635
);
3736
},
3837

39-
renderEnd: function(els, model, ctx, container, ctr){
40-
var compo = new EachStatement(this, this.attr);
38+
renderEnd (els, model, ctx, container, ctr){
39+
let compo = new EachStatement(this, this.attr);
4140

4241
_renderPlaceholder(this, compo, container);
4342
_compo_initAndBind(compo, this, model, ctx, container, ctr);
@@ -46,34 +45,34 @@ const EachBinded = {
4645

4746
};
4847

49-
var EachItem = class_create({
48+
const EachItem = class_create({
5049
compoName: 'each::item',
5150
scope: null,
5251
model: null,
5352
modelRef: null,
5453
parent: null,
5554
//#if (NODE)
56-
renderStart: function(){
57-
var expr = this.parent.expression;
55+
renderStart (){
56+
let expr = this.parent.expression;
5857
this.modelRef = ''
5958
+ (expr === '.' ? '' : ('(' + expr + ')'))
6059
+ '."'
6160
+ this.scope.index
6261
+ '"';
6362
},
6463
//#endif
65-
renderEnd: function(els) {
64+
renderEnd (els) {
6665
this.elements = els;
6766
},
68-
dispose: function(){
67+
dispose (){
6968
if (this.elements != null) {
7069
this.elements.length = 0;
7170
this.elements = null;
7271
}
7372
}
7473
});
7574

76-
var EachStatement = class_create(ALoopBindedStatement, {
75+
const EachStatement = class_create(ALoopBindedStatement, {
7776
compoName: '+each',
7877
constructor: function EachStatement(node, attr) {
7978
this.expression = node.expression;
@@ -85,13 +84,13 @@ var EachStatement = class_create(ALoopBindedStatement, {
8584
this.node = node;
8685
this.components = node.components;
8786
},
88-
_getModel: function(compo) {
87+
_getModel (compo) {
8988
return compo.model;
9089
},
91-
_build: function(node, model, ctx, component) {
92-
var fragment = _document.createDocumentFragment();
90+
build (model) {
91+
let fragment = _document.createDocumentFragment();
9392

94-
build(node.nodes, model, ctx, fragment, component);
93+
build(this.node.nodes, model, {}, fragment, this);
9594

9695
return fragment;
9796
}
@@ -100,18 +99,15 @@ var EachStatement = class_create(ALoopBindedStatement, {
10099
// METHODS
101100

102101
function build(nodes, array, ctx, container, ctr, elements?) {
103-
var imax = array.length,
104-
nodes_ = new Array(imax),
105-
i = 0, node;
106-
107-
for(; i < imax; i++) {
108-
node = createEachNode(nodes, i);
102+
let imax = array.length;
103+
for(let i = 0; i < imax; i++) {
104+
let node = createEachNode(nodes, i);
109105
builder_build(node, array[i], ctx, container, ctr, elements);
110106
}
111107
}
112108

113109
function createEachNode(nodes, index){
114-
var item = new EachItem;
110+
let item = new EachItem;
115111
item.scope = { index: index };
116112

117113
return {

projects/mask-binding/src/statements/loop/for.ts

-41
Original file line numberDiff line numberDiff line change
@@ -46,47 +46,6 @@ export class ObservableFor extends ALoopBindedStatement {
4646
this._beforeRender();
4747
}
4848

49-
// render (model, ctx, container, ctr, children){
50-
// const directive = For.parseFor(this.expression);
51-
// const attr = this.attr;
52-
53-
// attr[attr_PROP_1] = directive[0];
54-
// attr[attr_PROP_2] = directive[1];
55-
// attr[attr_TYPE] = directive[2];
56-
// attr[attr_EXPR] = directive[3];
57-
58-
// let subs = expression_subscribe(
59-
// directive[3]
60-
// , model
61-
// , ctx
62-
// , ctr
63-
// , this.onChanged
64-
// , is_NODE ? true : false
65-
// );
66-
67-
// let value = expression_eval(directive[3], model, ctx, ctr);
68-
// if (value == null) {
69-
// return;
70-
// }
71-
72-
// if (is_Array(value)) {
73-
// arr_createRefs(value);
74-
// }
75-
76-
// For.build(
77-
// value,
78-
// directive,
79-
// this.nodes,
80-
// model,
81-
// ctx,
82-
// container,
83-
// this,
84-
// children
85-
// );
86-
// }
87-
88-
89-
9049
getHandler (name, model){
9150
return For.getHandler(name, model);
9251
}

projects/mask-binding/src/statements/utils.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,20 @@ export function _compo_initAndBind(
2424
container,
2525
controller
2626
) {
27+
const expr: string = compo.expr ?? compo.expression ?? node.expression;
2728
compo.parent = controller;
2829
compo.model = model;
2930
compo.ctx = ctx;
3031
compo.refresh = fn_proxy(compo.refresh, compo);
3132
compo.binder = expression_createBinder(
32-
compo.expr || compo.expression,
33+
expr,
3334
model,
3435
ctx,
3536
controller,
3637
compo.refresh
3738
);
3839
expression_bind(
39-
compo.expr || compo.expression,
40+
expr,
4041
model,
4142
ctx,
4243
controller,

0 commit comments

Comments
 (0)