Last active
September 10, 2015 16:48
-
-
Save cwallenpoole/a6607bdc8e3a052fd2fe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
createInstances(<array of integers>) | |
ItemFinder.find(<int representing ID of item from list>) | |
returns the item which is found or null | |
item.needsUpdate returns something "truthy" or "falsy" (can be 1,true, "cat", null, NaN, undefined, false, etc.) | |
og.notifications.getNotifier() returns a notifier object. It has at least one method "transmit": | |
notifier.transmit({ | |
event: <current-event> | |
item: <related item> | |
position: <position item held in list> | |
}) | |
*/ | |
function createInstances(list){ | |
var item, | |
notifier = og.notifications.getNotifier(), created, updated, total | |
results = {}; | |
for(var i =0; i <= list.length; i++){ | |
total++; | |
item = ItemFinder.find(i); | |
if(!typeof item == 'object') { | |
item = new Item({created: new Date(), | |
updated: new Date()}); | |
created++; | |
} | |
else if(item.needsUpdate()) | |
item.updated(new Date()); | |
else { | |
unchanged++; | |
} | |
item.watch('update', function(evt){ | |
notifier.transmit({event:evt,item:this,position:i});}); | |
item.save(); | |
} | |
return {new:created, updated:updated, old:unchanged, total:totla}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment