{"id":19356873,"url":"https://github.com/alexfigliolia/galena-async-storage","last_synced_at":"2026-05-09T10:24:50.187Z","repository":{"id":174812613,"uuid":"652823764","full_name":"alexfigliolia/galena-async-storage","owner":"alexfigliolia","description":"An Galena middleware that persists your state using React Native's AsyncStorage","archived":false,"fork":false,"pushed_at":"2024-01-13T00:58:39.000Z","size":78,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-07T00:18:23.086Z","etag":null,"topics":["async-storage","galena","local-storage","middleware","react","react-native"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@figliolia/galena-async-storage","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alexfigliolia.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-06-12T21:47:25.000Z","updated_at":"2023-06-12T22:37:24.000Z","dependencies_parsed_at":"2024-01-13T06:13:45.795Z","dependency_job_id":"5e20e31b-a54d-4c58-8eb8-dee84036a9f6","html_url":"https://github.com/alexfigliolia/galena-async-storage","commit_stats":null,"previous_names":["alexfigliolia/galena-async-storage"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexfigliolia%2Fgalena-async-storage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexfigliolia%2Fgalena-async-storage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexfigliolia%2Fgalena-async-storage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexfigliolia%2Fgalena-async-storage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexfigliolia","download_url":"https://codeload.github.com/alexfigliolia/galena-async-storage/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240473328,"owners_count":19807118,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async-storage","galena","local-storage","middleware","react","react-native"],"created_at":"2024-11-10T07:05:43.925Z","updated_at":"2026-05-09T10:24:50.137Z","avatar_url":"https://github.com/alexfigliolia.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Async Storage Middleware\nA [Galena](https://www.npmjs.com/package/@figliolia/galena) middleware for persisting units of State with [Async Storage](https://react-native-async-storage.github.io/async-storage/). \n\n# Getting Started\n\n## Installation\n```bash\nnpm install --save @figliolia/galena-async-storage\n# or\nyarn add @figliolia/galena-async-storage\n```\n\n## Basic Usage\n\n```typescript\nimport { State } from \"@figliolia/galena\";\nimport { AsyncStorageMiddleware } from \"@figliolia/galena-async-storage\";\nimport AsyncStorage from \"@react-native-async-storage/async-storage\";\n\nconst UserState = new State(\"User\", {\n  token: \"\",\n  username: \"\"\n});\n\nvoid AsyncStorage.getItem(\"User\").then(savedState =\u003e {\n  if(savedState) {\n    // Initialize User State from async storage\n    UserState.update(state =\u003e {\n      state.token = savedState.token;\n      state.username = savedState.username;\n    });\n  }\n  // Persist all future state mutations using AsyncStorageMiddleware\n  UserState.registerMiddleware(new AsyncStorageMiddleware());\n});\n```\n### Persisting State Mutations\nOnce the `AsyncStorageMiddleware()` is registered on your state, each call to `State.update()`, `State.backgroundUpdate()`, and `State.priorityUpdate()` will persist the latest mutation into `AsyncStorage`. Each entry's key will be equal to `State.name`.\n\n## Factories for Persisted Galena State\nIn production, you may find yourself with several units of State requiring `AsyncStorage`. If using `Galena` instances, applying this middleware to all unit's of `State` is as easy as calling:\n\n```typescript\nimport { Galena } from \"@figliolia/galena\";\nimport { AsyncStorageMiddleware } from \"@figliolia/galena-async-storage\";\n\nexport const AppState = new Galena([\n  new AsyncStorageMiddleware()\n]);\n\nconst MyState = AppState.composeState(\"My State\", {\n  token: \"\",\n  username: \"\"\n});\n// MyState.middleware = [new AsyncStorageMiddleware()];\n```\n\nHowever, if you're using Island Architecture and require several AsyncStorage-persisted units of State, a factory can be created for automatically applying the `AsyncStorageMiddleware`\n\n```typescript\nimport { State, type Middleware } from \"@figliolia/galena\";\nimport { AsyncStorageMiddleware } from \"@figliolia/galena-async-storage\";\n\nexport const createPersistedState = \u003cT\u003e(\n  name: string, \n  initialState: T, \n  middleware: [new AsyncStorageMiddleware()]\n) =\u003e {\n  const state = new State\u003cT\u003e(name, initialState);\n  state.registerMiddleware(...middleware);\n  return state;\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexfigliolia%2Fgalena-async-storage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexfigliolia%2Fgalena-async-storage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexfigliolia%2Fgalena-async-storage/lists"}