Skip to content

Commit ba9a6b5

Browse files
committed
better subsReady
2 parents 1441472 + 3b9e973 commit ba9a6b5

File tree

5 files changed

+45
-41
lines changed

5 files changed

+45
-41
lines changed

.versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ [email protected]
99
1010
1111
12-
12+
1313
1414

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
"type": "git",
1212
"url": "https://github.com/meteorwebcomponents/mixin.git"
1313
},
14-
"version": "1.0.14"
14+
"version": "1.0.15"
1515
}

mwc-mixin.html

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
window.mwcMixin = {
44

55
properties: {
6-
subsReady:{type:Boolean,value:false},
6+
subsReady:{type:Boolean,computed:"_subsReady(__handles)"},
77
mwcData:Object,
88
__handles:{type:Array,value:[]}
99
},
@@ -21,12 +21,6 @@
2121
self.__mwcStateDep.depend();
2222
mwcDataUpdate(self);
2323
});
24-
//if no subscriptions are made make subsReady true.
25-
//this is to give user an users an option to subscribe after attaching the element. load spinner only during subscriptions.
26-
if(!self.__handles.length){
27-
self.set("subsReady",true);
28-
}
29-
3024
},
3125
detatched:function(){
3226
if (this.__mwcComputation) {
@@ -37,28 +31,35 @@
3731
},
3832
subscribe:function(){
3933
self = this;
40-
self.__mwcStateDep.depend();
41-
self.set("subsReady",false);
4234
var handle = Meteor.subscribe.apply(null,arguments);
4335
var handles = _.clone(self.__handles);
4436
handles.push(handle);
4537
self.set("__handles",handles);
4638

47-
var subsReady = function() {
48-
var isReady = _.every(self.__handles, function(sub) {
49-
return sub && sub.ready();
50-
});
51-
52-
return isReady;
53-
};
5439
Tracker.autorun(function(c) {
55-
if (subsReady()) {
56-
self.set("subsReady",true);
57-
c.stop();
40+
try{
41+
if (handle.ready()) {
42+
self.set("__handles",_.reject(_.clone(self.__handles),function(h){
43+
return h.subscriptionId = handle.subscriptionId;
44+
}));
45+
c.stop();
46+
}
5847
}
48+
catch(err){
49+
console.log(err);
50+
}
51+
5952
});
6053
return handle;
6154
},
55+
_subsReady : function(__h) {
56+
var isReady = _.every(__h, function(sub) {
57+
return sub && sub.ready();
58+
});
59+
60+
return isReady;
61+
},
62+
6263
getMeteorData:function(){
6364
}
6465
};
@@ -80,4 +81,6 @@
8081
element.setData(data);
8182
});
8283
}
84+
85+
8386
</script>

mwc-mixin.js

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
mwcMixin = {
22

33
properties: {
4-
subsReady:{type:Boolean,value:false},
4+
subsReady:{type:Boolean,computed:"_subsReady(__handles)"},
55
mwcData:Object,
66
__handles:{type:Array,value:[]}
77
},
@@ -19,12 +19,6 @@ mwcMixin = {
1919
self.__mwcStateDep.depend();
2020
mwcDataUpdate(self);
2121
});
22-
//if no subscriptions are made make subsReady true.
23-
//this is to give user an users an option to subscribe after attaching the element. load spinner only during subscriptions.
24-
if(!self.__handles.length){
25-
self.set("subsReady",true);
26-
}
27-
2822
},
2923
detatched:function(){
3024
if (this.__mwcComputation) {
@@ -35,28 +29,35 @@ mwcMixin = {
3529
},
3630
subscribe:function(){
3731
self = this;
38-
self.__mwcStateDep.depend();
39-
self.set("subsReady",false);
4032
var handle = Meteor.subscribe.apply(null,arguments);
4133
var handles = _.clone(self.__handles);
4234
handles.push(handle);
4335
self.set("__handles",handles);
4436

45-
var subsReady = function() {
46-
var isReady = _.every(self.__handles, function(sub) {
47-
return sub && sub.ready();
48-
});
49-
50-
return isReady;
51-
};
5237
Tracker.autorun(function(c) {
53-
if (subsReady()) {
54-
self.set("subsReady",true);
55-
c.stop();
38+
try{
39+
if (handle.ready()) {
40+
self.set("__handles",_.reject(_.clone(self.__handles),function(h){
41+
return h.subscriptionId = handle.subscriptionId;
42+
}));
43+
c.stop();
44+
}
5645
}
46+
catch(err){
47+
console.log(err);
48+
}
49+
5750
});
5851
return handle;
5952
},
53+
_subsReady : function(__h) {
54+
var isReady = _.every(__h, function(sub) {
55+
return sub && sub.ready();
56+
});
57+
58+
return isReady;
59+
},
60+
6061
getMeteorData:function(){
6162
}
6263
};

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.14',
3+
version: '1.0.15',
44
summary: 'Reactive Data Mixin For Polymer',
55
git: "https://github.com/meteorwebcomponents/mixin.git",
66
documentation: "README.md"

0 commit comments

Comments
 (0)