Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
Signed-off-by: Matteo Collina <hello@matteocollina.com>
  • Loading branch information
mcollina committed Apr 19, 2024
1 parent 1ae4d82 commit 0add09c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion asyncforge.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function memo (name) {

function setAll (memos) {
let store = asyncLocalStorage.getStore()
store = Object.create(store)
store = Object.create(store || null)
const keys = Object.getOwnPropertySymbols(memos)
for (const key of keys) {
store[key] = memos[key]
Expand Down
16 changes: 16 additions & 0 deletions test/setall.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ const { test } = require('node:test')
const { start, memo, setAll } = require('../')
const assert = require('node:assert/strict')

test('setAll no start', async (t) => {
const a = memo()
const b = memo()
const c = memo()

setAll({
[a.key]: 1,
[b.key]: 2,
[c.key]: 3
})

assert.equal(a(), 1)
assert.equal(b(), 2)
assert.equal(c(), 3)
})

test('setAll memos', async (t) => {
const a = memo()
const b = memo()
Expand Down

0 comments on commit 0add09c

Please sign in to comment.