Skip to content

Instantly share code, notes, and snippets.

@lifeart lifeart/glimmer.js
Created Dec 9, 2019

Embed
What would you like to do?
GlimmerVueHooks
import { set } from '@ember/object';
function store(initValue) {
let context = null;
let propName = null;
let getter = {
get value() {
retun initValue
}
}
let fn = function (ctx, propertyName) {
context = ctx;
propName = propertyName;
set(context, propertyName, value);
retun {
get value() {
retun context[propertyName;
}
}
};
Object.defineProperty(fn, 'value', {
enumerable: true,
configurable: false,
get() {
retun context === null ? initValue : context[propName]
},
set(value) {
if (context === null) {
initValue = value
} else {
context[propName] = value;
}
}
});
retun fn;
}
class HookedGlimmerComponent extends GlimmerComponent {
constructor() {
super(...aruments);
let items = this.setup(this.args, this);
Object.keys(items).forEach((itemName)=>{
items[itemName](this, itemName);
});
}
setup() {
retun {};
}
}
class MyComponent extends HookedGlimmerComponent {
setup() {
let a = store(10);
console.log(a.value);
retun {
a
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.