[ALOY-753] Alloy properties adapter 'reset' event fired twice
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2013-07-22T16:31:52.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Alloy 1.2.0, 2013 Sprint 15 |
Components | Models |
Labels | qe-testadded |
Reporter | Jong Eun Lee |
Assignee | Tony Lukasavage |
Created | 2013-07-20T06:52:55.000+0000 |
Updated | 2013-07-31T00:45:14.000+0000 |
Description
When collection fetch, "reset" event fired twice.
user.js
exports.definition = {
config: {
adapter: {
type: "properties",
collection_name: "user"
}
},
extendModel: function(Model) {
_.extend(Model.prototype, {
// extended functions and properties go here
});
return Model;
},
extendCollection: function(Collection) {
_.extend(Collection.prototype, {
// extended functions and properties go here
});
return Collection;
}
}
index.js
var personCol = Alloy.createCollection('user');
personCol.on('reset',function(){
alert('reset');
});
personCol.fetch();
Why properties adapter call reset method in Sync function (19line properties.js)?
function Sync(method, model, opts) {
var prefix = model.config.adapter.collection_name ? model.config.adapter.collection_name : "default";
var regex = new RegExp("^(" + prefix + ")\\-(.+)$");
var resp = null;
if ("read" === method) if (opts.parse) {
var list = [];
_.each(TAP.listProperties(), function(prop) {
var match = prop.match(regex);
null !== match && list.push(TAP.getObject(prop));
});
model.reset(list); // <!--- THIS LINE
resp = list;
} else {
...
.
PR: https://github.com/appcelerator/alloy/pull/192
Original PR: https://github.com/appcelerator/alloy/pull/192 PR with test app: https://github.com/appcelerator/alloy/pull/193 test app: https://github.com/appcelerator/alloy/tree/master/test/apps/testing/ALOY-753 Functional testing can be passed by simply running the test app and confirming that the "reset" alert dialog only pops up one. Before this fix it would have popped up twice.
Verified to be working as expected. Titanium SDK 3.1.2.v20130726192706 Alloy 1.2.0-alpha Appcelerator Studio 3.1.2.201307261628 CLI 3.1.2 Node 0.8.22 Closing.