Forked from alexlafroscia/controllers.application.js
Created
September 27, 2018 21:14
-
-
Save jasonmit/b1c411224de5a9ab6bb3757d1acac8c8 to your computer and use it in GitHub Desktop.
WeakMap and the KVO
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'; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle', | |
init() { | |
this._super(...arguments); | |
this.objects = [ | |
{ label: 'First' }, | |
{ label: 'Second' } | |
]; | |
this.errors = new WeakMap(); | |
this.errors.set(this.objects[0], { message: 'Danger, Will Robinson!' }); | |
}, | |
actions: { | |
createError() { | |
const second = this.objects[1]; | |
this.errors.set(second, { | |
message: 'Now I\'m in danger, too!' | |
}); | |
this.notifyPropertyChange('errors'); | |
} | |
} | |
}); |
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'; | |
export function weakmapGet([weakMap, key]) { | |
return weakMap.get(key); | |
} | |
export default Ember.Helper.helper(weakmapGet); |
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.15.0", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js", | |
"ember": "3.2.2", | |
"ember-template-compiler": "3.2.2", | |
"ember-testing": "3.2.2" | |
}, | |
"addons": { | |
"ember-data": "3.2.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment