Last active
October 24, 2015 00:33
-
-
Save phcoliveira/ee5e3d01b2877dce89eb to your computer and use it in GitHub Desktop.
Toggle computed property.
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
import Ember from 'ember'; | |
// Can't use session or local storage inside this Twiddle, but you get the picture. | |
var _sessionStorage = {}, | |
// Make _localStorage = { jwt: "something" } to see that the problem is not | |
// about the value "false", but rather the original value returned by the getter. | |
_localStorage = {}; | |
export default Ember.Controller.extend({ | |
appName:'Ember Twiddle', | |
jwt: 'some_fancy_jwt', | |
onInit: Ember.on('init', function() { _sessionStorage.jwt = this.get('jwt'); }), | |
rememberMe: Ember.computed({ | |
get() { | |
return Ember.isPresent(_localStorage.jwt); | |
}, | |
set(key, value) { | |
console.debug('service:session | rememberMe.set', value); | |
if (value) { | |
_localStorage.jwt = _sessionStorage.jwt; | |
} else { | |
delete _localStorage.jwt; | |
} | |
return !!value; | |
} | |
}).volatile(), // Loose .volatile() to make it work. | |
localStorage: Ember.computed(function() { return _localStorage.jwt || "undefined" }).volatile() | |
}); |
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
{ | |
"version": "0.4.13", | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.1.0/ember.debug.js", | |
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.1.0/ember-data.js", | |
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.1.0/ember-template-compiler.js" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment