Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions dist/regular.js
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ return /******/ (function(modules) { // webpackBootstrap
}
return paramObj;
}
_.eventReg = /^on-(\w[-\w]+)$/;
_.eventReg = /^on-(\w[-\w]*)$/;

_.toText = function(obj){
return obj == null ? "": "" + obj;
Expand Down Expand Up @@ -4906,12 +4906,16 @@ return /******/ (function(modules) { // webpackBootstrap
value = self._touchExpr(value);
// use bit operate to control scope
if( !(isolate & 2) )
// sync data from parent to child
this.$watch(value, (function(name, val){
this.data[name] = val;
}).bind(component, name), OPTIONS.SYNC)
if( value.set && !(isolate & 1 ) )
// sync the data. it force the component don't trigger attr.name's first dirty echeck
component.$watch(name, self.$update.bind(self, value), OPTIONS.INIT);
// sync data from child to parent. it force the component don't trigger attr.name's first dirty echeck
component.$watch(name, self.$update.bind(self, value), {
init: true,
last: this.data[ name ]
});
}
}
if(is && is.type === 'expression' ){
Expand Down
7 changes: 3 additions & 4 deletions dist/regular.min.js

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions lib/walkers.js
Original file line number Diff line number Diff line change
Expand Up @@ -713,12 +713,16 @@ walkers.component = function(ast, options){
value = self._touchExpr(value);
// use bit operate to control scope
if( !(isolate & 2) )
// sync data from parent to child
this.$watch(value, (function(name, val){
this.data[name] = val;
}).bind(component, name), OPTIONS.SYNC)
if( value.set && !(isolate & 1 ) )
// sync the data. it force the component don't trigger attr.name's first dirty echeck
component.$watch(name, self.$update.bind(self, value), OPTIONS.INIT);
// sync data from child to parent. it force the component don't trigger attr.name's first dirty echeck
component.$watch(name, self.$update.bind(self, value), {
init: true,
last: this.data[ name ]
});
}
}
if(is && is.type === 'expression' ){
Expand Down
46 changes: 46 additions & 0 deletions test/spec/browser-bugfix.js
Original file line number Diff line number Diff line change
Expand Up @@ -1433,4 +1433,50 @@ it('bugfix #50', function(){
})
})

describe("M 0.6.3", function(){
it('bugfix#235 - should sync data from child to parent with string', function(){
var Child = Regular.extend({
template: '{ foo }',
init: function() {
this.data.foo = 'changed'
},
});

var Parent = Regular.extend({
template: '{foo}\n<Child foo="{ foo }"></Child>',
config: function() {
this.data.foo = 'bar'
}
});

Parent.component('Child', Child);

var parent = new Parent();

expect(parent.data.foo).to.equal('changed');
})

it('bugfix#235 - should sync data from child to parent with undefined', function(){
var Child = Regular.extend({
template: '{ foo }',
init: function() {
this.data.foo = undefined
},
});

var Parent = Regular.extend({
template: '{foo}\n<Child foo="{ foo }"></Child>',
config: function() {
this.data.foo = 'bar'
}
});

Parent.component('Child', Child);

var parent = new Parent()

expect(parent.data.foo).to.equal(undefined);
})
})

})