Ajwah
Rx based store library for React, Vue, Angular, Preact. Manage your application's states, effects, and actions easy way. It's easy to use in functional components with React hooks.
Installation
>> npm install ajwah-store>> npm install ajwah-devtools
In Ajwah there are two different coding styles
- Coding by Decorators
- Coding by Convention
Here are the samples of all the decorators and it's corresponding coding by convention
@Action()
@ { return } // Convention: function name starts with `action` followed by action name - [action][actionName](...){...} { return }
@Effect()
@ { return actions } // Convention: function name starts with `effect` followed by anything - [effect][any](...){...} { return actions } //@Effect(...) decoretor: you may pass `dispatch:flase` - by default it's true. if you pass `false`, you effect should be disabled. @ { return actions } //Convention: for `dispatch:false` - just function name ends with `_ndispatch` { return actions } // you may use `For` for getting rid of `ofType('...')` - [effect][For][actionName](...){...}. // Use 'Or' for multiple actions name. ex: effectForAsyncIncOrDec(...) // - [effect][For][actionName][Or][actionName][Or][actionName][...](){} { return actions } // '_ndispatch' with `For` ex: effectForAsyncInc_ndispatch() { return actions }
@State()
@ //Convention: name= 'counter'; initialState= count: 5 msg: '' ;
@EffectKey()
@ //Convention: effectKey=DYNAMIC_EFFECTS_KEY;
Note: Please remember the starts with 'action' and 'effect'. This is by default. You may change whatever you want into the 'setStoreContext'
Vue //Now your actions and effects should be { return } { return actions }
babel.config.js
file.
To enable decoretors if you want: For Vue Cli if you choose Typescript, everything is ok. Otherwise you need to enable decorators supprot in moduleexports = presets: '@vue/app' plugins: "@babel/plugin-proposal-decorators" legacy: true
need to install the following plugin
>> npm install --save-dev @babel/plugin-proposal-decorators
Now let's install Ajwah store and others helping lib
>> npm install rxjs>> npm install vue-rx>> npm install ajwah-store>> npm install ajwah-devtools //optional>> npm run serve
counterState
Let's start with the hello world counterState using decoretors
;;;; @ @ { return } @ { return } @ { return } @ { return action$ } ;
counterState using convention
;;;; name = 'counter' initialState = count: 10 msg: '' { return } { return } { return } { return actions };
You can choose any style you like or any combination - ajwah support both together
CounterComponent
<template> <p> <button class="btn" @click="inc()">+</button> <button class="btn" @click="dec()">-</button> <button class="btn" @click="async_inc()">async+</button> countermsg||countercount </p></template> <script>; name: "Counter" { return counter: thisstoreCtx ; } methods: { thisstoreCtx; } { thisstoreCtx; } { thisstoreCtx; } ;</script>
StoreContext API
Here is the : StoreContext; : StoreContext; : StoreContext; : StoreContext; : StoreContext; : StoreContext; : StoreContext; : Observable<any>; select<T = any>pathOrMapFn: any | string : Observable<any>; addEffect<T extends Actions<Action>> Observable<Action> key?: string: StoreContext; : StoreContext; : void;
AjwahStore
in main file
using ;;; ;;; Vue; Vue VueconfigproductionTip = false; router ;
Note: this lib renamed as ajwah-store