Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
chee committed Feb 14, 2020
0 parents commit 2e2d1a8
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
54 changes: 54 additions & 0 deletions README.md
@@ -0,0 +1,54 @@
⚠ DEPRECATED ⚠

# jquery.redux

## usage

### setup

```html
<script src="https://git.snoot.club/chee/jquery.redux/blob/jquery.redux.min.js">
```
### set-reducer
```js
var initialState = 0;
function reducer(state, action) {
state = state || initialState
switch(action.type) {
case "+":
return state + 1
case "-":
return state - 1
case "@jQuery/init":
return 0
default:
return state;
}
}
$( "#my-element" ).redux( "set-reducer", { reducer } );
```
### dispatch
```
$("#my-element")
.redux("dispatch", {
action: {
type: "+"
}
})
.redux("dispatch", {
action: {
type: "+"
}
})
```
### get-state
```js
$( "#my-element" ).redux( "get-state" ); //=> 2
```
25 changes: 25 additions & 0 deletions jquery.redux.js
@@ -0,0 +1,25 @@
(function ( $, window, undefined ) {
$.fn.redux = function ( action, options ) {
options = options || {};

if ( action == "get-state" ) {
return this.data( "state" );
}

if (action == "set-reducer" ) {
this.data( "reducer", options.reducer );
this.data(
"state",
options.reducer(null, {
type: "@jQuery/init"
})
);
return this;
}

if ( action == "dispatch" ) {
this.data( "state", this.data( "reducer" )( this.data( "state" ), options.action ) );
return this;
}
}
})( jQuery, ( eval, eval )( "this" ), void undefined );
1 change: 1 addition & 0 deletions jquery.redux.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2e2d1a8

Please sign in to comment.