Skip to content

Instantly share code, notes, and snippets.

@dfreeman
Created July 18, 2016 18:18
Show Gist options
  • Save dfreeman/a3d5679b25113c1028f2f2324e27528d to your computer and use it in GitHub Desktop.
Save dfreeman/a3d5679b25113c1028f2f2324e27528d to your computer and use it in GitHub Desktop.
localstorage
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');
}
});
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;
}
})
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
{
"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