{"id":13826025,"url":"https://github.com/tomas2387/almy","last_synced_at":"2025-06-29T06:33:29.934Z","repository":{"id":28436684,"uuid":"118375162","full_name":"tomas2387/almy","owner":"tomas2387","description":"🗄️  673 bytes store for managing the state in your application","archived":false,"fork":false,"pushed_at":"2024-09-23T22:59:53.000Z","size":1056,"stargazers_count":26,"open_issues_count":6,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-11T05:40:16.882Z","etag":null,"topics":["javascript","state-management"],"latest_commit_sha":null,"homepage":"https://tomas2387.github.io/almy/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tomas2387.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-01-21T21:24:05.000Z","updated_at":"2024-06-09T19:41:37.000Z","dependencies_parsed_at":"2024-01-18T04:07:13.947Z","dependency_job_id":"291e3ef9-446e-49b3-8260-086dc07de7ab","html_url":"https://github.com/tomas2387/almy","commit_stats":{"total_commits":79,"total_committers":2,"mean_commits":39.5,"dds":0.240506329113924,"last_synced_commit":"6f6d86514535e8a76351b03e8259059fe6ae5c88"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/tomas2387/almy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomas2387%2Falmy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomas2387%2Falmy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomas2387%2Falmy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomas2387%2Falmy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tomas2387","download_url":"https://codeload.github.com/tomas2387/almy/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tomas2387%2Falmy/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260756603,"owners_count":23057922,"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":["javascript","state-management"],"created_at":"2024-08-04T09:01:30.956Z","updated_at":"2025-06-29T06:33:29.909Z","avatar_url":"https://github.com/tomas2387.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# 🗄️ almy\n[![Version](https://badgen.net/npm/v/almy)](https://www.npmjs.com/package/almy) \n[![Build Status](https://travis-ci.org/tomas2387/almy.svg?branch=master)](https://travis-ci.org/tomas2387/almy) \n[![Coverage Status](https://coveralls.io/repos/github/tomas2387/almy/badge.svg?branch=master)](https://coveralls.io/github/tomas2387/almy?branch=master)\n![npm bundle size](https://img.shields.io/bundlephobia/minzip/almy)\n\nThe simpliest store for managing the state in your application.    \nWorks in all environments and all browsers.\n\n## Why do I need a centralized state management\n\nManaging the information rendered is difficult, mostly when our apps grow large and the state is scattered across many components and the interactions between them without control. \n\nTo solve this, the current state of the art solution is to use a globalized state where we can centralize and have more control over the information we have to render. Almy is a simple library that uses a pub/sub façade along with a centralized state management which makes the the side effects of changing information easy to control and eliminates the risk of getting race conditions in our applications.\n\n## Installation\n\n```bash\nnpm install --save almy\n```\n\n## Methods\n-  **dispatch(key: string, value: any)**    \n_Dispatches some event that happened in a key value fashion_\n-  **subscribe(key: string, callback: Function)**   \n_Subscribes to dispatched events. If someone has dispatched an event before, it calls the callback right away_\n-  **state(key:?string):Object**    \n_Returns the state of your application_\n\n## Usage\n\nIncluding it as a script tag    \n```html\n\u003cscript src=\"./node_modules/almy/dist/almy.umd.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n  almy.almy.dispatch('window_width', 524)\n\u003c/script\u003e\n\u003cscript\u003e\n  almy.almy.subscribe('window_width', function(newWidth) {\n    //Do something with the new width\n  })\n\u003c/script\u003e\n\n```\nIncluding it as a module      \n```html\n\u003cdiv id=\"content\"\u003e\u003c/div\u003e\n\u003cscript type='module'\u003e\n    import {almy} from './node_modules/almy/dist/almy.esm.js'\n\n    almy.subscribe('user-\u003ename', (username) =\u003e {\n        document.getElementById('content').textContent = username;\n    });\n\n    almy.dispatch('user', {id: 1, name: 'nick'})\n\u003c/script\u003e\n```   \n\nUsing in a node environment\n```js\nconst { almy } = require('almy')\nalmy.subscribe('cpu_usage', function(newCpuUsage) {\n    //Do something with the new cpu usage\n})\n\n//In some other place in your code\nalmy.dispatch('cpu_usage', 9000)\n```\n\nYou can also dispatch objects:\n```js\nconst { almy } = require('almy')\nalmy.subscribe('cpu', function(cpu) {\n    console.log(cpu.temperature)\n})\n\nalmy.dispatch('cpu-\u003etemperature', 65)\n```\nOr subscribe to objects properties and receive every change:\n```js\nalmy.subscribe('cpu-\u003eips', function(ips) {\n    console.log('Intructions per seconds are '+ips)\n});\n...\n\nalmy.dispatch('cpu', {ips: 1})\n\n...\n\nalmy.dispatch('cpu', {ips: 5})\n\n// This would ouput:\n// \"Intructions per seconds are 1\"\n// \"Intructions per seconds are 5\"\n```\n\n## Limitations\n\nOnly one object deepness subscriptions are supported. Example:\n\n````js\nalmy.dispatch('user', {favorites: {televisions: {'4k': true}}})\n\n// This doesn't work\nalmy.subscribe('user-\u003efavorites-\u003etelevisions-\u003e4k', value =\u003e {\n    \n})\n\n// This does work\nalmy.subscribe('user-\u003efavorites', favorites =\u003e {\n    if (favorites.televisions['4k']) {\n        \n    }\n})\n````\n\nA flatten state is easier to reason and understand.\n\n## Other state management libraries\n\n-  Vuex: https://github.com/vuejs/vuex\n-  Redux: https://github.com/reduxjs/redux\n-  Flux: https://github.com/facebook/flux\n\n## References\n\nWorlds: Controlling the Scope of Side Effects\nhttp://www.vpri.org/pdf/tr2011001_final_worlds.pdf\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomas2387%2Falmy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomas2387%2Falmy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomas2387%2Falmy/lists"}