This pattern give the ability to dynamically define ES class members
import classfunc, { global, local, method, constructor } from "wiles/fp"
import * as scope from "wiles/scope"
export default classfunc(() => {
const self = local({ count: 0 })
const statis = global({ sum: 0 })
/* pre-constructor()
// no-reactivity
// all changes in self & statis doesn't update attribute nor element value
*/
constructor(() => {
// all changes are reactive
})
method("increment", () => {
self.count++
statis.sum++
})
// no-mangle
method(function decrement() {
this.count--
statis.count--
})
})
Note it still return class but with modified .prototype (prototypical inheritance is still sexy!👙). Also, local() & global() are binded to Class.prototype and Element.attributes when called before returned.
(I wonder if I can remove constructor() hook entirely 🤔)
This pattern give the ability to dynamically define ES class members