1.6.0 • Published 5 years ago

modular-react v1.6.0

Weekly downloads
48
License
-
Repository
-
Last release
5 years ago

modular-react

Example usage

import {
  createStore,
  dispatch,
  AppContainer,
  actionIs,
  alter,
  replace
} from 'modular-react'

const setName = name => dispatch({
  type: 'SET_NAME',
  name
})

const App = ({ name, children }) =>
  <div>
    <p onClick={() => setName('Lily')}> 
      {name}
    </p>
    { children }
  </div>

const initialState = {
  app: {
    element: App,
    props: [['people', 1]],
    children: []
  },
  data: {
    people: [
      'John',
      'Mary'
    ]
  }
}

const actionsToStates = [
  [
    actionIs('SET_NAME'),
    replace(['people', 1])
  ]
]

const state$ = createStore(initialState, actionsToStates)

<AppContainer state$={state$} />
// -> Build the app according to state. 

Info

initialState

Components are setup by following example:

{
  element: App, 
  // Where App is an component.
  
  props: [['data', 'people', 0, 'name'], ...], 
  // Declares a path to wanted prop. Accept multiple paths to props as arrays. Example equals state.data.people[0].name
  
  children: [
    {
      element: ...
      ...
    },
    ...
  ]
  // Children can be components presented in the same way as shown or just text
}

actionsToState

Setup

yarn add modular-react
1.6.0

5 years ago

1.5.0

5 years ago

1.4.0

5 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago