@rpcbase/client 0.121.0 → 0.123.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.
package/auth/getUid.js ADDED
@@ -0,0 +1,11 @@
1
+ /* @flow */
2
+ import {Platform} from "react-native"
3
+
4
+ import {getUid as _getUid} from "./index"
5
+
6
+ const getUid = Platform.OS === "web" ? _getUid : () => {
7
+ console.warn("native should not call getUid, use userId from AuthContext")
8
+ return null
9
+ }
10
+
11
+ export default getUid
package/auth/index.js CHANGED
@@ -110,7 +110,7 @@ export const session_restrict = (ctx, next) => {
110
110
  }
111
111
 
112
112
 
113
- export const get_uid = () => __user_id
113
+ export const getUid = () => __user_id
114
114
  export const set_uid = (val) => {
115
115
  __user_id = val
116
116
 
package/helpers/useRPC.js CHANGED
@@ -1,7 +1,10 @@
1
1
  /* @flow */
2
- import {useCallback, useMemo, useState, useEffect} from "react"
2
+ import {useCallback, useMemo, useState, useEffect, useRef} from "react"
3
+ import isEqual from "fast-deep-equal"
3
4
 
4
5
  const useRPC = (fn, payload) => {
6
+ const previousPayloadRef = useRef(null)
7
+
5
8
  const [loading, setLoading] = useState(true)
6
9
  const [error, setError] = useState()
7
10
  const [data, setData] = useState()
@@ -12,6 +15,12 @@ const useRPC = (fn, payload) => {
12
15
  }, [payload])
13
16
 
14
17
  useEffect(() => {
18
+ if (isEqual(previousPayloadRef.current, memoPayload)) {
19
+ return
20
+ }
21
+
22
+ previousPayloadRef.current = memoPayload
23
+
15
24
  const load = async() => {
16
25
  setLoading(true)
17
26
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/client",
3
- "version": "0.121.0",
3
+ "version": "0.123.0",
4
4
  "scripts": {
5
5
  "build-firebase": "webpack -c firebase/webpack.config.js",
6
6
  "build": "yarn build-firebase",
@@ -10,7 +10,7 @@ import LZString from "lz-string"
10
10
  import isEqual from "fast-deep-equal/react"
11
11
 
12
12
  import isEqualValues from "../../isEqualValues"
13
- import get_uid from "../../auth/get_uid"
13
+ import getUid from "../../auth/getUid"
14
14
 
15
15
  import useData from "./useData"
16
16
 
@@ -28,7 +28,7 @@ const getUseQuery = (register_query) => (
28
28
  // TODO: retrieve this from future AuthContext in client
29
29
  const uid = useMemo(() => {
30
30
  // TODO: why is there a options.userId here ??
31
- const _uid = Platform.OS === "web" ? get_uid() : options.userId
31
+ const _uid = Platform.OS === "web" ? getUid() : options.userId
32
32
  assert(_uid, "missing uid")
33
33
  return _uid
34
34
  }, [])
package/auth/get_uid.js DELETED
@@ -1,11 +0,0 @@
1
- /* @flow */
2
- import {Platform} from "react-native"
3
-
4
- import {get_uid as _get_uid} from "./index"
5
-
6
- const get_uid = Platform.OS === "web" ? _get_uid : () => {
7
- console.warn("native should not call get_uid, use userId from AuthContext")
8
- return null
9
- }
10
-
11
- export default get_uid