Last active
April 27, 2020 18:36
-
-
Save zelaznik/b6b50e8f56e4cb92c1b4f80d4cea22c3 to your computer and use it in GitHub Desktop.
Actions And Glimmer Components
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 GlimmerComponent from '@glimmer/component'; | |
import { tracked } from '@glimmer/tracking'; | |
import EmberComponent from '@ember/component'; | |
import { action } from '@ember/object'; | |
import { guidFor } from '@ember/object/internals'; | |
import { addObserver } from '@ember/object/observers'; | |
function myAction(_target, _name, descriptor) { | |
const original = descriptor.value; | |
const cache = {}; | |
return { | |
get() { | |
const id = guidFor(this); | |
const context = this; | |
if (id in cache) { | |
return cache[id]; | |
} | |
const value = function() { | |
return original.apply(context, arguments); | |
}; | |
cache[id] = value; | |
window.context = context; | |
console.log(context); | |
// context.addObserver('willDestroyElement', function() { | |
// console.log("DESTROYING ELEMENT"); | |
// delete cache[id]; | |
// }); | |
return value; | |
} | |
} | |
} | |
export default class extends GlimmerComponent { | |
@tracked isOpen | |
@myAction | |
toggleOpen() { | |
console.log(`wasOpen == ${this.isOpen}`); | |
this.isOpen = !this.isOpen; | |
console.log(`isOpen == ${this.isOpen}`); | |
} | |
} |
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 Controller from '@ember/controller'; | |
export default class ApplicationController extends Controller { | |
appName = 'Ember Twiddle'; | |
} |
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.17.0", | |
"EmberENV": { | |
"FEATURES": {}, | |
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false, | |
"_APPLICATION_TEMPLATE_WRAPPER": true, | |
"_JQUERY_INTEGRATION": true | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js", | |
"ember": "3.17.0", | |
"ember-template-compiler": "3.17.0", | |
"ember-testing": "3.17.0" | |
}, | |
"addons": { | |
"@glimmer/component": "1.0.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment