@simpreact/simpreact 0.0.2 → 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.
Files changed (48) hide show
  1. package/compat/context.d.ts +8 -0
  2. package/compat/context.js +7 -0
  3. package/compat/core.d.ts +43 -0
  4. package/compat/core.js +90 -0
  5. package/compat/dom.d.ts +11 -0
  6. package/compat/dom.js +10 -0
  7. package/compat/hooks.d.ts +24 -0
  8. package/compat/hooks.js +75 -0
  9. package/compat/index.d.ts +43 -0
  10. package/compat/index.js +17 -0
  11. package/compat/jsx-runtime.d.ts +10 -0
  12. package/compat/jsx-runtime.js +9 -0
  13. package/context/index.d.ts +24 -0
  14. package/context/index.js +64 -0
  15. package/core/createElement.d.ts +6 -9
  16. package/core/createElement.js +4 -25
  17. package/core/index.d.ts +4 -23
  18. package/core/index.js +3 -3
  19. package/core/internal.d.ts +1 -1
  20. package/core/internal.js +1 -1
  21. package/core/lifecycleEventBus.d.ts +4 -0
  22. package/core/memo.d.ts +10 -0
  23. package/core/memo.js +11 -0
  24. package/core/mounting.d.ts +6 -9
  25. package/core/mounting.js +44 -49
  26. package/core/patching.d.ts +4 -5
  27. package/core/patching.js +81 -68
  28. package/core/ref.d.ts +4 -4
  29. package/core/rerender.d.ts +7 -6
  30. package/core/rerender.js +91 -32
  31. package/core/unmounting.js +7 -3
  32. package/dom/attach-element-to-dom.js +11 -2
  33. package/dom/events.d.ts +9 -1
  34. package/dom/events.js +21 -5
  35. package/dom/props/controlled/input.js +5 -5
  36. package/dom/props/controlled/select.js +3 -3
  37. package/dom/props/controlled/textarea.js +5 -5
  38. package/dom/props/style.js +6 -3
  39. package/dom/render.js +3 -3
  40. package/hooks/index.d.ts +7 -3
  41. package/hooks/index.js +46 -14
  42. package/package.json +7 -1
  43. package/shared/index.d.ts +6 -0
  44. package/shared/index.js +12 -3
  45. package/shared/utils.d.ts +2 -0
  46. package/shared/utils.js +36 -0
  47. package/core/context.d.ts +0 -18
  48. package/core/context.js +0 -18
package/shared/utils.js CHANGED
@@ -2,3 +2,39 @@ export function isSimpText(value) {
2
2
  return typeof value === 'string' || typeof value === 'number' || typeof value === 'bigint';
3
3
  }
4
4
  export function noop() { }
5
+ export function callOrGet(value) {
6
+ if (typeof value !== 'function') {
7
+ return value;
8
+ }
9
+ if (arguments.length === 1) {
10
+ return value();
11
+ }
12
+ if (arguments.length === 2) {
13
+ return value(arguments[1]);
14
+ }
15
+ const args = [];
16
+ for (let i = 1; i < arguments.length; ++i) {
17
+ args.push(arguments[i]);
18
+ }
19
+ return value(...args);
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/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
- }