Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@heridux/core

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@heridux/core - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

82

dist/index.js
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@babel/runtime/helpers/defineProperty'), require('redux'), require('immutable')) :
typeof define === 'function' && define.amd ? define(['exports', '@babel/runtime/helpers/defineProperty', 'redux', 'immutable'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Heridux = {}, global._defineProperty, global.redux, global.Immutable));
}(this, (function (exports, _defineProperty, redux, immutable) { 'use strict';
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@babel/runtime/helpers/defineProperty'), require('redux')) :
typeof define === 'function' && define.amd ? define(['exports', '@babel/runtime/helpers/defineProperty', 'redux'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Heridux = {}, global._defineProperty, global.redux));
}(this, (function (exports, _defineProperty, redux) { 'use strict';

@@ -58,38 +58,4 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

this._reducers = {};
this._createGenericActions();
}
/**
* Create generic action to set simple values in the store without creating named actions
* @private
* @returns {undefined}
*/
_createGenericActions() {
// in some classes inheriting from Heridux, createAction is overloaded
// we therefore make sure to take the original
const {
createAction
} = Heridux.prototype;
createAction.call(this, "set", (state, {
prop,
value
}) => state.set(prop, immutable.fromJS(value)));
}
/**
* Set a first level value without creating a specific action
* @param {String} prop property name
* @param {any} value property value
* @returns {undefined}
*/
set(prop, value) {
return this.execAction("set", {
prop,
value
});
}
/**
* Get full action name with prefix + SCREAMING_SNAKE_CASE action name

@@ -140,4 +106,4 @@ * @private

* Get store slice
* @param {Immutable.Map} [state] global state (if not specified, call getState method of redux store)
* @return {Immutable.Map} store slice
* @param {Object} [state] global state (if not specified, call getState method of redux store)
* @return {Object} store slice
*/

@@ -159,33 +125,11 @@

* @param {String} key key name
* @param {Immutable.Map} [state] global state (if not specified, call getState method of redux store)
* @return {*} key value (converted in plain js if immutable)
* @param {Object} [_state] global state (if not specified, call getState method of redux store)
* @return {*} key value
*/
get(key, state) {
var _value$toJS, _value$toJS2;
const value = this.getState(state).get(key);
return (_value$toJS = value === null || value === void 0 ? void 0 : (_value$toJS2 = value.toJS) === null || _value$toJS2 === void 0 ? void 0 : _value$toJS2.call(value)) !== null && _value$toJS !== void 0 ? _value$toJS : value;
get(key, _state) {
return this.getState(_state)[key];
}
/**
* Get js value of a nested key
* @example
* const store = new Heridux("myPartialStore")
* store.setInitialState({
* list : [{ name : "foo"}, { name : "bar" }]
* })
* store.getIn(["list", 0, "name"]) // foo
* @param {Array} path Iterable key path (more details in Immutable.js documentation)
* @param {Immutable.Map} [state] global state (if not specified, call getState method of redux store)
* @return {*} key value (converted in plain js if immutable)
* @see {@link https://immutable-js.github.io/immutable-js/}
*/
getIn(path, state) {
const value = this.getState(state).getIn(path);
return value && value.toJS ? value.toJS() : value;
}
/**
* Get action from short name action

@@ -202,3 +146,3 @@ * @private

/**
* Define the initial state of the store slice. It will automatically be converted to immutable.
* Define the initial state of the store slice
* @param {Object} state plain js state

@@ -210,3 +154,3 @@ * @return {undefined}

setInitialState(state) {
this.initialState = immutable.fromJS(state);
this.initialState = state;
}

@@ -319,3 +263,3 @@ /**

* @param {Object|Function} action redux action
* @return {undefined|Promise} promise if async
* @return {undefined}
*/

@@ -322,0 +266,0 @@

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { createStore, combineReducers } from 'redux';
import { fromJS } from 'immutable';

@@ -52,38 +51,4 @@ /**

this._reducers = {};
this._createGenericActions();
}
/**
* Create generic action to set simple values in the store without creating named actions
* @private
* @returns {undefined}
*/
_createGenericActions() {
// in some classes inheriting from Heridux, createAction is overloaded
// we therefore make sure to take the original
const {
createAction
} = Heridux.prototype;
createAction.call(this, "set", (state, {
prop,
value
}) => state.set(prop, fromJS(value)));
}
/**
* Set a first level value without creating a specific action
* @param {String} prop property name
* @param {any} value property value
* @returns {undefined}
*/
set(prop, value) {
return this.execAction("set", {
prop,
value
});
}
/**
* Get full action name with prefix + SCREAMING_SNAKE_CASE action name

@@ -134,4 +99,4 @@ * @private

* Get store slice
* @param {Immutable.Map} [state] global state (if not specified, call getState method of redux store)
* @return {Immutable.Map} store slice
* @param {Object} [state] global state (if not specified, call getState method of redux store)
* @return {Object} store slice
*/

@@ -153,33 +118,11 @@

* @param {String} key key name
* @param {Immutable.Map} [state] global state (if not specified, call getState method of redux store)
* @return {*} key value (converted in plain js if immutable)
* @param {Object} [_state] global state (if not specified, call getState method of redux store)
* @return {*} key value
*/
get(key, state) {
var _value$toJS, _value$toJS2;
const value = this.getState(state).get(key);
return (_value$toJS = value === null || value === void 0 ? void 0 : (_value$toJS2 = value.toJS) === null || _value$toJS2 === void 0 ? void 0 : _value$toJS2.call(value)) !== null && _value$toJS !== void 0 ? _value$toJS : value;
get(key, _state) {
return this.getState(_state)[key];
}
/**
* Get js value of a nested key
* @example
* const store = new Heridux("myPartialStore")
* store.setInitialState({
* list : [{ name : "foo"}, { name : "bar" }]
* })
* store.getIn(["list", 0, "name"]) // foo
* @param {Array} path Iterable key path (more details in Immutable.js documentation)
* @param {Immutable.Map} [state] global state (if not specified, call getState method of redux store)
* @return {*} key value (converted in plain js if immutable)
* @see {@link https://immutable-js.github.io/immutable-js/}
*/
getIn(path, state) {
const value = this.getState(state).getIn(path);
return value && value.toJS ? value.toJS() : value;
}
/**
* Get action from short name action

@@ -196,3 +139,3 @@ * @private

/**
* Define the initial state of the store slice. It will automatically be converted to immutable.
* Define the initial state of the store slice
* @param {Object} state plain js state

@@ -204,3 +147,3 @@ * @return {undefined}

setInitialState(state) {
this.initialState = fromJS(state);
this.initialState = state;
}

@@ -313,3 +256,3 @@ /**

* @param {Object|Function} action redux action
* @return {undefined|Promise} promise if async
* @return {undefined}
*/

@@ -316,0 +259,0 @@

3

package.json
{
"name": "@heridux/core",
"version": "0.0.2",
"version": "0.0.3",
"main": "lib/index.js",

@@ -14,3 +14,2 @@ "description": "The easiest way to use and reuse redux stores or react internal states",

"dependencies": {
"immutable": "^4.0.0-rc.12",
"redux": "^4.0.5",

@@ -17,0 +16,0 @@ "@babel/runtime": "^7.12.5"

@@ -7,21 +7,16 @@ <!-- Generated by documentation.js. Update this documentation by updating the source code. -->

- [Parameters][2]
- [set][3]
- [getState][3]
- [Parameters][4]
- [getState][5]
- [get][5]
- [Parameters][6]
- [get][7]
- [setInitialState][7]
- [Parameters][8]
- [getIn][9]
- [createAction][9]
- [Parameters][10]
- [Examples][11]
- [setInitialState][12]
- [execAction][12]
- [Parameters][13]
- [createAction][14]
- [Parameters][15]
- [Examples][16]
- [execAction][17]
- [Parameters][18]
- [register][19]
- [dispatch][20]
- [Parameters][21]
- [register][14]
- [dispatch][15]
- [Parameters][16]

@@ -34,15 +29,4 @@ ## Heridux

- `STATE_PROPERTY` **[String][22]** string name for this slice of state. Generated actions wille use this as a prefix.
- `STATE_PROPERTY` **[String][17]** string name for this slice of state. Generated actions wille use this as a prefix.
### set
Set a first level value without creating a specific action
#### Parameters
- `prop` **[String][22]** property name
- `value` **any** property value
Returns **[undefined][23]**
### getState

@@ -54,5 +38,5 @@

- `state` **Immutable.Map?** global state (if not specified, call getState method of redux store)
- `state` **[Object][18]?** global state (if not specified, call getState method of redux store)
Returns **Immutable.Map** store slice
Returns **[Object][18]** store slice

@@ -65,40 +49,16 @@ ### get

- `key` **[String][22]** key name
- `state` **Immutable.Map?** global state (if not specified, call getState method of redux store)
- `key` **[String][17]** key name
- `_state` **[Object][18]?** global state (if not specified, call getState method of redux store)
Returns **any** key value (converted in plain js if immutable)
Returns **any** key value
### getIn
- **See: [https://immutable-js.github.io/immutable-js/][24]
**
Get js value of a nested key
#### Parameters
- `path` **[Array][25]** Iterable key path (more details in Immutable.js documentation)
- `state` **Immutable.Map?** global state (if not specified, call getState method of redux store)
#### Examples
```javascript
const store = new Heridux("myPartialStore")
store.setInitialState({
list : [{ name : "foo"}, { name : "bar" }]
})
store.getIn(["list", 0, "name"]) // foo
```
Returns **any** key value (converted in plain js if immutable)
### setInitialState
Define the initial state of the store slice. It will automatically be converted to immutable.
Define the initial state of the store slice
#### Parameters
- `state` **[Object][26]** plain js state
- `state` **[Object][18]** plain js state
Returns **[undefined][23]**
Returns **[undefined][19]**

@@ -111,4 +71,4 @@ ### createAction

- `name` **[String][22]** action short name
- `reducer` **[Function][27]** function to modify the state
- `name` **[String][17]** action short name
- `reducer` **[Function][20]** function to modify the state

@@ -131,3 +91,3 @@ #### Examples

Returns **[undefined][23]**
Returns **[undefined][19]**

@@ -143,6 +103,6 @@ ### execAction

- `name` **[String][22]** action short name
- `options` **[Object][26]** additional parameters
- `name` **[String][17]** action short name
- `options` **[Object][18]** additional parameters
Returns **[undefined][23]**
Returns **[undefined][19]**

@@ -153,3 +113,3 @@ ### register

Returns **[undefined][23]**
Returns **[undefined][19]**

@@ -162,5 +122,5 @@ ### dispatch

- `action` **([Object][26] \| [Function][27])** redux action
- `action` **([Object][18] \| [Function][20])** redux action
Returns **([undefined][23] \| [Promise][28])** promise if async
Returns **[undefined][19]**

@@ -171,15 +131,15 @@ [1]: #heridux

[3]: #set
[3]: #getstate
[4]: #parameters-1
[5]: #getstate
[5]: #get
[6]: #parameters-2
[7]: #get
[7]: #setinitialstate
[8]: #parameters-3
[9]: #getin
[9]: #createaction

@@ -190,34 +150,18 @@ [10]: #parameters-4

[12]: #setinitialstate
[12]: #execaction
[13]: #parameters-5
[14]: #createaction
[14]: #register
[15]: #parameters-6
[15]: #dispatch
[16]: #examples-1
[16]: #parameters-6
[17]: #execaction
[17]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
[18]: #parameters-7
[18]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
[19]: #register
[19]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined
[20]: #dispatch
[21]: #parameters-8
[22]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
[23]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined
[24]: https://immutable-js.github.io/immutable-js/
[25]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
[26]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
[27]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
[28]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise
[20]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
import { createStore, combineReducers } from "redux"
import { fromJS } from "immutable"
/**

@@ -43,29 +41,5 @@ * Creation of Heridux store

this._reducers = {}
this._createGenericActions()
}
/**
* Create generic action to set simple values in the store without creating named actions
* @private
* @returns {undefined}
*/
_createGenericActions() {
// in some classes inheriting from Heridux, createAction is overloaded
// we therefore make sure to take the original
const { createAction } = Heridux.prototype
createAction.call(this, "set", (state, { prop, value }) => state.set(prop, fromJS(value)))
}
/**
* Set a first level value without creating a specific action
* @param {String} prop property name
* @param {any} value property value
* @returns {undefined}
*/
set(prop, value) {
return this.execAction("set", { prop, value })
}
/**
* Get full action name with prefix + SCREAMING_SNAKE_CASE action name

@@ -118,4 +92,4 @@ * @private

* Get store slice
* @param {Immutable.Map} [state] global state (if not specified, call getState method of redux store)
* @return {Immutable.Map} store slice
* @param {Object} [state] global state (if not specified, call getState method of redux store)
* @return {Object} store slice
*/

@@ -138,33 +112,11 @@ getState(state) {

* @param {String} key key name
* @param {Immutable.Map} [state] global state (if not specified, call getState method of redux store)
* @return {*} key value (converted in plain js if immutable)
* @param {Object} [_state] global state (if not specified, call getState method of redux store)
* @return {*} key value
*/
get(key, state) {
get(key, _state) {
const value = this.getState(state).get(key)
return value?.toJS?.() ?? value
return this.getState(_state)[key]
}
/**
* Get js value of a nested key
* @example
* const store = new Heridux("myPartialStore")
* store.setInitialState({
* list : [{ name : "foo"}, { name : "bar" }]
* })
* store.getIn(["list", 0, "name"]) // foo
* @param {Array} path Iterable key path (more details in Immutable.js documentation)
* @param {Immutable.Map} [state] global state (if not specified, call getState method of redux store)
* @return {*} key value (converted in plain js if immutable)
* @see {@link https://immutable-js.github.io/immutable-js/}
*/
getIn(path, state) {
const value = this.getState(state).getIn(path)
return value && value.toJS ? value.toJS() : value
}
/**
* Get action from short name action

@@ -181,3 +133,3 @@ * @private

/**
* Define the initial state of the store slice. It will automatically be converted to immutable.
* Define the initial state of the store slice
* @param {Object} state plain js state

@@ -188,3 +140,3 @@ * @return {undefined}

this.initialState = fromJS(state)
this.initialState = state
}

@@ -318,3 +270,3 @@

* @param {Object|Function} action redux action
* @return {undefined|Promise} promise if async
* @return {undefined}
*/

@@ -321,0 +273,0 @@ dispatch = action => this._getReduxStore().dispatch(action)

@@ -13,5 +13,15 @@ /* eslint no-unused-expressions:0 max-statements:0*/

myRedux.createAction("editItem", (state, { index, name }) => state.setIn(["items", index], name))
myRedux.createAction("changeType", (state, { type }) => state.set("type", type))
myRedux.createAction("editItem", (state, { index, name }) => {
const newItems = [...state.items]
newItems[index] = name
return {
...state,
items : newItems
}
})
myRedux.createAction("changeType", (state, { type }) => ({ ...state, type }))
myRedux.register()

@@ -18,0 +28,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc