Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: rename getInstanceId to getNodeId and add a scope option #211

Merged
merged 1 commit into from
Mar 13, 2025

Conversation

bowheart
Copy link
Collaborator

@affects atoms, stores

Description

With the introduction of scoped atoms came the concept of scoped ids. These @scope()-suffixed ids can currently only be generated automatically by Zedux internals.

Expose a way to create scoped ids via the existing getInstanceId method on AtomTemplateBase. Pass an optional third object parameter with a scope map pointing contexts to their contextual values that should be added to the id. Also rename getInstanceId to getNodeId to match the new nomenclature.

import { atom, createEcosystem } from '@zedux/react'

const ecosystem = createEcosystem()
const contextAtom = atom('context', 'example state')

const scopedAtom = atom('scoped', () => {
  inject(contextAtom)
})

const scope = new Map([
  [contextAtom, ecosystem.getNode(contextAtom)]
])

const id = scopedAtom.getNodeId(ecosystem, [], { scope })

id // 'scoped-@scope("context")'

Breaking Changes

The AtomTemplateBase class is the last thing that needs some love for Zedux v2. Rename:

  • getInstanceId -> getNodeId
  • _createInstance -> _instantiate
  • _config -> c (short for config)
  • _value -> v (short for valueOrFactory)

@bowheart bowheart force-pushed the josh/atom-template-changes branch from d35dc0f to 240de17 Compare March 13, 2025 15:43
@bowheart bowheart changed the title feat!: rename getInstanceId to makeId and add a scope option feat!: rename getInstanceId to getNodeId and add a scope option Mar 13, 2025
@bowheart bowheart merged commit 88915f3 into master Mar 13, 2025
2 checks passed
@bowheart bowheart deleted the josh/atom-template-changes branch March 13, 2025 16:00
@bowheart bowheart mentioned this pull request Mar 13, 2025
53 tasks
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.

1 participant