New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

state-local

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

state-local - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

5

CHANGELOG.md
### Versions
## 1.0.2
###### *Nov 14, 2020*
- fix `module` path in package.json
## 1.0.1

@@ -4,0 +9,0 @@ ###### *Aug 6, 2020*

4

package.json
{
"name": "state-local",
"version": "1.0.1",
"version": "1.0.2",
"description": "Tiny, simple, and robust technique for defining and acting with local states",
"main": "dist/state-local.js",
"module": "src/index.js",
"module": "dist/state-local.js",
"types": "dist/types.d.ts",

@@ -8,0 +8,0 @@ "author": "Suren Atoyan <contact@surenatoyan.com>",

@@ -1,2 +0,2 @@

# State &middot; [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/suren-atoyan/state-local/blob/master/LICENSE) [![npm version](https://img.shields.io/npm/v/state-local.svg?style=flat)](https://www.npmjs.com/package/state-local) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)]([https://github.com/suren-atoyan/monaco-react/pulls](https://github.com/suren-atoyan/state-local/pulls))
# State &middot; [![monthly downloads](https://img.shields.io/npm/dm/state-local)](https://www.npmjs.com/package/state-local) [![gitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/suren-atoyan/state-local/blob/master/LICENSE) [![build size](https://img.shields.io/bundlephobia/minzip/state-local)](https://bundlephobia.com/result?p=state-local) [![npm version](https://img.shields.io/npm/v/state-local.svg?style=flat)](https://www.npmjs.com/package/state-local) [![PRs welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/suren-atoyan/state-local/pulls)

@@ -61,5 +61,5 @@ :zap: Tiny, simple, and robust technique for defining and acting with local states (for all js environments - node, browser, etc.)

// ...
setState({ y: 6 });
const state = getState();
setState({ y: 6 });
console.log(state.x);
console.log(state);
}

@@ -74,2 +74,4 @@

[codesandbox](https://codesandbox.io/s/motivation-1-xv5el?file=/src/index.js)
We also can track the changes in items:

@@ -88,2 +90,4 @@

[codesandbox](https://codesandbox.io/s/motivation-2-ivf7d)
We can use the subset of the state in some execution contexts:

@@ -101,6 +105,8 @@

console.log(state.x); // 5
console.log(state.y); // ❌ undifined - there is no y
console.log(state.y); // ❌ undefined - there is no y
}
```
[codesandbox](https://codesandbox.io/s/motivation-3-femne)
And much more...

@@ -155,2 +161,4 @@

[codesandbox](https://codesandbox.io/s/docs-create-t1cxe)
`create` is a function with two parameters:

@@ -178,2 +186,4 @@

[codesandbox](https://codesandbox.io/s/docs-initial-state-22i3s)
#### handler

@@ -202,2 +212,4 @@

[codesandbox](https://codesandbox.io/s/handler-function-uevxj)
if `handler` is an object

@@ -225,2 +237,4 @@ ```javascript

[codesandbox](https://codesandbox.io/s/handler-object-8k0pt)
#### getState

@@ -231,9 +245,9 @@

```javascript
import { create as createState } from 'state-local';
import { create as createState } from "state-local";
const [getState, setState] = state.create({ p1: 509, p2: 521 });
const [getState, setState] = createState({ p1: 509, p2: 521 });
const state = getState();
console.log(state.p1); // 501
consoel.log(state.p2); // 521
console.log(state.p1); // 509
console.log(state.p2); // 521

@@ -243,6 +257,8 @@ // or

const { p1, p2 } = getState();
console.log(p1); // 501
console.log(p1); // 509
console.log(p2); // 521
```
[codesandbox](https://codesandbox.io/s/getstate-zn3hj)
#### selector

@@ -255,3 +271,3 @@

const [getState, setState] = state.create({ p1: 389, p2: 397, p3: 401 });
const [getState, setState] = createState({ p1: 389, p2: 397, p3: 401 });

@@ -261,7 +277,9 @@ function someFn() {

console.log(state.p1); // 389
consoel.log(state.p2); // 397
console.log(state.p3); // ❌ undifined - there is no p3
console.log(state.p2); // 397
console.log(state.p3); // ❌ undefined - there is no p3
}
```
[codesandbox](https://codesandbox.io/s/selector-vjmdu)
#### setState

@@ -276,3 +294,3 @@

const [getState, setState] = state.create({ x:0, y: 0 });
const [getState, setState] = createState({ x:0, y: 0 });

@@ -286,2 +304,4 @@ setState({ z: 'some value' }); // ❌ error - it seams you want to change a field in the state which is not specified in the "initial" state

[codesandbox](https://codesandbox.io/s/setstate-1-u4fq0)
`setState` also can receive a function which will be called with the current state and it is supposed to return the change object

@@ -292,6 +312,6 @@

const [getState, setState] = state.create({ x:0, y: 0 });
const [getState, setState] = createState({ x:0, y: 0 });
setState(state => ({ x: state.x + 2 })); // ✅ ok
setState(state => ({ x: staet.x - 11, y: state.y + 11 })); // ✅ ok
setState(state => ({ x: state.x - 11, y: state.y + 11 })); // ✅ ok

@@ -301,4 +321,6 @@ setState(state => ({ z: 'some value' })); // ❌ error - it seams you want to change a field in the state which is not specified in the "initial" state

[codesandbox](https://codesandbox.io/s/smoosh-wildflower-nv9dg)
## License
[MIT](./LICENSE)
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