All Projects β†’ tomas2387 β†’ almy

tomas2387 / almy

Licence: MIT license
πŸ—„οΈ 673 bytes store for managing the state in your application

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to almy

magnetar
A framework-agnostic syncing solution that auto-connects any DB/API with your local data store and has optimistic-UI built in 🌟
Stars: ✭ 36 (+38.46%)
Mutual labels:  state-management
tuxi
✨ White glove service for your async needs
Stars: ✭ 14 (-46.15%)
Mutual labels:  state-management
storken
🦩 Storken is a React State Manager. Simple as `useState`.
Stars: ✭ 22 (-15.38%)
Mutual labels:  state-management
vana
Observe your immutable state trees πŸŒ²πŸ‘€ (great with React)
Stars: ✭ 24 (-7.69%)
Mutual labels:  state-management
swr-internal-state
Use SWR to manage app's internal state
Stars: ✭ 32 (+23.08%)
Mutual labels:  state-management
crypto-currency
A Flutter application showing crypto currency rates.
Stars: ✭ 16 (-38.46%)
Mutual labels:  state-management
mobius.kt
Kotlin Multiplatform framework for managing state evolution and side-effects
Stars: ✭ 39 (+50%)
Mutual labels:  state-management
mst-effect
πŸ’« Designed to be used with MobX-State-Tree to create asynchronous actions using RxJS.
Stars: ✭ 19 (-26.92%)
Mutual labels:  state-management
screenmanager
Stackable Screen/State Management for the LΓ–VE framework.
Stars: ✭ 29 (+11.54%)
Mutual labels:  state-management
quick-redux
helper functions to make redux and react development quicker
Stars: ✭ 61 (+134.62%)
Mutual labels:  state-management
service-tree
[ABANDONED] A tree that stores services in its node for a given key, and allows traversing them.
Stars: ✭ 33 (+26.92%)
Mutual labels:  state-management
Accounting
A simple accounting app that provides basic additions, deletions, modifications, and provides a simple summary page, which is implemented by using MVI pattern.
Stars: ✭ 30 (+15.38%)
Mutual labels:  state-management
reactive-states
Reactive state implementations (brainstorming)
Stars: ✭ 51 (+96.15%)
Mutual labels:  state-management
onli-reducer
βš›οΈ One line reducer. State management without boilerplate.
Stars: ✭ 31 (+19.23%)
Mutual labels:  state-management
gstate
A crazy state management for lazy programmers
Stars: ✭ 27 (+3.85%)
Mutual labels:  state-management
rematch
The Redux Framework
Stars: ✭ 8,340 (+31976.92%)
Mutual labels:  state-management
bloc
A predictable state management library that helps implement the BLoC design pattern
Stars: ✭ 12 (-53.85%)
Mutual labels:  state-management
ngx-mobx
Mobx decorators for Angular Applications
Stars: ✭ 14 (-46.15%)
Mutual labels:  state-management
atomic-state
Atomic State is a state management library for React
Stars: ✭ 15 (-42.31%)
Mutual labels:  state-management
yurt
high quality mounted real (e)states
Stars: ✭ 53 (+103.85%)
Mutual labels:  state-management

πŸ—„οΈ almy

Version Build Status Coverage Status npm bundle size

The simpliest store for managing the state in your application.
Works in all environments and all browsers.

Why do I need a centralized state management

Managing 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.

To 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.

Installation

npm install --save almy

Methods

  • dispatch(key: string, value: any)
    Dispatches some event that happened in a key value fashion
  • subscribe(key: string, callback: Function)
    Subscribes to dispatched events. If someone has dispatched an event before, it calls the callback right away
  • state(key:?string):Object
    Returns the state of your application

Usage

Including it as a script tag

<script src="./node_modules/almy/dist/almy.umd.js"></script>
<script>
  almy.almy.dispatch('window_width', 524)
</script>
<script>
  almy.almy.subscribe('window_width', function(newWidth) {
    //Do something with the new width
  })
</script>

Including it as a module

<div id="content"></div>
<script type='module'>
    import {almy} from './node_modules/almy/dist/almy.esm.js'

    almy.subscribe('user->name', (username) => {
        document.getElementById('content').textContent = username;
    });

    almy.dispatch('user', {id: 1, name: 'nick'})
</script>

Using in a node environment

const { almy } = require('almy')
almy.subscribe('cpu_usage', function(newCpuUsage) {
    //Do something with the new cpu usage
})

//In some other place in your code
almy.dispatch('cpu_usage', 9000)

You can also dispatch objects:

const { almy } = require('almy')
almy.subscribe('cpu', function(cpu) {
    console.log(cpu.temperature)
})

almy.dispatch('cpu->temperature', 65)

Or subscribe to objects properties and receive every change:

almy.subscribe('cpu->ips', function(ips) {
    console.log('Intructions per seconds are '+ips)
});
...

almy.dispatch('cpu', {ips: 1})

...

almy.dispatch('cpu', {ips: 5})

// This would ouput:
// "Intructions per seconds are 1"
// "Intructions per seconds are 5"

Limitations

Only one object deepness subscriptions are supported. Example:

almy.dispatch('user', {favorites: {televisions: {'4k': true}}})

// This doesn't work
almy.subscribe('user->favorites->televisions->4k', value => {
    
})

// This does work
almy.subscribe('user->favorites', favorites => {
    if (favorites.televisions['4k']) {
        
    }
})

A flatten state is easier to reason and understand.

Other state management libraries

References

Worlds: Controlling the Scope of Side Effects http://www.vpri.org/pdf/tr2011001_final_worlds.pdf

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].