snootforge

chee/jquery.redux

Unnamed repository; edit this file 'description' to name the repository.

⚠ DEPRECATED ⚠

jquery.redux

$element can have little a reducer, as a treat

usage

setup

  1. <script src="https://git.snoot.club/chee/jquery.redux/raw/master/jquery.redux.min.js">

Note! Make sure to include it after jquery!!

set-reducer

  1. var initialState = 0;
  2. function reducer( state, action ) {
  3. state = state || initialState
  4. switch( action.type ) {
  5. case "+":
  6. return state + 1
  7. case "-":
  8. return state - 1
  9. case "@jQuery/init":
  10. return 0
  11. default:
  12. return state;
  13. }
  14. }
  15. $( "#my-element" ).redux( "set-reducer", { reducer } );

dispatch

  1. $("#my-element")
  2. .redux("dispatch", {
  3. action: {
  4. type: "+"
  5. }
  6. })
  7. .redux("dispatch", {
  8. action: {
  9. type: "+"
  10. }
  11. })

get-state

  1. $( "#my-element" ).redux( "get-state" ); //=> 2