2.0.8 • Published 4 years ago

reduxwork v2.0.8

Weekly downloads
6
License
MIT
Repository
github
Last release
4 years ago

Reduxwork

Build Status

A small Redux framework for creating actions and reducers that work with AJAX or WebSocket functions and create real-time apps.

For the previous version and installation, instructions, pleas check the https://github.com/michalkow/reduxwork/tree/v1(v1 branch).

Install

Install from npm:

npm install reduxwork 

You need to have redux and redux-offline

Usage

Actions and reducer configuration options and defaults

const reduxwork = new Reduxwork({
  keyName: 'id',// Name of identificator key in your database.
  addKeyOnCreate: false, // Reducers only. When creating a temporary item (before socket/fetch) random indentificator will be added.
  rewriteOnUpdate: true,
  socketEventName: 'redux_action_event', // Actions only. Name of event that will be send by socket.io.
  socket: null, // Actions only. Socket funtion to use for transport.
  transport: 'fetch',
  virtualFieldsName: 'virtualFields',
  localFieldsName: 'localFields',
  uuidOptions: {},
  uuidVersion: 'v4',
  actionInject: (action) => action,
  validationHook: null,
  createKey: null,
  schemas: {}
});

Use with redux and redux-offline

import { applyMiddleware, createStore, compose } from 'redux';
import { createOffline } from '@redux-offline/redux-offline';
import offlineConfig from '@redux-offline/redux-offline/lib/defaults';
import reduxwork from './reduxwork';
import reducers from './reducers';

const offlineOptions = Object.assign({}, offlineConfig, reduxwork.createOfflineOptions());

const { middleware, enhanceReducer, enhanceStore } = createOffline(offlineOptions);

const store = createStore(
  enhanceReducer(reduxwork.createRootReducer([reducers])),
  reduxwork.createInitialState(),
  compose(enhanceStore, applyMiddleware(middleware))
);

Reducer creators

import reduxwork from './reduxwork';

export default {
	// Standard creator
  messages: reduxwork.createIoReducers('messages'),
  // Creator with added state and actions to handle
  users: reduxwork.createIoReducers('users', {
   	WENT_ONLINE(state, action) {
      return Object.assign({}, state, {
      	online: [...state.online, action.data]
      })        
    },   
   	WENT_OFFLINE(state, action) {
      return Object.assign({}, state, {
      	online: _.reject([...state.online], action.data)
      })        
    }
  })
}

Action creators

import reduxwork from './reduxwork';

export var {
  findMessages,
  createMessages,
  updateMessages,
  destroyMessages,
  clearMessages,
  selectMessages,
  syncMessages,
  receiveMessages,
  resetMessages
} = reduxwork.createIoActions('Messages');

export var {
  findUsers,
  createUsers,
  updateUsers,
  destroyUsers,
  clearUsers,
  selectUsers,
  syncUsers,
  receiveUsers,
  resetUsers
} = reduxwork.createIoActions('Users');

export var wentOffline = reduxwork.createPostAction('WENT_OFFLINE');
export var wentOnline = reduxwork.createPostAction('WENT_ONLINE');

Framework

I created this libary while working on my own projects. It has been really useful, so I thought others might like it as well. It was created to fit me and my own style. Did my best to turn it into an open-source project that accounts for a broad range of usecases. If you have any feedback on style, naming or other things, please let me know or submit a pull request. Thanks!

License

Reduxwork is released under MIT license.

Credits

Reduxwork was created by Michał Kowalkowski. You can contact me at kowalkowski.michal@gmail.com

2.0.7

4 years ago

2.0.8

4 years ago

2.0.6

6 years ago

2.0.5

6 years ago

2.0.4

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.5.2

6 years ago

1.5.1

6 years ago

1.5.0

6 years ago

1.4.25

7 years ago

1.4.24

7 years ago

1.4.23

7 years ago

1.4.22

7 years ago

1.4.21

7 years ago

1.4.20

7 years ago

1.4.19

7 years ago

1.4.18

7 years ago

1.4.17

7 years ago

1.4.16

7 years ago

1.4.15

7 years ago

1.4.13

7 years ago

1.4.12

7 years ago

1.4.11

8 years ago

1.4.10

8 years ago

1.4.9

8 years ago

1.4.8

8 years ago

1.4.7

8 years ago

1.4.6

8 years ago

1.4.5

8 years ago

1.4.4

8 years ago

1.4.3

8 years ago

1.4.2

8 years ago

1.4.1

8 years ago

1.4.0

8 years ago

1.3.12

8 years ago

1.3.11

8 years ago

1.3.10

8 years ago

1.3.9

8 years ago

1.3.8

8 years ago

1.3.7

8 years ago

1.3.6

8 years ago

1.3.5

8 years ago

1.3.4

8 years ago

1.3.3

8 years ago

1.3.2

8 years ago

1.3.1

8 years ago

1.3.0

8 years ago

1.2.0

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.13

8 years ago

1.0.12

8 years ago

1.0.11

8 years ago

1.0.10

8 years ago

1.0.9

8 years ago

1.0.8

8 years ago

1.0.7

8 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago