Skip to content

Commit

Permalink
fix(collections): listen for sort event when using backbone 1.1.2 or …
Browse files Browse the repository at this point in the history
…above

We do this conditionally to avoid any potential issues for people who may be calling a sort event on their collection manually
  • Loading branch information
ewanharris committed Jun 6, 2019
1 parent 9f0b0ac commit e206f14
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 8 additions & 2 deletions Alloy/commands/compile/compilerUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,12 @@ exports.validateNodeName = function(node, names) {

exports.generateCollectionBindingTemplate = function(args) {
var code = '';
var COLLECTION_BINDING_EVENTS = CONST.COLLECTION_BINDING_EVENTS_092;

// Check if not 0.9.2 and if it's a supported version as we'll default to 0.9.2 if the version is not supported
if (compilerConfig.backbone !== '0.9.2' && CONST.SUPPORTED_BACKBONE_VERSIONS.includes(compilerConfig.backbone)) {
COLLECTION_BINDING_EVENTS = CONST.COLLECTION_BINDING_EVENTS;
}

// Determine the collection variable to use
var obj = { name: args[CONST.BIND_COLLECTION] };
Expand Down Expand Up @@ -1015,10 +1021,10 @@ exports.generateCollectionBindingTemplate = function(args) {
code += ' }';
code += '<%= post %>';
code += '};';
code += colVar + ".on('" + CONST.COLLECTION_BINDING_EVENTS + "'," + handlerFunc + ');';
code += colVar + ".on('" + COLLECTION_BINDING_EVENTS + "'," + handlerFunc + ');';

exports.destroyCode += colVar + ' && ' + ((args.parentFormFactor) ? 'Alloy.is' + U.ucfirst(args.parentFormFactor) + ' && ' : '' ) +
colVar + ".off('" + CONST.COLLECTION_BINDING_EVENTS + "'," + handlerFunc + ');';
colVar + ".off('" + COLLECTION_BINDING_EVENTS + "'," + handlerFunc + ');';

return code;
};
3 changes: 2 additions & 1 deletion Alloy/common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ exports.BIND_TRANSFORM_VAR = '__transform';
exports.BIND_MODEL_VAR = '$model';
exports.MODEL_ELEMENTS = ['Alloy.Collection', 'Alloy.Model'];
exports.MODEL_BINDING_EVENTS = 'fetch change destroy';
exports.COLLECTION_BINDING_EVENTS = 'fetch destroy change add remove reset';
exports.COLLECTION_BINDING_EVENTS = 'fetch destroy change add remove reset sort';
exports.COLLECTION_BINDING_EVENTS_092 = 'fetch destroy change add remove reset';

// Constants for properties shared between ActionBar and Toolbar on Android
exports.BACKGROUND_IMAGE = 'backgroundImage';
Expand Down

0 comments on commit e206f14

Please sign in to comment.