loopback-ds-changed-mixin icon indicating copy to clipboard operation
loopback-ds-changed-mixin copied to clipboard

Define callback methods on the model programatically

Open beeman opened this issue 9 years ago • 0 comments

This is copied from #5


In a future version it would be nice the possibility of adding the logic of this mixin programatically:

/**
 * var changed = {
 *   ids: {
 *     '123': 'processing',
 *     '456': 'processing',
 *     '789': 'on-hold'
 *   },
 *   values: {
 *     'processing': ['123', '456'],
 *     'on-hold': ['789']
 *   }
 * }
 */
Fulfillment.onChanged('status', function(changed) {
    // do first thing on changed status
});

Fulfillment.onChanged('status', function(changed) {
    // do another thing on changed status
});

And even watch a specific property value:

/**
 * var changed =  ['123', '456'];
 */
Fulfillment.onChangedValue('status', 'cancelled', function(changed) {
    // this is triggered when status changed to cancelled
});

beeman avatar Jun 23 '15 22:06 beeman