parent
cce7dbfbe9
commit
2bdaa84438
@ -0,0 +1,20 @@ |
|||||||
|
import { deepSignal } from './dist/index.js'; |
||||||
|
|
||||||
|
const root = deepSignal({
|
||||||
|
mySet: new Set([ |
||||||
|
{ "@id": "obj1", value: 10 }, |
||||||
|
{ "@id": "obj2", value: 20 } |
||||||
|
]) |
||||||
|
}); |
||||||
|
|
||||||
|
const result = root.mySet.values().map(entry => entry); |
||||||
|
console.log('Type:', typeof result); |
||||||
|
console.log('Constructor:', result.constructor.name); |
||||||
|
console.log('Result:', result); |
||||||
|
console.log('Has next?:', typeof result.next); |
||||||
|
console.log('Is iterable?:', Symbol.iterator in result); |
||||||
|
|
||||||
|
// Convert to array
|
||||||
|
const arr = Array.from(result); |
||||||
|
console.log('Array:', arr); |
||||||
|
console.log('First entry:', arr[0]); |
||||||
@ -0,0 +1,28 @@ |
|||||||
|
import { deepSignal, subscribeDeepMutations } from './dist/index.js'; |
||||||
|
|
||||||
|
const root = deepSignal({
|
||||||
|
mySet: new Set([ |
||||||
|
{ "@id": "obj1", value: 10 }, |
||||||
|
{ "@id": "obj2", value: 20 } |
||||||
|
]) |
||||||
|
}); |
||||||
|
|
||||||
|
subscribeDeepMutations(root, (patches) => { |
||||||
|
console.log('Patches:', JSON.stringify(patches, null, 2)); |
||||||
|
}); |
||||||
|
|
||||||
|
// Use .map() to get entries
|
||||||
|
const entries = root.mySet.values().map(entry => { |
||||||
|
console.log('Entry:', entry); |
||||||
|
return entry; |
||||||
|
}); |
||||||
|
|
||||||
|
console.log('Got entries:', entries.length); |
||||||
|
console.log('Modifying first entry...'); |
||||||
|
|
||||||
|
// Modify the first one
|
||||||
|
entries[0].value = 100; |
||||||
|
|
||||||
|
setTimeout(() => { |
||||||
|
console.log('Done'); |
||||||
|
}, 100); |
||||||
@ -0,0 +1,25 @@ |
|||||||
|
import { deepSignal, subscribeDeepMutations } from './dist/index.js'; |
||||||
|
|
||||||
|
const root = deepSignal({
|
||||||
|
mySet: new Set([ |
||||||
|
{ "@id": "obj1", value: 10 } |
||||||
|
]) |
||||||
|
}); |
||||||
|
|
||||||
|
subscribeDeepMutations(root, (patches) => { |
||||||
|
console.log('Patches:', JSON.stringify(patches, null, 2)); |
||||||
|
}); |
||||||
|
|
||||||
|
// Get the first entry from the set
|
||||||
|
const entries = root.mySet.values(); |
||||||
|
const firstEntry = entries.next().value; |
||||||
|
|
||||||
|
console.log('First entry:', firstEntry); |
||||||
|
console.log('Modifying value...'); |
||||||
|
|
||||||
|
// Modify it
|
||||||
|
firstEntry.value = 20; |
||||||
|
|
||||||
|
setTimeout(() => { |
||||||
|
console.log('Done'); |
||||||
|
}, 100); |
||||||
Loading…
Reference in new issue