Skip to content

Commit

Permalink
rename unstable_onInit to INTERNAL_onInit
Browse files Browse the repository at this point in the history
  • Loading branch information
dmaskasky committed Dec 21, 2024
1 parent bfdd52e commit debac97
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/vanilla/atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export interface Atom<Value> {
/**
* Fires after atom is referenced by the store for the first time
*/
unstable_onInit?: (store: Store) => void
INTERNAL_onInit?: (store: Store) => void
}

export interface WritableAtom<Value, Args extends unknown[], Result>
Expand Down
2 changes: 1 addition & 1 deletion src/vanilla/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ export const createStore = (): Store => {
(atom, ...params) => atom.read(...params),
(atom, ...params) => atom.write(...params),
(atom, ...params) => atom.onMount?.(...params),
(store) => (atom) => atom.unstable_onInit?.(store),
(store) => (atom) => atom.INTERNAL_onInit?.(store),
)
}

Expand Down
2 changes: 1 addition & 1 deletion tests/vanilla/effect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function atomSyncEffect(effect: Effect) {
},
)
bridgeAtom.onMount = (mount) => mount()
bridgeAtom.unstable_onInit = (store) => {
bridgeAtom.INTERNAL_onInit = (store) => {
store.get(refAtom).sub = () => {
const listener = Object.assign(
() => {
Expand Down
6 changes: 3 additions & 3 deletions tests/vanilla/store.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ it('should call onInit only once per atom', () => {
const store = createStore()
const a = atom(0)
const onInit = vi.fn()
a.unstable_onInit = onInit
a.INTERNAL_onInit = onInit
store.get(a)
expect(onInit).toHaveBeenCalledTimes(1)
expect(onInit).toHaveBeenCalledWith(store)
Expand All @@ -1028,10 +1028,10 @@ it('should call onInit only once per atom', () => {
it('should call onInit only once per store', () => {
const a = atom(0)
const aOnInit = vi.fn()
a.unstable_onInit = aOnInit
a.INTERNAL_onInit = aOnInit
const b = atom(0)
const bOnInit = vi.fn()
b.unstable_onInit = bOnInit
b.INTERNAL_onInit = bOnInit
type Store = ReturnType<typeof createStore>
function testInStore(store: Store) {
store.get(a)
Expand Down
4 changes: 2 additions & 2 deletions tests/vanilla/unstable_derive.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,11 @@ it('should pass the correct store instance to the atom initializer', () => {
const baseStore = createStore()
const derivedStore = baseStore.unstable_derive((...args) => args)
const a = atom(null)
a.unstable_onInit = (store) => {
a.INTERNAL_onInit = (store) => {
expect(store).toBe(baseStore)
}
baseStore.get(a)
a.unstable_onInit = (store) => {
a.INTERNAL_onInit = (store) => {
expect(store).toBe(derivedStore)
}
derivedStore.get(a)
Expand Down

0 comments on commit debac97

Please # to comment.