Giter VIP home page Giter VIP logo

Heridux

The easiest way to use and reuse redux stores or react internal states.

Packages

@heridux/core

A few lines of code to make redux more user-friendly, reusable and expandable.

import Heridux from "@heridux/core"

const store = new Heridux("counterStore")

store.setInitialState({ counter : 0 })

store.createAction("increment", state => ({
  ...state, counter : state.counter + 1
}))

store.createAction("decrement", state => ({
  ...state, counter : state.counter - 1
}))

store.register()

store.execAction("increment")
store.get("counter") // 1

@heridux/immer

Manage your state with ImmerJS

import Heridux from "@heridux/immer"

const store = new Heridux("counterStore")

store.setInitialState({ counter : 0 })

store.createAction("increment", state => {
  state.counter++
})

store.createAction("decrement", state => {
  state.counter--
})

@heridux/imutable

Manage your state with ImmutableJS

import Heridux from "@heridux/immutable"

const store = new Heridux("counterStore")

store.setInitialState({ counter : 0 })

store.createAction("increment", state => (
  state.set("counter", state.get("counter") + 1)
))

store.createAction("decrement", state => (
  state.set("counter", state.get("counter") - 1)
))

@heridux/react

Use heridux with react (HOC or hook).

import { useStore, useSelector } from "@heridux/react"

const MyComponent = () => {
  const store = useStore()
  const counter = useSelector(state => state.counter)

  return (
    <div>
      <p>Clicked: <span>{ counter }</span> times</p>
      <button onClick={ () => store.execAction("increment") }>+</button>
      <button onClick={ () => store.execAction("decrement") }>-</button>
    </div>
  )
}

@heridux/form-rules

Type check your fields the way you know it with PropTypes

import Rules from "@heridux/form-rules"

const form = {
  name : Rules.minLength(2).isRequired,
  age : Rules.number,
  birthday : Rules.date,
  genre : Rules.oneOf(["male", "female"]),
  email : Rules.email,
  hobbies : Rules.arrayOf([Rules.string])
}

try {
  form.name.check("Foo")
} catch (e) {
  console.error(e.message)
}

@heridux/form

Manage your forms easily with heridux-form.

import HeriduxForm from "@heridux/form"
import Rules from "@heridux/rules"

const store = new HeriduxForm("myForm")

store.defineForm({
  name : Rules.string.isRequired,
  age : Rules.number,
  address : {
    street : Rules.string,
    city : Rules.string,
    zipCode : Rules.number
  }
})

store.register()

store.initFormValues({
  name : "Roger",
  age : 56
})

store.setFieldValue(["address", "city"], "Paris")

store.getFieldValue("age") // 56

@heridux/form-arrays

Manage easily array fields with heridux

import HeriduxForm from "@heridux/form"
import Rules from "@heridux/form-rules"
import FormArrays from "@heridux/form-arrays"

const store = new HeriduxForm("myForm")

store.defineForm({
  name : Rules.string.isRequired,
  age : Rules.number,
  friends : FormArray({
    name : Rules.string.isRequired,
    age : Rules.number
  })
})

store.register()

@heridux/react-form

Use heridux forms with React

import { useFormControl } from "@heridux/react-form"

const Field = ({ formKey }) => {
  const { value, onChange, error } = useFormControl(formKey)

  return (
    <div>
      <input value={ value } onChange={ onChange }>
      { error && <span style={ { color : "red" } }>{ error }</span>}
    </div>
  )
}

heridux's Projects

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.