@nbottarini/react-observable 0.1.5 → 0.2.0

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.
@@ -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 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"}
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>(observable: Observable<T>, initialValue: T): 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,SAAiBA,WAA2BC,cACxD,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"}
@@ -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 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"}
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>(observable: Observable<T>, initialValue: T): 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,cAAiBC,WAA2BC,cACxD,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.5",
3
+ "version": "0.2.0",
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",
@@ -28,7 +28,7 @@
28
28
  "test": "jest"
29
29
  },
30
30
  "dependencies": {
31
- "@nbottarini/observable": "^0.3.0"
31
+ "@nbottarini/observable": "^0.4.1"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "react": "*"