Created
July 18, 2016 18:18
-
-
Save dfreeman/a3d5679b25113c1028f2f2324e27528d to your computer and use it in GitHub Desktop.
localstorage
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
| import Ember from 'ember'; | |
| import { storageFor } from 'ember-local-storage'; | |
| export default Ember.Controller.extend({ | |
| appName: 'Ember Twiddle', | |
| favorites: storageFor('favorites'), | |
| init() { | |
| this._super(); | |
| window.f = this.get('favorites'); | |
| } | |
| }); |
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
| import StorageObject from 'ember-local-storage/local/object'; | |
| export default StorageObject.extend({ | |
| addFavorite(id) { | |
| this.set('favorites', this.get('favorites').pushObject(id)); | |
| }, | |
| removeFavorite(id) { | |
| this.set('favorites', this.get('favorites').removeObject(id)); | |
| }, | |
| favorites: Ember.computed({ | |
| get() { | |
| const id = this.get('catalogContext.guid'); | |
| let favorites = this.get(id); | |
| if (!favorites) { | |
| favorites = Ember.A(); | |
| this.set(id, favorites); | |
| } | |
| return favorites; | |
| }, | |
| set(key, value) { | |
| this.set(this.get('catalogContext.id'), value); | |
| return value; | |
| } | |
| }) | |
| }); |
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
| { | |
| "version": "0.10.1", | |
| "EmberENV": { | |
| "FEATURES": {} | |
| }, | |
| "options": { | |
| "use_pods": false, | |
| "enable-testing": false | |
| }, | |
| "dependencies": { | |
| "jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
| "ember": "2.6.0", | |
| "ember-data": "2.6.1", | |
| "ember-template-compiler": "2.6.0" | |
| }, | |
| "addons": { | |
| "ember-local-storage": "*" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment