Comparing version 0.0.1 to 0.0.2
@@ -1,3 +0,4 @@ | ||
import { combineReducers } from "redux" | ||
import { createStore, combineReducers } from "redux" | ||
import { fromJS } from "immutable" | ||
/** | ||
@@ -9,5 +10,19 @@ * Création d'un store partiel et réutilisable | ||
static connect(store, reducers) { | ||
static createReduxStore(reducer, preloadedState, enhancer) { | ||
const DEVTOOLS = window.__REDUX_DEVTOOLS_EXTENSION__ | ||
reducer = reducer || ((state = {}) => state) | ||
Heridux._globalStore = createStore( | ||
reducer, | ||
preloadedState, | ||
enhancer || (DEVTOOLS && DEVTOOLS()) | ||
) | ||
Heridux._reducers = reducer | ||
} | ||
static connect(store, initialReducers) { | ||
Heridux._globalStore = store | ||
Heridux._reducers = reducers | ||
Heridux._reducers = initialReducers | ||
} | ||
@@ -243,2 +258,5 @@ | ||
} | ||
subscribe(callback) { | ||
return Heridux._globalStore.subscribe(callback) | ||
} | ||
} |
{ | ||
"name": "heridux", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "the simpliest way to use and reuse redux stores", | ||
@@ -11,4 +11,5 @@ "main": "lib/index.js", | ||
"eslint": "^5.16.0", | ||
"rollup-plugin-node-globals": "^1.4.0", | ||
"rollup-plugin-node-resolve": "^4.2.3", | ||
"rollup-plugin-node-globals": "^1.4.0" | ||
"rollup-watch": "^4.3.1" | ||
}, | ||
@@ -18,3 +19,7 @@ "dependencies": { | ||
"redux": "^4.0.1" | ||
}, | ||
"scripts": { | ||
"build": "rollup -c", | ||
"dev": "rollup -c -w" | ||
} | ||
} |
@@ -1,2 +0,37 @@ | ||
# heridux | ||
The simpliest way to use and reuse redux stores | ||
# Heridux | ||
The simpliest way to use and reuse redux stores. | ||
See especially [react-heridux](https://github.com/YannickBochatay/react-heridux). | ||
### Installation | ||
With npm or yarn. | ||
```shell | ||
npm install heridux | ||
``` | ||
```shell | ||
yarn install heridux | ||
``` | ||
### Basic example | ||
```javascript | ||
import Heridux from "heridux" | ||
Heridux.createReduxStore() //create global redux store | ||
const hStore = new Heridux("keyForPartialStore") // create as many partial stores as you want | ||
hStore.setInitialState({ counter : 0 }) // state will be converted to Immutable | ||
hStore.createAction("increment", state => ( // define your actions | ||
state.update("counter", state.get("counter") + 1) | ||
)) | ||
hStore.createAction("decrement", state => ( | ||
state.set("counter", state.get("counter") - 1) | ||
)) | ||
hStore.register() // register this store to the global redux store | ||
``` | ||
### Example in action | ||
[http://yannickbochatay.github.io/heridux](http://yannickbochatay.github.io/heridux/) |
@@ -6,7 +6,5 @@ import nodeResolve from "rollup-plugin-node-resolve" | ||
input: 'lib/index.js', | ||
output: { | ||
file: 'build.js', | ||
format: 'esm' | ||
}, | ||
dest: 'bundle.js', | ||
format: 'esm', | ||
plugins :[nodeResolve(), nodeGlobals()] | ||
} |
import Heridux from "./build.js" | ||
console.log("Heridux found !", Heridux) | ||
Heridux.createReduxStore() | ||
const hStore = new Heridux("counterStore") | ||
hStore.setInitialState({ counter : 0 }) | ||
hStore.createAction("increment", state => ( | ||
state.set("counter", state.get("counter") + 1) | ||
)) | ||
hStore.createAction("decrement", state => ( | ||
state.set("counter", state.get("counter") - 1) | ||
)) | ||
hStore.register() | ||
/////////////////////////////////////////////////////////// | ||
const valueEl = document.getElementById('value') | ||
const render = () => valueEl.innerHTML = hStore.get("counter") | ||
render() | ||
hStore.subscribe(render) | ||
document.getElementById('increment') | ||
.addEventListener('click', () => hStore.execAction("increment")) | ||
document.getElementById('decrement') | ||
.addEventListener('click', () => hStore.execAction("decrement")) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
37
84549
4
10
265
1