1.1.1 • Published 2 years ago

reapex v1.1.1

Weekly downloads
373
License
MIT
Repository
github
Last release
2 years ago

Reapex

travis-ci github-workflow npm issues license

Reapex is a lightweight "framework" written in TypeScript to build pluggable and extendable redux(react) application. It greatly reduced the boilerpates of a regular redux based application.

Reapex is designed in a way that modules have a clear boundary with each other. It provides strong-typed everything out of the box.

You can use reapex to create shareable modules easily. And share the modules among projects or publishing to npm and share with the public. Such as reapex-plugin-dataloader

Built with the love of TypeScript

Reapex is written with TypeScript and it provides strong-typed state, selectors, actions.

Documentation

Examples

  1. Counter: A simple Counter example
  2. Login Form: Side effects handling with the demo of API call

Getting started with a simple Counter example

npm i reapex@latest --save

Peer dependencies

npm i react react-dom redux react-redux redux-saga --save

1. Initialize the application

import { App } from 'reapex'

const app = new App()

2. Create a model(the shape of the state)

const CounterModel = app.model('Counter', { total: 0 })

3. Defined the mutations: how you want the state to be mutated

const [mutations] = counter.mutations({
  increase: () => s => ({...s, total: s.total + 1}),
  decrease: () => s => ({...s, total: s.total - 1}),
})

4. Connect it with Component

react-redux users should be very familiar with the following codes, it is a typical react-redux container, but with action creators and selectors which provided by reapex.

import React from 'react'
import { useSelector, useDispatch, Provider } from 'react-redux'

export const Counter = () => {
  // reapex generate selectors for all the fields of the state
  const total = useSelector(CounterModel.selectors.total)
  const dispatch = useDispatch()

  return (
    <>
      <button onClick={() => dispatch(mutations.decrease())}>-</button>
      {props.total}
      <button onClick={() => dispatch(mutations.increase())}>+</button>
    </>
  )
}

5. Render it!

import React from 'react'
import { render } from 'react-dom'
import { Provider } from 'react-redux'

const store = app.createStore()

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

Use Immutable Record as the state

import { Record } from 'immutable'

const CounterState = Record({ total: 0 })
const CounterModel = app.model('Counter', new CounterState())

// the state here is an Immutable Record
const [mutations] = counter.mutations({
  increase: () => s => s.set('total', s.total + 1),
  decrease: () => s => s.set('total', s.total - 1),
})

Integration with immerjs

import immerPlugin from 'reapex-plugin-immer'

app.plugin(immerPlugin)

const CounterModel = app.model('Counter', { total: 0 })
const [mutations] = counter.mutations({
  increase: () => s => {
    s.total = s.total + 1
    return s
  },
  decrease: () => s => {
    s.total = s.total - 1
    return s
  },
})

Checkout reapex-plugin-immer

1.1.1

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago

1.0.0-beta.28

2 years ago

1.0.0-beta.27

2 years ago

0.11.7

2 years ago

1.0.0-beta.26

3 years ago

1.0.0-beta.22

3 years ago

1.0.0-beta.23

3 years ago

1.0.0-beta.21

3 years ago

1.0.0-beta.20

3 years ago

1.0.0-beta.19

3 years ago

1.0.0-beta.18

3 years ago

1.0.0-beta.17

3 years ago

1.0.0-beta.16

3 years ago

1.0.0-beta.15

3 years ago

1.0.0-beta.14

3 years ago

1.0.0-beta.13

3 years ago

1.0.0-beta.11

3 years ago

1.0.0-beta.12

3 years ago

1.0.0-beta.10

3 years ago

1.0.0-beta.9

3 years ago

1.0.0-beta.8

3 years ago

1.0.0-beta.7

3 years ago

1.0.0-beta.5

4 years ago

1.0.0-beta.4

4 years ago

1.0.0-beta.3

4 years ago

1.0.0-beta.2

4 years ago

1.0.0-beta.1

4 years ago

0.12.0

4 years ago

0.11.6

4 years ago

0.11.5

4 years ago

0.11.4

4 years ago

0.11.3

4 years ago

0.11.2

4 years ago

0.11.1

4 years ago

0.11.0

4 years ago

0.10.2

4 years ago

0.10.1

4 years ago

0.10.0

4 years ago

0.9.1

5 years ago

0.9.0

5 years ago

0.8.6

5 years ago

0.8.5

5 years ago

0.8.4

5 years ago

0.8.3

5 years ago

0.8.2

5 years ago

0.8.1

5 years ago

0.8.0

5 years ago

0.7.3

5 years ago

0.7.2

5 years ago

0.7.1

5 years ago

0.7.0

5 years ago

0.6.11

5 years ago

0.6.10

5 years ago

0.6.9

5 years ago

0.6.8

5 years ago

0.6.7

5 years ago

0.6.6

5 years ago

0.6.5

5 years ago

0.6.4

5 years ago

0.6.3

5 years ago

0.6.2

5 years ago

0.6.1

5 years ago

0.6.0

5 years ago

0.5.1

5 years ago

0.5.0

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.0

5 years ago

0.2.9

5 years ago

0.2.8

5 years ago

0.2.7

5 years ago

0.2.6

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago