Titanium JIRA Archive
Alloy (ALOY)

[ALOY-753] Alloy properties adapter 'reset' event fired twice

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2013-07-22T16:31:52.000+0000
Affected Version/sn/a
Fix Version/sAlloy 1.2.0, 2013 Sprint 15
ComponentsModels
Labelsqe-testadded
ReporterJong Eun Lee
AssigneeTony Lukasavage
Created2013-07-20T06:52:55.000+0000
Updated2013-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 {
...
.

Comments

  1. Tony Lukasavage 2013-07-22

    PR: https://github.com/appcelerator/alloy/pull/192
  2. Tony Lukasavage 2013-07-22

    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.
  3. Federico Casali 2013-07-31

    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.

JSON Source