@nbottarini/react-observable 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -9,10 +9,10 @@ React hook for reacting to changes in @nbottarini/observable properties
|
|
|
9
9
|
|
|
10
10
|
Npm:
|
|
11
11
|
```
|
|
12
|
-
$ npm install --save @nbottarini/
|
|
12
|
+
$ npm install --save @nbottarini/react-observable
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
Yarn:
|
|
16
16
|
```
|
|
17
|
-
$ yarn add @nbottarini/
|
|
17
|
+
$ yarn add @nbottarini/react-observable
|
|
18
18
|
```
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var react=require("react");exports.useObservable=function(observable,initialValue){const[value,setValue]=react.useState(initialValue),forceUpdate=react.useReducer((()=>({})),{})[1];return react.useEffect((()=>{const observer={handler:newValue=>{
|
|
1
|
+
"use strict";var react=require("react");exports.useObservable=function(observable,initialValue){const[value,setValue]=react.useState(initialValue),forceUpdate=react.useReducer((()=>({})),{})[1];return react.useEffect((()=>{const observer={handler:newValue=>{value===newValue?forceUpdate():setValue(newValue)}};return observable.subscribe(observer,observer.handler),()=>{observable.unsubscribe(observer)}}),[observable]),value};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/useObservable.tsx"],"sourcesContent":["import { useEffect, useReducer, useState } from 'react'\nimport { Observable } from '@nbottarini/observable'\n\nexport function useObservable<T>(\n observable: Observable<T>,\n initialValue: T,\n): T {\n const [value, setValue] = useState(initialValue)\n const forceUpdate = useReducer(() => ({}), {})[1] as () => void\n\n useEffect(() => {\n const observer = {\n handler: (newValue: T) => {\n
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useObservable.tsx"],"sourcesContent":["import { useEffect, useReducer, useState } from 'react'\nimport { Observable } from '@nbottarini/observable'\n\nexport function useObservable<T>(\n observable: Observable<T>,\n initialValue: T,\n): T {\n const [value, setValue] = useState(initialValue)\n const forceUpdate = useReducer(() => ({}), {})[1] as () => void\n\n useEffect(() => {\n const observer = {\n handler: (newValue: T) => {\n if (value === newValue) {\n forceUpdate()\n } else { // If setValue is applied before forceUpdate strange things happens with hooks\n setValue(newValue)\n }\n }\n }\n observable.subscribe(observer, observer.handler)\n return () => {\n observable.unsubscribe(observer)\n }\n }, [observable])\n return value\n}\n"],"names":["observable","initialValue","value","setValue","useState","forceUpdate","useReducer","useEffect","observer","handler","newValue","subscribe","unsubscribe"],"mappings":"8DAGgB,SACZA,WACAC,cAEA,MAAOC,MAAOC,UAAYC,MAAQA,SAACH,cAC7BI,YAAcC,MAAAA,YAAW,KAAO,CAAE,IAAG,CAAE,GAAE,GAiB/C,OAfAC,MAAAA,WAAU,KACN,MAAMC,SAAW,CACbC,QAAUC,WACFR,QAAUQ,SACVL,cAEAF,SAASO,SACZ,GAIT,OADAV,WAAWW,UAAUH,SAAUA,SAASC,SACjC,KACHT,WAAWY,YAAYJ,SAAS,CACnC,GACF,CAACR,aACGE,KACX"}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useState,useReducer,useEffect}from"react";function useObservable(observable,initialValue){const[value,setValue]=useState(initialValue),forceUpdate=useReducer((()=>({})),{})[1];return useEffect((()=>{const observer={handler:newValue=>{
|
|
1
|
+
import{useState,useReducer,useEffect}from"react";function useObservable(observable,initialValue){const[value,setValue]=useState(initialValue),forceUpdate=useReducer((()=>({})),{})[1];return useEffect((()=>{const observer={handler:newValue=>{value===newValue?forceUpdate():setValue(newValue)}};return observable.subscribe(observer,observer.handler),()=>{observable.unsubscribe(observer)}}),[observable]),value}export{useObservable};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/useObservable.tsx"],"sourcesContent":["import { useEffect, useReducer, useState } from 'react'\nimport { Observable } from '@nbottarini/observable'\n\nexport function useObservable<T>(\n observable: Observable<T>,\n initialValue: T,\n): T {\n const [value, setValue] = useState(initialValue)\n const forceUpdate = useReducer(() => ({}), {})[1] as () => void\n\n useEffect(() => {\n const observer = {\n handler: (newValue: T) => {\n
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/useObservable.tsx"],"sourcesContent":["import { useEffect, useReducer, useState } from 'react'\nimport { Observable } from '@nbottarini/observable'\n\nexport function useObservable<T>(\n observable: Observable<T>,\n initialValue: T,\n): T {\n const [value, setValue] = useState(initialValue)\n const forceUpdate = useReducer(() => ({}), {})[1] as () => void\n\n useEffect(() => {\n const observer = {\n handler: (newValue: T) => {\n if (value === newValue) {\n forceUpdate()\n } else { // If setValue is applied before forceUpdate strange things happens with hooks\n setValue(newValue)\n }\n }\n }\n observable.subscribe(observer, observer.handler)\n return () => {\n observable.unsubscribe(observer)\n }\n }, [observable])\n return value\n}\n"],"names":["useObservable","observable","initialValue","value","setValue","useState","forceUpdate","useReducer","useEffect","observer","handler","newValue","subscribe","unsubscribe"],"mappings":"iDAGgB,SAAAA,cACZC,WACAC,cAEA,MAAOC,MAAOC,UAAYC,SAASH,cAC7BI,YAAcC,YAAW,KAAO,CAAE,IAAG,CAAE,GAAE,GAiB/C,OAfAC,WAAU,KACN,MAAMC,SAAW,CACbC,QAAUC,WACFR,QAAUQ,SACVL,cAEAF,SAASO,SACZ,GAIT,OADAV,WAAWW,UAAUH,SAAUA,SAASC,SACjC,KACHT,WAAWY,YAAYJ,SAAS,CACnC,GACF,CAACR,aACGE,KACX"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nbottarini/react-observable",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "React hook for reacting to changes in @nbottarini/observable properties",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -27,8 +27,10 @@
|
|
|
27
27
|
"lint": "eslint . && tsc --noEmit",
|
|
28
28
|
"test": "jest"
|
|
29
29
|
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@nbottarini/observable": "^0.3.0"
|
|
32
|
+
},
|
|
30
33
|
"peerDependencies": {
|
|
31
|
-
"@nbottarini/observable": "*",
|
|
32
34
|
"react": "*"
|
|
33
35
|
},
|
|
34
36
|
"devDependencies": {
|
|
@@ -36,7 +38,6 @@
|
|
|
36
38
|
"@babel/preset-env": "^7.22.10",
|
|
37
39
|
"@babel/preset-react": "^7.22.5",
|
|
38
40
|
"@babel/preset-typescript": "^7.22.5",
|
|
39
|
-
"@nbottarini/observable": "^0.2.2",
|
|
40
41
|
"@rollup/plugin-commonjs": "^25.0.3",
|
|
41
42
|
"@rollup/plugin-node-resolve": "^15.1.0",
|
|
42
43
|
"@rollup/plugin-terser": "^0.4.3",
|