Skip to content

Persistent state #13

@aminnairi

Description

@aminnairi

Is your feature request related to a problem? Please describe.
There is no way of persisting the state easily, it would require observing each state change from the outside, and savin the state to a storage.

Describe the solution you'd like
Provide functions that would allow to quickly create a persistent state when creating an application.

import {
  createApplication,
  createState,
  createMemoryState,
  createLocalStorageState,
  createSessionStorageState,
  createIndexedDBState
} from "@arachnide/core";
const startApplication = createApplication();
const startApplication = createApplication({
  state: createMemoryState()
});
const startApplication = createApplication({
  state: createLocalStorageState({
    key: "state"
  })
});
const startApplication = createApplication({
  state: createSessionStorageState({
    key: "state"
  })
});
const startApplication = createApplication({
  state: createIndexedDBState({
    key: "state"
  })
});

The interface would look like that.

interface StateAdapter<State> {
  retrieve(): State
  save(state: State): void
}

Describe alternatives you've considered
None.

Additional context
This would introduce a breaking change.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions