Last active
August 29, 2015 14:06
-
-
Save mrinterweb/2642c26d4b0ea0ff819b to your computer and use it in GitHub Desktop.
This file contains 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
App.FriendCache = Em.Object.extend | |
init: -> | |
@store = App.__container__.lookup('store:main') | |
findAll: -> | |
localforage.getItem('friends').then (cfriends)=> | |
if Em.isEmpty(cfriends) | |
@findAndCache() | |
else | |
allFriends = @store.all('friend') | |
if Em.isEmpty allFriends | |
cfriends.map (cfriend)=> | |
@store.createRecord('friend', cfriend) | |
else | |
allFriends | |
findAndCache: -> | |
@store.find('friend').then (friends)-> | |
cfriends = friends.map (friend)-> | |
if friend.id | |
s = friend.serialize() | |
s.id = friend.id | |
s.group_ids = friend._data.groups.mapBy('id') | |
s | |
localforage.setItem('friends', cfriends.compact()) | |
friends |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment