Skip to content

Commit c7c3b9f

Browse files
committed
Accept objs as first param too
1 parent 3f75bc9 commit c7c3b9f

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/stores.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ const createToast = () => {
44
const { subscribe, update } = writable([])
55
let count = 0
66
let defaults = {}
7+
const _obj = obj => typeof obj === 'object'
78
const push = (msg, opts = {}) => {
8-
const entry = { id: ++count, msg: msg, ...defaults, ...opts, theme: { ...defaults.theme, ...opts.theme } }
9+
opts = _obj(msg) ? { ...msg } : { ...opts, msg }
10+
const entry = { ...defaults, ...opts, id: ++count, theme: { ...defaults.theme, ...opts.theme } }
911
update(n => entry.reversed ? [...n, entry] : [entry, ...n])
1012
return count
1113
}
@@ -16,11 +18,12 @@ const createToast = () => {
1618
return n.filter(i => i.id !== target)
1719
})
1820
}
19-
const set = (id, obj) => {
21+
const set = (id, opts = {}) => {
22+
opts = _obj(id) ? { ...id } : { ...opts, id }
2023
update(n => {
21-
const idx = n.findIndex(i => i.id === id)
24+
const idx = n.findIndex(i => i.id === opts.id)
2225
if (idx > -1) {
23-
n[idx] = { ...n[idx], ...obj }
26+
n[idx] = { ...n[idx], ...opts }
2427
}
2528
return n
2629
})

0 commit comments

Comments
 (0)