@simpreact/simpreact 0.0.3 → 0.0.4
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/compat/context.d.ts +8 -0
- package/compat/context.js +7 -0
- package/compat/core.d.ts +4 -7
- package/compat/core.js +2 -5
- package/compat/hooks.d.ts +0 -2
- package/compat/hooks.js +0 -2
- package/compat/index.d.ts +5 -4
- package/compat/index.js +3 -0
- package/context/index.d.ts +24 -0
- package/context/index.js +64 -0
- package/core/createElement.d.ts +6 -9
- package/core/createElement.js +1 -24
- package/core/index.d.ts +2 -21
- package/core/index.js +3 -3
- package/core/internal.d.ts +1 -1
- package/core/internal.js +1 -1
- package/core/memo.d.ts +10 -0
- package/core/memo.js +11 -0
- package/core/mounting.d.ts +6 -9
- package/core/mounting.js +21 -53
- package/core/patching.d.ts +4 -5
- package/core/patching.js +55 -82
- package/core/rerender.d.ts +5 -4
- package/core/rerender.js +76 -24
- package/core/unmounting.js +3 -3
- package/dom/attach-element-to-dom.js +10 -1
- package/dom/events.d.ts +6 -1
- package/dom/events.js +12 -2
- package/hooks/index.d.ts +1 -3
- package/hooks/index.js +6 -7
- package/package.json +1 -1
- package/shared/index.d.ts +6 -0
- package/shared/index.js +12 -3
- package/shared/utils.d.ts +1 -0
- package/shared/utils.js +20 -0
- package/compat/utils.d.ts +0 -1
- package/compat/utils.js +0 -3
- package/core/context.d.ts +0 -18
- package/core/context.js +0 -18
package/shared/index.d.ts
CHANGED
|
@@ -17,3 +17,9 @@ declare class EventBus<Event = void> {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
declare function isSimpText(value: unknown): value is SimpText;
|
|
20
|
+
|
|
21
|
+
declare function noop(): void;
|
|
22
|
+
|
|
23
|
+
declare function callOrGet<T, A extends any[]>(value: T | ((...args: A) => T), ...args: A): T;
|
|
24
|
+
|
|
25
|
+
declare function shallowEqual(objA: any, objB: any): boolean;
|
package/shared/index.js
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { EventBus } from './EventBus.js';
|
|
2
2
|
import { emptyArray, emptyMap, emptyObject } from './lang.js';
|
|
3
|
-
import { isSimpText, noop } from './utils.js';
|
|
4
|
-
export { emptyObject, emptyMap, emptyArray, isSimpText, EventBus, noop };
|
|
5
|
-
export default {
|
|
3
|
+
import { callOrGet, isSimpText, noop, shallowEqual } from './utils.js';
|
|
4
|
+
export { emptyObject, emptyMap, emptyArray, isSimpText, EventBus, noop, callOrGet, shallowEqual };
|
|
5
|
+
export default {
|
|
6
|
+
isSimpText,
|
|
7
|
+
EMPTY_MAP: emptyMap,
|
|
8
|
+
EMPTY_ARRAY: emptyArray,
|
|
9
|
+
EMPTY_OBJECT: emptyObject,
|
|
10
|
+
EventBus,
|
|
11
|
+
noop,
|
|
12
|
+
callOrGet,
|
|
13
|
+
emptyObject,
|
|
14
|
+
};
|
package/shared/utils.d.ts
CHANGED
|
@@ -2,3 +2,4 @@ import type { SimpText } from './public.js';
|
|
|
2
2
|
export declare function isSimpText(value: unknown): value is SimpText;
|
|
3
3
|
export declare function noop(): void;
|
|
4
4
|
export declare function callOrGet<T, A extends any[]>(value: T | ((...args: A) => T), ...args: A): T;
|
|
5
|
+
export declare function shallowEqual(objA: any, objB: any): boolean;
|
package/shared/utils.js
CHANGED
|
@@ -18,3 +18,23 @@ export function callOrGet(value) {
|
|
|
18
18
|
}
|
|
19
19
|
return value(...args);
|
|
20
20
|
}
|
|
21
|
+
export function shallowEqual(objA, objB) {
|
|
22
|
+
if (Object.is(objA, objB)) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
const keysA = Object.keys(objA);
|
|
29
|
+
const keysB = Object.keys(objB);
|
|
30
|
+
if (keysA.length !== keysB.length) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
for (let i = 0; i < keysA.length; i++) {
|
|
34
|
+
const currentKey = keysA[i];
|
|
35
|
+
if (!Object.prototype.hasOwnProperty.call(objB, currentKey) || !Object.is(objA[currentKey], objB[currentKey])) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return true;
|
|
40
|
+
}
|
package/compat/utils.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function identity(value: any): any;
|
package/compat/utils.js
DELETED
package/core/context.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { SimpNode } from './createElement.js';
|
|
2
|
-
type Provider<T = any> = (props: {
|
|
3
|
-
value: T;
|
|
4
|
-
children: SimpNode;
|
|
5
|
-
}) => SimpNode;
|
|
6
|
-
type Consumer<T = any> = (props: {
|
|
7
|
-
children: (value: T) => SimpNode;
|
|
8
|
-
}, contextMap: SimpContextMap) => SimpNode;
|
|
9
|
-
export interface SimpContext<T> {
|
|
10
|
-
defaultValue: T;
|
|
11
|
-
Provider: Provider<T>;
|
|
12
|
-
Consumer: Consumer<T>;
|
|
13
|
-
}
|
|
14
|
-
export type SimpContextMap = Map<SimpContext<any>, any>;
|
|
15
|
-
export declare function createContext<T>(defaultValue: T): SimpContext<T>;
|
|
16
|
-
export declare function isProvider(type: any): boolean;
|
|
17
|
-
export declare function isConsumer(type: any): boolean;
|
|
18
|
-
export {};
|
package/core/context.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export function createContext(defaultValue) {
|
|
2
|
-
const context = {
|
|
3
|
-
defaultValue,
|
|
4
|
-
Provider: Object.create(null),
|
|
5
|
-
Consumer(props, contextMap) {
|
|
6
|
-
return props.children(contextMap.get(context) ?? defaultValue);
|
|
7
|
-
},
|
|
8
|
-
};
|
|
9
|
-
Object.defineProperty(context.Consumer, 'isConsumer', { value: true });
|
|
10
|
-
Object.defineProperty(context.Provider, 'context', { value: context, enumerable: true });
|
|
11
|
-
return context;
|
|
12
|
-
}
|
|
13
|
-
export function isProvider(type) {
|
|
14
|
-
return type != null && type.context != null;
|
|
15
|
-
}
|
|
16
|
-
export function isConsumer(type) {
|
|
17
|
-
return type != null && type.isConsumer === true;
|
|
18
|
-
}
|