Skip to content

Commit 7465e4e

Browse files
committed
v31 trackers bug fix
1 parent 0df3a42 commit 7465e4e

File tree

5 files changed

+137
-111
lines changed

5 files changed

+137
-111
lines changed

.versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ [email protected]
77
88
99
10-
10+
1111
1212
1313

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
"type": "git",
1212
"url": "https://github.com/meteorwebcomponents/mixin.git"
1313
},
14-
"version": "1.0.30",
14+
"version": "1.0.31",
1515
"ignore":["mwc-mixin.js","package.js"]
1616
}

mwc-mixin.html

Lines changed: 102 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -3,83 +3,105 @@
33
window.mwcMixin = {
44

55
properties: {
6-
subsReady:{type:Boolean,notify:true,value:true},
7-
8-
mwcData:Object,
9-
__mwcHandles:{type:Array,value:[]},
10-
__mwcComputations:{type:Array,value:[]},
11-
__mwcComputationsIds:{type:Array,value:[]},
12-
__mwcBin:{type:Array,value:[]}
6+
subsReady: { type: Boolean, notify: true, value: true },
7+
mwcData: Object,
8+
__mwcHandles: { type: Array, value: [] },
9+
__mwcPush: { type: Array, value: [] },
10+
__mwcComputations: { type: Array, value: [] },
11+
__mwcComputationsIds: { type: Array, value: [] },
12+
__mwcBin: { type: Array, value: [] }
1313
},
14-
trackers:[],
15-
_mwcSetData(data){
16-
this.set("mwcData",data);
14+
trackers: [],
15+
_mwcSetData: function _mwcSetData(data) {
16+
this.set("mwcData", data);
1717
},
18-
beforeRegister(){
19-
this.__mwcDeps = {};
20-
this.observers = this.observers || [];
21-
for(let i = 0;i < this.trackers.length;i++){
22-
const tracker = this.trackers[i];
23-
const sections = tracker.split(/[\(,\)]+/);
24-
const input = sections[1];
25-
const cb = sections[0];
26-
const r_id = `__mwc_${Random.id(10)}`;
27-
const dep = new Tracker.Dependency();
28-
this.__mwcDeps[tracker] = {_id:r_id,dep:dep,cb:cb};
29-
this[r_id] = (...arg)=>{
30-
this.__mwcDeps[tracker].arg = arg;
31-
this.__mwcDeps[tracker].dep.changed();
18+
beforeRegister: function beforeRegister() {
19+
var _this = this;
20+
21+
var mwcDeps = {};
22+
var observers = this.observers || [];
23+
var trackers = this.trackers;
24+
//console.log("elem",trackers);
25+
26+
var _loop = function _loop(i) {
27+
var tracker = trackers[i];
28+
var sections = tracker.split(/[\(\)]+/);
29+
var input = sections[1];
30+
var cb = sections[0];
31+
var r_id = "__mwc_" + Random.id(10);
32+
var obj = {
33+
_id: r_id,
34+
cb: cb
35+
};
36+
mwcDeps[tracker] = obj;
37+
var _trObFn = function _trObFn() {
38+
var arg = arguments;
39+
var dep = obj;
40+
dep.dep = this.__mwcDeps[tracker].dep || new Tracker.Dependency();
41+
dep.arg = arg;
42+
this.__mwcDeps[tracker] = dep;
43+
this.__mwcDeps[tracker] = _.clone(this.__mwcDeps[tracker]);
44+
dep.dep.changed();
3245
};
46+
_this[r_id] = _trObFn;
47+
observers.push(r_id + "(" + input + ")");
48+
};
3349

34-
this.observers.push(`${r_id}(${input})`);
50+
for (var i = 0; i < trackers.length; i++) {
51+
_loop(i);
3552
}
53+
this.observers = observers;
54+
this.__mwcDeps = mwcDeps;
3655
},
37-
attached() {
56+
attached: function attached() {
57+
var _this2 = this;
58+
3859
this.__mwcFirstRun = true;
39-
for(let i in this.__mwcDeps){
40-
const tracker = this.__mwcDeps[i];
41-
const obFn = (c)=>{
42-
tracker.dep.depend();
43-
this[tracker.cb].apply(this,tracker.arg);
60+
61+
var _loop2 = function _loop2(i) {
62+
var obFn = function obFn(c) {
63+
_this2.__mwcDeps[i].dep = _this2.__mwcDeps[i].dep || new Tracker.Dependency();
64+
_this2.__mwcDeps[i].dep.depend();
65+
_this2[_this2.__mwcDeps[i].cb].apply(_this2, _this2.__mwcDeps[i].arg);
66+
_this2.__mwcDeps = _.clone(_this2.__mwcDeps);
4467
};
45-
this.autorun(obFn.bind(null,this));
68+
_this2.autorun(obFn.bind(_this2));
69+
};
70+
71+
for (var i in this.__mwcDeps) {
72+
_loop2(i);
4673
}
4774
this.autorun(this.tracker);
48-
this.autorun(mwcDataUpdate.bind(null,this));
75+
this.autorun(mwcDataUpdate.bind(null, this));
4976
},
50-
detached() {
51-
for(let i in this.__mwcDeps){
52-
const tracker = this.__mwcDeps[i];
53-
delete this[tracker[`_id`]];
54-
}
55-
delete this.__mwcDeps;
56-
_.each(this.__mwcComputations,(c)=>{
77+
detached: function detached() {
78+
_.each(this.__mwcComputations, function (c) {
5779
c.stop();
5880
});
5981
this.__mwcComputations = [];
60-
this.__mwcHandles.forEach((h)=>{
82+
this.__mwcHandles.forEach(function (h) {
6183
h.stop();
6284
});
63-
this.__mwcBin.forEach((h)=>{
85+
this.__mwcBin.forEach(function (h) {
6486
h.stop();
6587
});
66-
6788
},
68-
_mwcPush(p,val) {
69-
let prop = _.clone(this[p]);
89+
_mwcPush: function _mwcPush(p, val) {
90+
var prop = _.clone(this[p]);
7091
prop.push(val);
71-
this.set(p,prop);
92+
this.set(p, prop);
7293
},
73-
guard(f) {
94+
guard: function guard(f) {
7495
if (Meteor.isServer || !Tracker.currentComputation) {
7596
return f();
7697
}
7798

78-
let dep = new Tracker.Dependency();
99+
var dep = new Tracker.Dependency();
79100
dep.depend();
80101

81-
let value, newValue;
82-
Tracker.autorun(comp => {
102+
var value = void 0,
103+
newValue = void 0;
104+
Tracker.autorun(function (comp) {
83105
newValue = f();
84106
if (!comp.firstRun && !EJSON.equals(newValue, value)) {
85107
dep.changed();
@@ -88,63 +110,59 @@
88110
});
89111

90112
return newValue;
91-
92113
},
93-
autorun(f){
94-
const cb = (c)=> {
95-
if(!_.find(this.__mwcComputationsIds,(_id)=>{
114+
autorun: function autorun(f) {
115+
var _this3 = this;
116+
117+
var cb = function cb(c) {
118+
if (!_.find(_this3.__mwcComputationsIds, function (_id) {
96119
return _id == c._id;
97-
})){
98-
this._mwcPush("__mwcComputationsIds",c._id);
99-
this._mwcPush("__mwcComputations",c);
120+
})) {
121+
_this3._mwcPush("__mwcComputationsIds", c._id);
122+
_this3._mwcPush("__mwcComputations", c);
100123
}
101-
f.bind(this)(c);
124+
f.bind(_this3)(c);
102125
};
103126
return Tracker.autorun(cb.bind(this));
104-
105127
},
106-
_removeSubs(val){
107-
const handles = _.reject(_.clone(this.__mwcHandles),(h)=>{
108-
if(h.subscriptionId == val.subscriptionId){
128+
_removeSubs: function _removeSubs(val) {
129+
var handles = _.reject(_.clone(this.__mwcHandles), function (h) {
130+
if (h.subscriptionId == val.subscriptionId) {
109131
return true;
110132
}
111133
});
112-
this._mwcPush('__mwcBin',val);
113-
this.set("__mwcHandles",handles);
114-
134+
this._mwcPush('__mwcBin', val);
135+
this.set("__mwcHandles", handles);
115136
},
116-
subscribe() {
117-
const handle = Meteor.subscribe.apply(null,arguments);
118-
this._mwcPush("__mwcHandles",handle);
137+
subscribe: function subscribe() {
138+
var _this4 = this;
139+
140+
var handle = Meteor.subscribe.apply(null, arguments);
141+
this._mwcPush("__mwcHandles", handle);
119142
this._subsReady();
120-
const afterSub = (c)=>{
143+
var afterSub = function afterSub(c) {
121144
if (handle.ready()) {
122-
this._removeSubs(handle);
123-
this._subsReady();
145+
_this4._removeSubs(handle);
146+
_this4._subsReady();
124147
c.stop();
125-
126148
}
127149
};
128150
this.autorun(afterSub.bind(this));
129151

130152
return handle;
131153
},
132-
_subsReady(h) {
133-
const isReady = _.every(this.__mwcHandles, (sub)=> {
154+
_subsReady: function _subsReady(h) {
155+
var isReady = _.every(this.__mwcHandles, function (sub) {
134156
return sub && sub.ready();
135157
});
136-
this.set("subsReady",isReady);
158+
this.set("subsReady", isReady);
137159
return isReady;
138160
},
139-
140-
getMeteorData(){
141-
},
142-
tracker(){
143-
144-
}
161+
getMeteorData: function getMeteorData() {},
162+
tracker: function tracker() {}
145163
};
146-
const mwcDataUpdate = (element)=> {
147-
const data = element.getMeteorData();
164+
var mwcDataUpdate = function mwcDataUpdate(element) {
165+
var data = element.getMeteorData();
148166
// if(element.getMeteorData()){
149167
// console.log("Use tracker instead of getMeteorData");
150168
// }
@@ -158,7 +176,7 @@
158176
return;
159177
}
160178

161-
Tracker.afterFlush(()=> {
179+
Tracker.afterFlush(function () {
162180
element._mwcSetData(data);
163181
});
164182
};

mwc-mixin.js

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ mwcMixin = {
33

44
properties: {
55
subsReady:{type:Boolean,notify:true,value:true},
6-
76
mwcData:Object,
87
__mwcHandles:{type:Array,value:[]},
8+
__mwcPush:{type:Array,value:[]},
99
__mwcComputations:{type:Array,value:[]},
1010
__mwcComputationsIds:{type:Array,value:[]},
1111
__mwcBin:{type:Array,value:[]}
@@ -15,43 +15,51 @@ mwcMixin = {
1515
this.set("mwcData",data);
1616
},
1717
beforeRegister(){
18-
this.__mwcDeps = {};
19-
this.observers = this.observers || [];
20-
for(let i = 0;i < this.trackers.length;i++){
21-
const tracker = this.trackers[i];
22-
const sections = tracker.split(/[\(,\)]+/);
18+
const mwcDeps = {};
19+
const observers = this.observers || [];
20+
const trackers = this.trackers;
21+
//console.log("elem",trackers);
22+
for(let i = 0;i < trackers.length;i++){
23+
const tracker = trackers[i];
24+
const sections = tracker.split(/[\(\)]+/);
2325
const input = sections[1];
2426
const cb = sections[0];
2527
const r_id = `__mwc_${Random.id(10)}`;
26-
const dep = new Tracker.Dependency();
27-
this.__mwcDeps[tracker] = {_id:r_id,dep:dep,cb:cb};
28-
this[r_id] = (...arg)=>{
29-
this.__mwcDeps[tracker].arg = arg;
30-
this.__mwcDeps[tracker].dep.changed();
28+
const obj = {
29+
_id : r_id,
30+
cb : cb
3131
};
32-
33-
this.observers.push(`${r_id}(${input})`);
32+
mwcDeps[tracker] = obj;
33+
const _trObFn = function(){
34+
const arg = arguments;
35+
const dep = obj;
36+
dep.dep = this.__mwcDeps[tracker].dep || new Tracker.Dependency();
37+
dep.arg = arg;
38+
this.__mwcDeps[tracker] = dep;
39+
this.__mwcDeps[tracker] = _.clone(this.__mwcDeps[tracker]);
40+
dep.dep.changed();
41+
};
42+
this[r_id] = _trObFn;
43+
observers.push(`${r_id}(${input})`);
3444
}
45+
this.observers = observers;
46+
this.__mwcDeps = mwcDeps;
3547
},
3648
attached() {
3749
this.__mwcFirstRun = true;
3850
for(let i in this.__mwcDeps){
39-
const tracker = this.__mwcDeps[i];
40-
const obFn = (c)=>{
41-
tracker.dep.depend();
42-
this[tracker.cb].apply(this,tracker.arg);
51+
const obFn = c => {
52+
this.__mwcDeps[i].dep = this.__mwcDeps[i].dep || new Tracker.Dependency();
53+
this.__mwcDeps[i].dep.depend();
54+
this[this.__mwcDeps[i].cb].apply(this,this.__mwcDeps[i].arg);
55+
this.__mwcDeps = _.clone(this.__mwcDeps);
4356
};
44-
this.autorun(obFn.bind(null,this));
57+
this.autorun(obFn.bind(this));
4558
}
4659
this.autorun(this.tracker);
4760
this.autorun(mwcDataUpdate.bind(null,this));
4861
},
4962
detached() {
50-
for(let i in this.__mwcDeps){
51-
const tracker = this.__mwcDeps[i];
52-
delete this[tracker[`_id`]];
53-
}
54-
delete this.__mwcDeps;
5563
_.each(this.__mwcComputations,(c)=>{
5664
c.stop();
5765
});
@@ -142,7 +150,7 @@ mwcMixin = {
142150

143151
}
144152
};
145-
const mwcDataUpdate = (element)=> {
153+
const mwcDataUpdate = element => {
146154
const data = element.getMeteorData();
147155
// if(element.getMeteorData()){
148156
// console.log("Use tracker instead of getMeteorData");

package.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package.describe({
22
name: 'mwc:mixin',
3-
version: '1.0.30',
3+
version: '1.0.31',
44
summary: 'Reactive Data Mixin For Polymer',
55
git: "https://github.com/meteorwebcomponents/mixin.git",
66
documentation: "README.md"

0 commit comments

Comments
 (0)