Skip to content

Commit

Permalink
fix($utils): observer updater fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Jan 1, 2020
1 parent 93e6646 commit 126cb03
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/koishi-utils/src/observe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,16 @@ export function observe <T extends object, R> (target: T, ...args: [(string | nu
}
}

let label = '', update: UpdateFunction<T, R> = noop
let label = '', update: UpdateFunction<T, R>
if (typeof args[0] === 'function') update = args.shift() as UpdateFunction<T, R>
if (typeof args[0] === 'string') label = args[0]

if (label && label in refs) {
refs[label].__updateCallback__ = update
refs[label].__updateCallback__ = update || refs[label].__updateCallback__
return refs[label]._merge(target)
}

Object.defineProperty(target, '__updateCallback__', { value: update, writable: true })
Object.defineProperty(target, '__updateCallback__', { value: update || noop, writable: true })

Object.defineProperty(target, '_update', {
value (this: Observed<T, R>) {
Expand Down

0 comments on commit 126cb03

Please sign in to comment.