@tanstack/router-core 0.0.1-beta.36 → 0.0.1-beta.39

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.
@@ -0,0 +1,118 @@
1
+ /**
2
+ * This function returns `a` if `b` is deeply equal.
3
+ * If not, it will replace any deeply equal children of `b` with those of `a`.
4
+ * This can be used for structural sharing between JSON values for example.
5
+ */
6
+ export function sharedClone<T>(prev: any, next: T, touchAll?: boolean): T {
7
+ const things = new Map()
8
+
9
+ function recurse(prev: any, next: any) {
10
+ if (prev === next) {
11
+ return prev
12
+ }
13
+
14
+ if (things.has(next)) {
15
+ return things.get(next)
16
+ }
17
+
18
+ const prevIsArray = Array.isArray(prev)
19
+ const nextIsArray = Array.isArray(next)
20
+ const prevIsObj = isPlainObject(prev)
21
+ const nextIsObj = isPlainObject(next)
22
+
23
+ const isArray = prevIsArray && nextIsArray
24
+ const isObj = prevIsObj && nextIsObj
25
+
26
+ const isSameStructure = isArray || isObj
27
+
28
+ // Both are arrays or objects
29
+ if (isSameStructure) {
30
+ const aSize = isArray ? prev.length : Object.keys(prev).length
31
+ const bItems = isArray ? next : Object.keys(next)
32
+ const bSize = bItems.length
33
+ const copy: any = isArray ? [] : {}
34
+
35
+ let equalItems = 0
36
+
37
+ for (let i = 0; i < bSize; i++) {
38
+ const key = isArray ? i : bItems[i]
39
+ if (copy[key] === prev[key]) {
40
+ equalItems++
41
+ }
42
+ }
43
+ if (aSize === bSize && equalItems === aSize) {
44
+ things.set(next, prev)
45
+ return prev
46
+ }
47
+ things.set(next, copy)
48
+ for (let i = 0; i < bSize; i++) {
49
+ const key = isArray ? i : bItems[i]
50
+ if (typeof bItems[i] === 'function') {
51
+ copy[key] = prev[key]
52
+ } else {
53
+ copy[key] = recurse(prev[key], next[key])
54
+ }
55
+ if (copy[key] === prev[key]) {
56
+ equalItems++
57
+ }
58
+ }
59
+
60
+ return copy
61
+ }
62
+
63
+ if (nextIsArray) {
64
+ const copy: any[] = []
65
+ things.set(next, copy)
66
+ for (let i = 0; i < next.length; i++) {
67
+ copy[i] = recurse(undefined, next[i])
68
+ }
69
+ return copy as T
70
+ }
71
+
72
+ if (nextIsObj) {
73
+ const copy = {} as any
74
+ things.set(next, copy)
75
+ const nextKeys = Object.keys(next)
76
+ for (let i = 0; i < nextKeys.length; i++) {
77
+ const key = nextKeys[i]!
78
+ copy[key] = recurse(undefined, next[key])
79
+ }
80
+ return copy as T
81
+ }
82
+
83
+ return next
84
+ }
85
+
86
+ return recurse(prev, next)
87
+ }
88
+
89
+ // Copied from: https://github.com/jonschlinkert/is-plain-object
90
+ function isPlainObject(o: any) {
91
+ if (!hasObjectPrototype(o)) {
92
+ return false
93
+ }
94
+
95
+ // If has modified constructor
96
+ const ctor = o.constructor
97
+ if (typeof ctor === 'undefined') {
98
+ return true
99
+ }
100
+
101
+ // If has modified prototype
102
+ const prot = ctor.prototype
103
+ if (!hasObjectPrototype(prot)) {
104
+ return false
105
+ }
106
+
107
+ // If constructor does not have an Object-specific method
108
+ if (!prot.hasOwnProperty('isPrototypeOf')) {
109
+ return false
110
+ }
111
+
112
+ // Most likely a plain Object
113
+ return true
114
+ }
115
+
116
+ function hasObjectPrototype(o: any) {
117
+ return Object.prototype.toString.call(o) === '[object Object]'
118
+ }
package/src/utils.ts CHANGED
@@ -60,71 +60,6 @@ export type PickExclude<T, U> = {
60
60
  [K in keyof T as T[K] extends U ? never : K]: T[K]
61
61
  }
62
62
 
63
- /**
64
- * This function returns `a` if `b` is deeply equal.
65
- * If not, it will replace any deeply equal children of `b` with those of `a`.
66
- * This can be used for structural sharing between JSON values for example.
67
- */
68
- export function replaceEqualDeep(prev: any, next: any) {
69
- if (prev === next) {
70
- return prev
71
- }
72
-
73
- const array = Array.isArray(prev) && Array.isArray(next)
74
-
75
- if (array || (isPlainObject(prev) && isPlainObject(next))) {
76
- const aSize = array ? prev.length : Object.keys(prev).length
77
- const bItems = array ? next : Object.keys(next)
78
- const bSize = bItems.length
79
- const copy: any = array ? [] : {}
80
-
81
- let equalItems = 0
82
-
83
- for (let i = 0; i < bSize; i++) {
84
- const key = array ? i : bItems[i]
85
- copy[key] = replaceEqualDeep(prev[key], next[key])
86
- if (copy[key] === prev[key]) {
87
- equalItems++
88
- }
89
- }
90
-
91
- return aSize === bSize && equalItems === aSize ? prev : copy
92
- }
93
-
94
- return next
95
- }
96
-
97
- // Copied from: https://github.com/jonschlinkert/is-plain-object
98
- function isPlainObject(o: any) {
99
- if (!hasObjectPrototype(o)) {
100
- return false
101
- }
102
-
103
- // If has modified constructor
104
- const ctor = o.constructor
105
- if (typeof ctor === 'undefined') {
106
- return true
107
- }
108
-
109
- // If has modified prototype
110
- const prot = ctor.prototype
111
- if (!hasObjectPrototype(prot)) {
112
- return false
113
- }
114
-
115
- // If constructor does not have an Object-specific method
116
- if (!prot.hasOwnProperty('isPrototypeOf')) {
117
- return false
118
- }
119
-
120
- // Most likely a plain Object
121
- return true
122
- }
123
-
124
- function hasObjectPrototype(o: any) {
125
- return Object.prototype.toString.call(o) === '[object Object]'
126
- }
127
-
128
63
  export function last<T>(arr: T[]) {
129
64
  return arr[arr.length - 1]
130
65
  }
@@ -1,31 +0,0 @@
1
- /**
2
- * router-core
3
- *
4
- * Copyright (c) TanStack
5
- *
6
- * This source code is licensed under the MIT license found in the
7
- * LICENSE.md file in the root directory of this source tree.
8
- *
9
- * @license MIT
10
- */
11
- 'use strict';
12
-
13
- Object.defineProperty(exports, '__esModule', { value: true });
14
-
15
- function _extends() {
16
- _extends = Object.assign ? Object.assign.bind() : function (target) {
17
- for (var i = 1; i < arguments.length; i++) {
18
- var source = arguments[i];
19
- for (var key in source) {
20
- if (Object.prototype.hasOwnProperty.call(source, key)) {
21
- target[key] = source[key];
22
- }
23
- }
24
- }
25
- return target;
26
- };
27
- return _extends.apply(this, arguments);
28
- }
29
-
30
- exports["extends"] = _extends;
31
- //# sourceMappingURL=_rollupPluginBabelHelpers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"_rollupPluginBabelHelpers.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}