{"id":31956341,"url":"https://github.com/profullstack/state-manager","last_synced_at":"2026-03-05T06:31:23.947Z","repository":{"id":290024572,"uuid":"973158902","full_name":"profullstack/state-manager","owner":"profullstack","description":"A simplified state management system inspired by Svelte's reactivity model.","archived":false,"fork":false,"pushed_at":"2025-05-18T14:33:00.000Z","size":123,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-10-23T19:52:03.277Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/profullstack.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,"zenodo":null}},"created_at":"2025-04-26T11:44:37.000Z","updated_at":"2025-05-18T14:33:04.000Z","dependencies_parsed_at":"2025-04-26T11:51:49.915Z","dependency_job_id":"efad10ee-e439-4fa4-8489-3a272d79816d","html_url":"https://github.com/profullstack/state-manager","commit_stats":null,"previous_names":["profullstack/state-manager"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/profullstack/state-manager","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/profullstack%2Fstate-manager","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/profullstack%2Fstate-manager/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/profullstack%2Fstate-manager/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/profullstack%2Fstate-manager/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/profullstack","download_url":"https://codeload.github.com/profullstack/state-manager/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/profullstack%2Fstate-manager/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30112224,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-05T03:40:26.266Z","status":"ssl_error","status_checked_at":"2026-03-05T03:39:15.902Z","response_time":93,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2025-10-14T14:48:36.329Z","updated_at":"2026-03-05T06:31:23.602Z","avatar_url":"https://github.com/profullstack.png","language":"JavaScript","readme":"# @profullstack/state-manager\n\nEnhanced state manager with web component integration, persistence, and subscription management.\n\n## Browser-Only Version\n\nThis module has been refactored to be browser-only, removing any Node.js-specific dependencies. It can be used directly in browser environments without any additional polyfills or bundling.\n\n### No External Dependencies\n\nThe module now uses the browser's native EventTarget API instead of the eventemitter3 library, eliminating all external dependencies. This makes the module lighter and more efficient for browser usage.\n\n## Features\n\n- Simple and intuitive API for state management\n- Immutable state updates\n- Subscription system for state changes\n- Path-based state access and updates\n- Persistence with various storage adapters (localStorage, sessionStorage, IndexedDB, memory)\n- Web component integration\n- Middleware support for intercepting and modifying state updates\n- Selectors for derived state\n\n## Installation\n\n```bash\nnpm install @profullstack/state-manager\n```\n\n## Usage\n\n### Basic Usage\n\n```javascript\nimport { createStateManager } from '@profullstack/state-manager';\n\n// Create a state manager with initial state\nconst stateManager = createStateManager({\n  user: {\n    name: 'John Doe',\n    preferences: {\n      theme: 'light'\n    }\n  },\n  todos: [\n    { id: 1, text: 'Learn state management', completed: false }\n  ]\n});\n\n// Subscribe to state changes\nconst unsubscribe = stateManager.subscribe((state, changedPaths) =\u003e {\n  console.log('State changed:', state);\n  console.log('Changed paths:', changedPaths);\n});\n\n// Update state\nstateManager.setState({\n  user: {\n    preferences: {\n      theme: 'dark'\n    }\n  }\n});\n\n// Get state\nconst theme = stateManager.getState('user.preferences.theme');\nconsole.log('Theme:', theme); // 'dark'\n\n// Unsubscribe when done\nunsubscribe();\n```\n\n### Persistence\n\n```javascript\nimport { createStateManager } from '@profullstack/state-manager';\n\n// Create a state manager with persistence enabled\nconst stateManager = createStateManager({\n  user: {\n    name: 'John Doe'\n  }\n}, {\n  enablePersistence: true,\n  persistenceKey: 'my_app_state'\n});\n\n// State will be automatically saved to localStorage\nstateManager.setState({\n  user: {\n    name: 'Jane Doe'\n  }\n});\n\n// When the app is reloaded, the state will be restored from localStorage\n```\n\n### Web Component Integration\n\n```javascript\nimport { createStateManager } from '@profullstack/state-manager';\n\n// Create a state manager\nconst stateManager = createStateManager({\n  todos: [\n    { id: 1, text: 'Learn state management', completed: false }\n  ]\n});\n\n// Create a connected web component\nconst { createConnectedComponent } = stateManager.webComponents;\n\nclass TodoListElement extends HTMLElement {\n  constructor() {\n    super();\n    this.attachShadow({ mode: 'open' });\n  }\n  \n  connectedCallback() {\n    this.render();\n  }\n  \n  stateChanged(state, path, fullState) {\n    this.render();\n  }\n  \n  render() {\n    const todos = this.getState('todos');\n    \n    this.shadowRoot.innerHTML = `\n      \u003cul\u003e\n        ${todos.map(todo =\u003e `\n          \u003cli\u003e${todo.text}\u003c/li\u003e\n        `).join('')}\n      \u003c/ul\u003e\n    `;\n  }\n}\n\n// Register the component\ncreateConnectedComponent('todo-list', TodoListElement, {\n  statePaths: ['todos']\n});\n\n// Use the component in HTML\n// \u003ctodo-list\u003e\u003c/todo-list\u003e\n```\n\n## API Reference\n\n### createStateManager(initialState, options)\n\nCreates a new state manager instance.\n\n- `initialState`: Initial state object\n- `options`: Configuration options\n  - `enablePersistence`: Whether to enable persistence (default: false)\n  - `persistenceKey`: Key for persistence storage (default: 'app_state')\n  - `persistenceAdapter`: Persistence adapter (default: localStorage)\n  - `persistentKeys`: Keys to persist (default: all)\n  - `immutable`: Whether to use immutable state (default: true)\n  - `debug`: Whether to enable debug logging (default: false)\n\n### StateManager Methods\n\n- `getState(path)`: Get the current state or a specific part of the state\n- `setState(update, options)`: Update the state\n- `resetState(initialState, options)`: Reset the state to initial values\n- `subscribe(callback, paths)`: Subscribe to state changes\n- `unsubscribe(callback)`: Unsubscribe a callback from all subscriptions\n- `use(type, middleware)`: Add middleware to the state manager\n- `createSelector(selectorFn, equalityFn)`: Create a selector function that memoizes the result\n\n## License\n\nMIT","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprofullstack%2Fstate-manager","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprofullstack%2Fstate-manager","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprofullstack%2Fstate-manager/lists"}