Skip to content

Conversation

@igorkamyshev
Copy link
Collaborator

@igorkamyshev igorkamyshev commented Aug 6, 2024

fixes #216

Changes since @yumauri contribution to the branch:

  • implement remove Effect which is setting undefined to storage value
  • get rid of clear Effect because it has to affect all storage, but current API assumes that Effects can affect only a particular entry with provided key
  • rename all Effects to emphasize that they are Effects
    • get -> getFx
    • set -> setFx
    • remove -> removeFx
  • add basic docs

@igorkamyshev igorkamyshev marked this pull request as ready for review August 6, 2024 12:48
}) as Effect<State, void, any> // as Effect<State, void, Fail<Err>>

const removeFx = attach({
mapParams: () => undefined as any,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid that using undefined as new storage value will break synchronization across different persisted entities... I thought about adding extra support from adapter, like, adding removeItem support for localStorage and sessionStorage

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried to fix this by adding remove method to adapter, and removeFx calls it, or, in case it is absent — set method with null. Not sure I like it or not. Tried on memory adapter, will add for other adapters later.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After tests approach didn't work with storage adapter (localStorage/sessionStorage) though... Cannot think of a way to notify persisted stores about removing value from storage. Will try smth else.

# Conflicts:
#	.size-limit.js
#	src/broadcast/index.ts
#	src/core/index.ts
#	src/core/persist.ts
#	src/index.ts
#	src/local/index.ts
#	src/memory/index.ts
#	src/query/index.ts
#	src/session/index.ts
#	src/types.ts
# Conflicts:
#	tests/core-validate.test.ts
# Conflicts:
#	tests/broadcast.test.ts
#	tests/local.test.ts
#	tests/memory.test.ts
#	tests/query.test.ts
#	tests/session.test.ts
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.

createStorage API for complex cases that cannot be covered with persist

3 participants