react-hook-core 0.4.16 → 0.4.17

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/lib/update.js CHANGED
@@ -53,7 +53,7 @@ function useMergeState(initialState) {
53
53
  var _a = react_1.useState(initialState ? initialState : {}),
54
54
  state = _a[0],
55
55
  _setState = _a[1]
56
- var callbackRef = react_1.useRef()
56
+ var callbackRef = react_1.useRef(null)
57
57
  var setState = react_1.useCallback(
58
58
  function (newState, callback) {
59
59
  callbackRef.current = callback
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-hook-core",
3
- "version": "0.4.16",
3
+ "version": "0.4.17",
4
4
  "description": "react",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./src/index.ts",
package/src/reflect.ts CHANGED
@@ -36,14 +36,6 @@ export function clone(obj: any): any {
36
36
  return x
37
37
  }
38
38
 
39
- export function isEmptyObject(obj: any): boolean {
40
- for (let key in obj) {
41
- if (obj.hasOwnProperty(key)) {
42
- return false
43
- }
44
- }
45
- return true
46
- }
47
39
  export function diff(obj1: any, obj2: any): string[] {
48
40
  const fields = []
49
41
  const key1s = Object.keys(obj1)
@@ -74,6 +66,15 @@ export function diff(obj1: any, obj2: any): string[] {
74
66
  }
75
67
  return fields
76
68
  }
69
+ export function notIn(s1: string[], s2: string[]): string[] {
70
+ const r = []
71
+ for (const s of s2) {
72
+ if (s1.indexOf(s) < 0) {
73
+ r.push(s)
74
+ }
75
+ }
76
+ return r
77
+ }
77
78
 
78
79
  export function makeDiff<T>(o1: T, o2: T, keys?: string[], version?: string): Partial<T> {
79
80
  const obj1: any = o1
@@ -102,15 +103,13 @@ export function hasDiff<T>(o1: T, o2: T, keys?: string[], version?: string): boo
102
103
  const diff = makeDiff(o1, o2, keys, version)
103
104
  return !isEmptyObject(diff)
104
105
  }
105
-
106
- export function notIn(s1: string[], s2: string[]): string[] {
107
- const r = []
108
- for (const s of s2) {
109
- if (s1.indexOf(s) < 0) {
110
- r.push(s)
106
+ export function isEmptyObject(obj: any): boolean {
107
+ for (let key in obj) {
108
+ if (obj.hasOwnProperty(key)) {
109
+ return false
111
110
  }
112
111
  }
113
- return r
112
+ return true
114
113
  }
115
114
 
116
115
  export function equal(obj1: any, obj2: any): boolean {
@@ -158,7 +157,6 @@ export function equal(obj1: any, obj2: any): boolean {
158
157
  }
159
158
  return equalArrays(obj1, obj2)
160
159
  }
161
-
162
160
  export function equalArrays<T>(ar1: T[], ar2: T[]): boolean {
163
161
  if (ar1 == null && ar2 == null) {
164
162
  return true
@@ -193,30 +191,13 @@ export function getDiffArray<T>(list: T[] | undefined | null, name: string, v: b
193
191
  const arrs = []
194
192
  if (list) {
195
193
  for (const obj of list) {
196
- if ((obj as any)[name] !== true) {
194
+ if ((obj as any)[name] !== v) {
197
195
  arrs.push(obj)
198
196
  }
199
197
  }
200
198
  }
201
199
  return arrs
202
200
  }
203
- export function setAll<T>(list: T[] | undefined | null, name: string, v: boolean | string | number): void {
204
- if (list) {
205
- for (const obj of list) {
206
- ;(obj as any)[name] = v
207
- }
208
- }
209
- }
210
- export function equalAll<T>(list: T[] | undefined | null, name: string, v: boolean | string | number): boolean {
211
- if (list) {
212
- for (const obj of list) {
213
- if ((obj as any)[name] !== v) {
214
- return false
215
- }
216
- }
217
- }
218
- return true
219
- }
220
201
 
221
202
  export function getDirectValue(obj: any, key: string): any {
222
203
  if (obj && obj.hasOwnProperty(key)) {
package/src/update.ts CHANGED
@@ -40,11 +40,11 @@ export type DispatchWithCallback<T> = (value: T, callback?: Callback<T>) => void
40
40
  export function useMergeState<T>(initialState?: T | (() => T)): [T, DispatchWithCallback<Partial<T>>] {
41
41
  const [state, _setState] = useState(initialState ? initialState : ({} as any))
42
42
 
43
- const callbackRef = useRef<Callback<T>>()
43
+ const callbackRef = useRef<Callback<T>>(null)
44
44
 
45
45
  const setState = useCallback(
46
46
  (newState: Partial<T>, callback?: Callback<T>): void => {
47
- callbackRef.current = callback
47
+ ;(callbackRef as any).current = callback
48
48
  _setState((prevState: any) => Object.assign({}, prevState, newState))
49
49
  },
50
50
  [state],