()
| 9 | let previousArgs |
| 10 | let currentEpoch |
| 11 | let set = () => { |
| 12 | if (currentEpoch === nanostoresGlobal.epoch) return |
| 13 | currentEpoch = nanostoresGlobal.epoch |
| 14 | let args = stores.map($store => $store.get()) |
| 15 | if (!previousArgs || args.some((arg, i) => arg !== previousArgs[i])) { |
| 16 | previousArgs = args |
| 17 | let value = cb(...args) |
| 18 | if (value && value.then && value.t) { |
| 19 | if (process.env.NODE_ENV !== 'production') { |
| 20 | warn( |
| 21 | 'Use @nanostores/async for async computed. We will remove Promise support in computed() in Nano Stores 2.0' |
| 22 | ) |
| 23 | } |
| 24 | value.then(asyncValue => { |
| 25 | if (previousArgs === args) { |
| 26 | // Prevent a stale set |
| 27 | $computed.set(asyncValue) |
| 28 | } |
| 29 | }) |
| 30 | } else { |
| 31 | $computed.set(value) |
| 32 | currentEpoch = nanostoresGlobal.epoch |
| 33 | } |
| 34 | } |
| 35 | } |
| 36 | let $computed = atom(undefined) |
| 37 | let get = $computed.get |
| 38 | $computed.get = () => { |
no test coverage detected