Created
December 9, 2019 08:49
-
-
Save lifeart/da51dd083c800e8322bd5f4d60c4b3f3 to your computer and use it in GitHub Desktop.
GlimmerVueHooks
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 { 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