All Projects → d-band → yax

d-band / yax

Licence: other
Yet another store using redux. (Inspired by vuex and dva)

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to yax

chatty
A React single-page-application alternative client for the shacknews chatty.
Stars: ✭ 27 (-58.46%)
Mutual labels:  react-router
edliz
This 7th essential medicines list and standard treatment guidelines for the most common health conditions in Zimbabwe has been endorsed by the National Medicine & Therapeutics Policy Advisory Committee [NMTPAC]. It is the product of many years of combined efforts by hundreds of health workers at all levels of the health care system in Zimbabwe. …
Stars: ✭ 25 (-61.54%)
Mutual labels:  react-router
awesome-ecommerce
Collect and develop Open Source or Free Projects for building ecommerce platform easy and fast and free
Stars: ✭ 39 (-40%)
Mutual labels:  store
myBlog
💊personal website: FE:React;BE:Django
Stars: ✭ 26 (-60%)
Mutual labels:  react-router
Fakeflix
Not the usual clone that you can find on the web.
Stars: ✭ 4,429 (+6713.85%)
Mutual labels:  react-router
parcelui
Parcel + Typescript + React/Preact + Router + CSS Modules + SASS + Jest + Api-Now + Github Actions CI
Stars: ✭ 32 (-50.77%)
Mutual labels:  react-router
Gitzilla
A resume builder for your GitHub profile.
Stars: ✭ 60 (-7.69%)
Mutual labels:  react-router
trivin
⚡️Setup your entire project quickly and easily with 1-line command ⚡️
Stars: ✭ 58 (-10.77%)
Mutual labels:  react-router
react-flux-gulp-starter
A universal boilerplate for building React/Flux apps using Gulp and ES6.
Stars: ✭ 46 (-29.23%)
Mutual labels:  react-router
react-douban
A React project
Stars: ✭ 21 (-67.69%)
Mutual labels:  react-router
react16-seed-with-apollo-graphql-scss-router4-ssr-tests-eslint-prettier-docker-webpack3-hot
Seed to create your own project using React with Apollo GraphQL client
Stars: ✭ 19 (-70.77%)
Mutual labels:  react-router
yarr
A React router library enabling the render-as-you-fetch concurrent UI pattern.
Stars: ✭ 97 (+49.23%)
Mutual labels:  react-router
store-ue4-sdk
Xsolla Store plugin for Unreal Engine 4
Stars: ✭ 17 (-73.85%)
Mutual labels:  store
GOSH-FHIRworks2020-React-Dashboard
🩺 Fully Responsive FHIR Dashboard written using @reactjs for NHS and GOSH hackathon
Stars: ✭ 21 (-67.69%)
Mutual labels:  react-router
svelte-persistent-store
A Svelte store that keep its value through pages and reloads
Stars: ✭ 111 (+70.77%)
Mutual labels:  store
cra-redux-boilerplate
⚛️🔨create-react-app application with redux and another cool libraries to make your life easier.
Stars: ✭ 15 (-76.92%)
Mutual labels:  react-router
kodlama.io-javareactcamp
Java - React Camp Works | Kodlama.io
Stars: ✭ 33 (-49.23%)
Mutual labels:  react-router
DwinaTech-Shop
E-commerce application. created for education and learning
Stars: ✭ 35 (-46.15%)
Mutual labels:  react-router
froute
Type safe and flexible router for React
Stars: ✭ 31 (-52.31%)
Mutual labels:  react-router
react-social-network
react social network
Stars: ✭ 13 (-80%)
Mutual labels:  react-router

Yax (Yet Another Store)

NPM version NPM downloads Build Status Coverage Status Dependency Status Greenkeeper badge

Yet another store using redux. (Inspired by vuex and dva)

Demos & Plugins

  • yax-router: Router plugin for yax (Using react-router).
  • HackerNews: HackerNews clone built with Yax, based on dva-hackernews.

Getting Started

Install

$ npm install --save yax

Usage Example

import yax from 'yax';

const delay = ms => new Promise(resolve => setTimeout(resolve, ms));

const count = {
  state: 0,
  reducers: {
    addDone (state, payload) {
      return state + payload;
    },
    minusDone (state, payload) {
      return state - payload;
    }
  },
  actions: {
    async add ({ commit }, payload) {
      await delay(1);
      commit('addDone', payload);
    },
    async minus ({ commit }, payload) {
      await delay(1);
      commit('minusDone', payload);
    }
  }
};
const store = yax({
  modules: { count }
});

store.subscribe(() =>
  console.log(store.getState())
);

store.dispatch({
  type: 'count/add',
  payload: 2
});
store.dispatch({
  type: 'count/minus',
  payload: 1
});

Usage with React

import React from 'react';
import { render } from 'react-dom';
import { Provider } from 'react-redux';
import yax from 'yax';
import count from './count';
import App from './App';

const store = yax({
  modules: { count }
});

render(
  <Provider store={store}>
    <App />
  </Provider>,
  document.getElementById('root')
);

Usage with redux-persist

import yax from 'yax';
import { persistStore, autoRehydrate } from 'redux-persist';

const store = yax(options, autoRehydrate());

persistStore(store, { storage: Storage });

Usage with react-navigation

import yax, { compose, composeReducers, mapReducers } from 'yax';
import { StackNavigator } from 'react-navigation';

const AppNavigator = StackNavigator(AppRouteConfigs);
const initialAction = AppNavigator.router.getActionForPathAndParams('Login');
const initialState = AppNavigator.router.getStateForAction(initialAction);

const navReducer = (state = initialState, action) => {
  const nextState = AppNavigator.router.getStateForAction(action, state);
  return nextState || state;
};
const navEnhancer = createStore => (reducer, preloadedState, enhancer) => {
  const appReducer = composeReducers(
    reducer,
    mapReducers({
      nav: navReducer
    })
  );
  return createStore(appReducer, preloadedState, enhancer);
};
const store = yax({
  modules: { foo, bar }
}, compose(
  navEnhancer,
  otherEnhancers
));


// In modules with `commit`
import { NavigationActions } from 'react-navigation';

const LOGIN = NavigationActions.navigate({ routeName: 'Login' });
const BACK = NavigationActions.back();
...
commit(LOGIN, true);
commit(BACK, true);

API Reference

import yax, {
  // Redux original functions
  combineReducers,
  bindActionCreators,
  applyMiddleware,
  compose,
  // Yax helper functions
  composeReducers,
  mapReducers,
  mapState,
  mapActions
} from 'yax';

yax(options = {}, [enhancer])

  • options.state

    The root state object for the store.

  • options.reducers

    { [type: string]: Reducer }
    
    type Reducer = (state, payload) => state
    

    state will be module local state if defined in a module

  • options.actions

    { [type: string]: Action }
    
    type Action = ({ dispatch, commit, select }, payload) => Promise
    
    type dispatch = (type, payload, isRoot) => Promise
    type commit   = (type, payload, isRoot) => any
    

    isRoot=true will dispatch actions or commit reducers in the global namespace

    type select   = (Selector) => Selector(state, rootState)
    type Selector = (state, rootState) => any
    

    select() without Selector will return state

  • options.modules

    { [type: string]: Module }
    
    type Module = { state, reducers, actions, modules }
    
  • enhancer

    type StoreEnhancer = (next: StoreCreator) => StoreCreator
    

    redux store enhancer

composeReducers(...reducers)

const f = (state, action) => {};
const g = (state, action) => {};
// (state, action) => g(f(state, action), action)
const reducer = composeReducers(f, g);

mapReducers(reducers)

Like with combineReducers but composability. More

const foo = (state, action) => {};
const bar = (state, action) => {};
const reducer = mapReducers({ foo, bar });

mapState and mapActions

Used for react-redux connect

const App = ({ foo, bar, addFoo, addBar }) => {
  addFoo(payload);
  addBar(payload);
  return <span>{foo} / {bar}</span>;
};
connect(
  mapState({
    foo: 'foo/value',
    bar: 'bar/value'
  }),
  mapActions({
    addFoo: 'foo/add',
    addBar: 'bar/add'
  })
)(App);

Report a issue

License

yax is available under the terms of the MIT License.

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