Skip to content

Instantly share code, notes, and snippets.

@lifeart
Created December 9, 2019 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lifeart/da51dd083c800e8322bd5f4d60c4b3f3 to your computer and use it in GitHub Desktop.
Save lifeart/da51dd083c800e8322bd5f4d60c4b3f3 to your computer and use it in GitHub Desktop.
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