deee
Ruby
code posted
created at 22 Jan 00:33
Edit
|
Back
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
function QueueObject(model, fn, args, type) { var queue = []; var model = model; var fn = fn; var args = args; this.push = function (queueObject) { queue.push(queueObject); } this.run = function() { var action = function() { var modelOrPromise = fn.call(model, args); if (modelOrPromise.then) { modelOrPromise.then(function() { if (model.get('actionQueue')) {model.get('actionQueue').next()} }) } else { if (model.get('actionQueue')) {model.get('actionQueue').next()} } } if (model.get('isDeleted')) { model.set('actionQueue', null); } else if (model.get('isSaving')) { model.one('didSave', action); } else { action.call(); } } this.next = function () { var next = queue.shift(); if (next) { next.run(); } else { model.set('actionQueue', null); } } } |
949 Bytes in 3 ms with coderay