Closed amandaXCY closed 4 months ago
function observable(fnName:any) { // 装饰器工厂函数 return function (target: any, key: string): any { console.log(1,target)// 装饰器 console.log(2,key)// 装饰 let prev = target[key];
Object.defineProperty(target, key, { set(next) { target[fnName](prev, next); prev = next; } })
} }
class Store { @observable('onCountChange') count = -1; }
const store = new Store(); store.count = 10
out
1 undefined 2 { kind: 'field', name: 'count', metadata: [Object: null prototype] {}, addInitializer: ƒ bound (), static: false, private: false, access: { has: ƒ (), get: ƒ k(), set: ƒ F() } }
but in https://www.typescriptlang.org/play/
LOG: 1, Store: {}
node packs: babel/core:7.24.5 babel/preset-env:7.24.7
Thanks @amandaXCY. I'm seeing the same result in both RunJS and the typescript playground:
What version of RunJS are you using?
Closing as there's not been a response from @amandaXCY 😔
function observable(fnName:any) { // 装饰器工厂函数 return function (target: any, key: string): any { console.log(1,target)// 装饰器 console.log(2,key)// 装饰 let prev = target[key];
} }
class Store { @observable('onCountChange') count = -1; }
const store = new Store(); store.count = 10
out
1 undefined 2 { kind: 'field', name: 'count', metadata: [Object: null prototype] {}, addInitializer: ƒ bound (), static: false, private: false, access: { has: ƒ (), get: ƒ k(), set: ƒ F() } }
but in https://www.typescriptlang.org/play/
LOG: 1, Store: {}
node packs: babel/core:7.24.5 babel/preset-env:7.24.7