Skip to content
Source
Sign inSign up
TanStack/store

feat: add lazy store in angular #285

Closedbenjavicente(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/285/headopened

🎯 Changes

This PR experiments with a new API to handle the Angular limitation of input signals described here: https://github.com/TanStack/store/discussions/284

I don't intent this to be the final API to solve the issue. The idea is to support Angular input signals with this pattern:

@Component({})
export class InjectExampleComponent {
  key = input.required<number>()
  value = injectValue(() => ({ key: this.key() }))
}

export function injectValue(options: Options | (() => Options)) {
  const storeSignal = stableSignal(() => {
    const resolvedOptions = typeof options === 'function' ? options() : options
    return new Store(resolvedOptions)
  })

  return injectLazyStore(store, (state) => state.value)
}

The type of the store signal is branded to enforce it been created by a computed with untracked content, done in a new exported function stableSignal.


The tests setup changes where needed to support input signals in the tests.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Sign in to join this conversation.