Skip to content

Conversation

@estherbrunner
Copy link
Member

No description provided.

Support optional KeyConfig parameter in createStore to generate stable
keys for array items. This allows tracking items across reorders and
prevents false change notifications when array structure changes but
item identity remains the same.
Replace dual `keyAt` and `indexByKey` Maps with a single `order` array
for simpler and more efficient key-to-index tracking. Update
`indexByKey` method to `indexOfKey` with consistent return values (-1
for not found). Simplify `current()` to properly handle both array and
record stores. Remove unused utility functions `validArrayIndexes` and
`recordToArray`.
Documentation and examples for array-like stores with stable keys, which
persist through sorting and reordering operations. Includes new store
methods `byKey()`, `keyAt()`, `indexOfKey()`, and `splice()`.
Implement Collections in src/collection.ts:
- createCollection factory for deriving from stores
- Proxy-based array-like interface with computed signals
- Key management and event notifications
- Read-only enforcement with DuplicateKeyError

Rename StoreKeyExistsError to DuplicateKeyError for consistency across
both stores and collections.

Update system.ts with Notifications and Listener types for standardized
event handling across signal types.
})

test('works with array stores using custom string prefix keys', () => {
const items = createStore(['apple', 'banana', 'cherry'], 'fruit')
{ id: 'u2', name: 'Bob' },
{ id: 'u3', name: 'Charlie' },
],
item => item.id,
})

test('stable keys persist after sort operations', () => {
const numbers = createStore([30, 10, 20], 'num')
})

test('stable keys work with add/remove operations', () => {
const items = createStore(['first'], 'item')
{ id: 'item1', count: 5 },
{ id: 'item2', count: 3 },
],
item => item.id,
})

test('keyAt() and indexOfKey() work with custom string prefix keys', () => {
const items = createStore(['apple', 'banana', 'cherry'], 'fruit')
{ id: 'bob', name: 'Bob' },
{ id: 'charlie', name: 'Charlie' },
],
item => item.id,
})

test('round-trip consistency: keyAt(indexOfKey(key)) === key', () => {
const items = createStore(['a', 'b', 'c'], 'item')
})

test('methods work correctly after multiple operations', () => {
const items = createStore(['a', 'b'], 'x')
})

test('collection supports key-based access methods', () => {
const items = createStore(['a', 'b', 'c'], 'item')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants