hyperscript-rxjs 1.3.15 → 1.3.16

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 (278) hide show
  1. package/dist/hyperscript-rxjs.cjs +4114 -0
  2. package/dist/hyperscript-rxjs.d.ts +1438 -0
  3. package/package.json +21 -12
  4. package/src/array/advance.d.ts +0 -9
  5. package/src/array/advance.js +0 -13
  6. package/src/array/advance.test.js +0 -12
  7. package/src/array/arrayInsert.d.ts +0 -8
  8. package/src/array/arrayInsert.js +0 -13
  9. package/src/array/arrayInsert.test.js +0 -13
  10. package/src/array/arrayRemove.d.ts +0 -7
  11. package/src/array/arrayRemove.js +0 -15
  12. package/src/array/arrayRemove.test.js +0 -13
  13. package/src/array/findLastIndex.d.ts +0 -14
  14. package/src/array/findLastIndex.js +0 -20
  15. package/src/array/findLastIndex.test.js +0 -41
  16. package/src/array/index.d.ts +0 -9
  17. package/src/array/index.js +0 -9
  18. package/src/array/isRange.d.ts +0 -7
  19. package/src/array/isRange.js +0 -15
  20. package/src/array/isRange.test.js +0 -6
  21. package/src/array/rangeArray.d.ts +0 -7
  22. package/src/array/rangeArray.js +0 -10
  23. package/src/array/rangeArray.test.js +0 -11
  24. package/src/array/unwrapArgs.d.ts +0 -10
  25. package/src/array/unwrapArgs.js +0 -15
  26. package/src/array/unwrapArgs.test.js +0 -33
  27. package/src/array/zipArray.d.ts +0 -11
  28. package/src/array/zipArray.js +0 -24
  29. package/src/array/zipArray.test.js +0 -16
  30. package/src/comparers/Comparer.d.ts +0 -101
  31. package/src/comparers/Comparer.js +0 -149
  32. package/src/comparers/comparers.d.ts +0 -21
  33. package/src/comparers/comparers.js +0 -10
  34. package/src/comparers/differenceSet.d.ts +0 -20
  35. package/src/comparers/differenceSet.js +0 -35
  36. package/src/comparers/differenceSet.test.js +0 -11
  37. package/src/comparers/distinctArray.d.ts +0 -13
  38. package/src/comparers/distinctArray.js +0 -30
  39. package/src/comparers/distinctArray.test.js +0 -10
  40. package/src/comparers/findIndexInSet.d.ts +0 -20
  41. package/src/comparers/findIndexInSet.js +0 -27
  42. package/src/comparers/findIndexInSet.test.js +0 -8
  43. package/src/comparers/groupArrayBy.d.ts +0 -19
  44. package/src/comparers/groupArrayBy.js +0 -29
  45. package/src/comparers/groupArrayBy.test.js +0 -38
  46. package/src/comparers/groupSortedEntries.d.ts +0 -17
  47. package/src/comparers/groupSortedEntries.js +0 -38
  48. package/src/comparers/groupSortedEntries.test.js +0 -46
  49. package/src/comparers/index.d.ts +0 -14
  50. package/src/comparers/index.js +0 -14
  51. package/src/comparers/intersectSet.d.ts +0 -19
  52. package/src/comparers/intersectSet.js +0 -35
  53. package/src/comparers/intersectSet.test.js +0 -14
  54. package/src/comparers/isEqualset.d.ts +0 -22
  55. package/src/comparers/isEqualset.js +0 -33
  56. package/src/comparers/isEqualset.test.js +0 -22
  57. package/src/comparers/isSubset.d.ts +0 -21
  58. package/src/comparers/isSubset.js +0 -33
  59. package/src/comparers/isSubset.test.js +0 -21
  60. package/src/comparers/isSuperset.d.ts +0 -21
  61. package/src/comparers/isSuperset.js +0 -13
  62. package/src/comparers/isSuperset.test.js +0 -21
  63. package/src/comparers/sortedArrayToSet.d.ts +0 -20
  64. package/src/comparers/sortedArrayToSet.js +0 -35
  65. package/src/comparers/sortedArrayToSet.test.js +0 -11
  66. package/src/comparers/unionSet.d.ts +0 -21
  67. package/src/comparers/unionSet.js +0 -34
  68. package/src/comparers/unionSet.test.js +0 -11
  69. package/src/comparison/compareDate.d.ts +0 -8
  70. package/src/comparison/compareDate.js +0 -11
  71. package/src/comparison/compareEntries.d.ts +0 -13
  72. package/src/comparison/compareEntries.js +0 -13
  73. package/src/comparison/compareKey.d.ts +0 -11
  74. package/src/comparison/compareKey.js +0 -25
  75. package/src/comparison/compareKey.test.js +0 -21
  76. package/src/comparison/compareKeyPath.d.ts +0 -15
  77. package/src/comparison/compareKeyPath.js +0 -33
  78. package/src/comparison/compareKeyPath.test.js +0 -28
  79. package/src/comparison/compareNumber.d.ts +0 -11
  80. package/src/comparison/compareNumber.js +0 -27
  81. package/src/comparison/compareNumber.test.js +0 -21
  82. package/src/comparison/defaultCompare.d.ts +0 -8
  83. package/src/comparison/defaultCompare.js +0 -12
  84. package/src/comparison/defaultCompare.test.js +0 -24
  85. package/src/comparison/index.d.ts +0 -7
  86. package/src/comparison/index.js +0 -7
  87. package/src/comparison/infinity.test.js +0 -122
  88. package/src/comparison/typeof.test.js +0 -64
  89. package/src/comparison/types.d.ts +0 -5
  90. package/src/comparison/types.js +0 -11
  91. package/src/deep/Deep.d.ts +0 -58
  92. package/src/deep/Deep.js +0 -267
  93. package/src/deep/Deep.test.js +0 -130
  94. package/src/deep/deepCombineLatest.test.js +0 -36
  95. package/src/deep/deepMerge.test.js +0 -34
  96. package/src/deep/differenceDeep.test.js +0 -31
  97. package/src/deep/freshValueDeep.test.js +0 -17
  98. package/src/deep/index.d.ts +0 -1
  99. package/src/deep/index.js +0 -2
  100. package/src/deep/intersectDeep.test.js +0 -25
  101. package/src/deep/intersectEntries.d.ts +0 -13
  102. package/src/deep/intersectEntries.js +0 -37
  103. package/src/deep/intersectEntries.test.js +0 -20
  104. package/src/deep/objectToDeep.test.js +0 -31
  105. package/src/deep/replaceValueDeep.test.js +0 -21
  106. package/src/deep/unionDeep.test.js +0 -30
  107. package/src/deep/zipValueDeep.test.js +0 -21
  108. package/src/deep-rxjs/ObservableArray.d.ts +0 -55
  109. package/src/deep-rxjs/ObservableArray.js +0 -94
  110. package/src/deep-rxjs/ObservableArray.test.js +0 -117
  111. package/src/deep-rxjs/index.d.ts +0 -2
  112. package/src/deep-rxjs/index.js +0 -2
  113. package/src/deep-rxjs/isRxType.d.ts +0 -9
  114. package/src/deep-rxjs/isRxType.js +0 -15
  115. package/src/deep-rxjs/isRxType.test.js +0 -43
  116. package/src/hyperscript-rxjs/HyperscriptExtensions.d.ts +0 -20
  117. package/src/hyperscript-rxjs/checkbox.d.ts +0 -13
  118. package/src/hyperscript-rxjs/checkbox.js +0 -47
  119. package/src/hyperscript-rxjs/checkbox.test.js +0 -68
  120. package/src/hyperscript-rxjs/choice.d.ts +0 -13
  121. package/src/hyperscript-rxjs/choice.js +0 -24
  122. package/src/hyperscript-rxjs/choice.test.js +0 -108
  123. package/src/hyperscript-rxjs/collapse.d.ts +0 -14
  124. package/src/hyperscript-rxjs/collapse.js +0 -32
  125. package/src/hyperscript-rxjs/collapse.test.js +0 -67
  126. package/src/hyperscript-rxjs/displays/blockLevelFamily.d.ts +0 -5
  127. package/src/hyperscript-rxjs/displays/blockLevelFamily.js +0 -51
  128. package/src/hyperscript-rxjs/displays/getDisplay.d.ts +0 -7
  129. package/src/hyperscript-rxjs/displays/getDisplay.js +0 -51
  130. package/src/hyperscript-rxjs/displays/getDisplay.test.js +0 -56
  131. package/src/hyperscript-rxjs/displays/index.d.ts +0 -3
  132. package/src/hyperscript-rxjs/displays/index.js +0 -3
  133. package/src/hyperscript-rxjs/displays/inlineFamily.d.ts +0 -5
  134. package/src/hyperscript-rxjs/displays/inlineFamily.js +0 -73
  135. package/src/hyperscript-rxjs/flip.d.ts +0 -15
  136. package/src/hyperscript-rxjs/flip.js +0 -29
  137. package/src/hyperscript-rxjs/flip.test.js +0 -85
  138. package/src/hyperscript-rxjs/fragment.d.ts +0 -10
  139. package/src/hyperscript-rxjs/fragment.js +0 -22
  140. package/src/hyperscript-rxjs/fragment.test.js +0 -70
  141. package/src/hyperscript-rxjs/hyperscript.d.ts +0 -15
  142. package/src/hyperscript-rxjs/hyperscript.js +0 -170
  143. package/src/hyperscript-rxjs/hyperscript.test.js +0 -75
  144. package/src/hyperscript-rxjs/index.d.ts +0 -19
  145. package/src/hyperscript-rxjs/index.js +0 -19
  146. package/src/hyperscript-rxjs/multiselect.d.ts +0 -18
  147. package/src/hyperscript-rxjs/multiselect.js +0 -41
  148. package/src/hyperscript-rxjs/multiselect.test.js +0 -121
  149. package/src/hyperscript-rxjs/numberbox.d.ts +0 -14
  150. package/src/hyperscript-rxjs/numberbox.js +0 -73
  151. package/src/hyperscript-rxjs/numberbox.test.js +0 -84
  152. package/src/hyperscript-rxjs/radio.d.ts +0 -15
  153. package/src/hyperscript-rxjs/radio.js +0 -53
  154. package/src/hyperscript-rxjs/radio.test.js +0 -59
  155. package/src/hyperscript-rxjs/select.d.ts +0 -28
  156. package/src/hyperscript-rxjs/select.js +0 -88
  157. package/src/hyperscript-rxjs/select.test.js +0 -101
  158. package/src/hyperscript-rxjs/tabControls/bindTabIndex.d.ts +0 -12
  159. package/src/hyperscript-rxjs/tabControls/bindTabIndex.js +0 -59
  160. package/src/hyperscript-rxjs/tabControls/index.d.ts +0 -8
  161. package/src/hyperscript-rxjs/tabControls/index.js +0 -10
  162. package/src/hyperscript-rxjs/tabControls/tabControl.d.ts +0 -19
  163. package/src/hyperscript-rxjs/tabControls/tabControl.js +0 -40
  164. package/src/hyperscript-rxjs/tabControls/tabControl.test.js +0 -98
  165. package/src/hyperscript-rxjs/tabControls/tabNavItem.d.ts +0 -9
  166. package/src/hyperscript-rxjs/tabControls/tabNavItem.js +0 -30
  167. package/src/hyperscript-rxjs/tabControls/tabPanel.d.ts +0 -9
  168. package/src/hyperscript-rxjs/tabControls/tabPanel.js +0 -21
  169. package/src/hyperscript-rxjs/tabControls/tabRoot.d.ts +0 -7
  170. package/src/hyperscript-rxjs/tabControls/tabRoot.js +0 -26
  171. package/src/hyperscript-rxjs/tags.d.ts +0 -193
  172. package/src/hyperscript-rxjs/tags.js +0 -751
  173. package/src/hyperscript-rxjs/tags.test.js +0 -75
  174. package/src/hyperscript-rxjs/textNode.d.ts +0 -11
  175. package/src/hyperscript-rxjs/textNode.js +0 -51
  176. package/src/hyperscript-rxjs/textNode.test.js +0 -56
  177. package/src/hyperscript-rxjs/textarea.d.ts +0 -17
  178. package/src/hyperscript-rxjs/textarea.js +0 -45
  179. package/src/hyperscript-rxjs/textarea.test.js +0 -52
  180. package/src/hyperscript-rxjs/textbox.d.ts +0 -15
  181. package/src/hyperscript-rxjs/textbox.js +0 -42
  182. package/src/hyperscript-rxjs/textbox.test.js +0 -52
  183. package/src/index.d.ts +0 -19
  184. package/src/index.js +0 -19
  185. package/src/nodes/attachSubscriptionToNode.d.ts +0 -13
  186. package/src/nodes/attachSubscriptionToNode.js +0 -25
  187. package/src/nodes/attachSubscriptionToNode.test.js +0 -73
  188. package/src/nodes/index.d.ts +0 -6
  189. package/src/nodes/index.js +0 -6
  190. package/src/nodes/normalizeChildNodes.d.ts +0 -9
  191. package/src/nodes/normalizeChildNodes.js +0 -15
  192. package/src/nodes/normalizeChildNodes.test.js +0 -55
  193. package/src/nodes/parseHyperscriptArgs.d.ts +0 -10
  194. package/src/nodes/parseHyperscriptArgs.js +0 -57
  195. package/src/nodes/parseHyperscriptArgs.test.js +0 -85
  196. package/src/nodes/pipeEvent.d.ts +0 -15
  197. package/src/nodes/pipeEvent.js +0 -49
  198. package/src/nodes/pipeEvent.test.js +0 -97
  199. package/src/nodes/subscribeEvent.d.ts +0 -15
  200. package/src/nodes/subscribeEvent.js +0 -56
  201. package/src/nodes/subscribeEvent.test.js +0 -88
  202. package/src/object/index.d.ts +0 -10
  203. package/src/object/index.js +0 -11
  204. package/src/object/intersectObject.d.ts +0 -12
  205. package/src/object/intersectObject.js +0 -23
  206. package/src/object/intersectObject.test.js +0 -69
  207. package/src/object/isEmptyObject.d.ts +0 -7
  208. package/src/object/isEmptyObject.js +0 -13
  209. package/src/object/isEmptyObject.test.js +0 -33
  210. package/src/object/isPlainObject.d.ts +0 -11
  211. package/src/object/isPlainObject.js +0 -18
  212. package/src/object/nestedCombineLatest.d.ts +0 -11
  213. package/src/object/nestedCombineLatest.js +0 -18
  214. package/src/object/nestedCombineLatest.test.js +0 -25
  215. package/src/object/nestedMerge.d.ts +0 -11
  216. package/src/object/nestedMerge.js +0 -11
  217. package/src/object/nestedMerge.test.js +0 -61
  218. package/src/object/pickBehaviorSubject.d.ts +0 -13
  219. package/src/object/pickBehaviorSubject.js +0 -81
  220. package/src/object/pickBehaviorSubject.test.js +0 -88
  221. package/src/object/pluckProperty.d.ts +0 -13
  222. package/src/object/pluckProperty.js +0 -24
  223. package/src/object/pluckProperty.test.js +0 -37
  224. package/src/object/restore.d.ts +0 -12
  225. package/src/object/restore.js +0 -69
  226. package/src/object/restore.test.js +0 -124
  227. package/src/object/splitObjectByObservable.d.ts +0 -12
  228. package/src/object/splitObjectByObservable.js +0 -41
  229. package/src/object/splitObjectByObservable.test.js +0 -78
  230. package/src/props/getNestedProperty.d.ts +0 -12
  231. package/src/props/getNestedProperty.js +0 -31
  232. package/src/props/getNestedProperty.test.js +0 -72
  233. package/src/props/index.d.ts +0 -7
  234. package/src/props/index.js +0 -7
  235. package/src/props/parsePropName.d.ts +0 -13
  236. package/src/props/parsePropName.js +0 -45
  237. package/src/props/parsePropName.test.js +0 -67
  238. package/src/props/setProp.d.ts +0 -16
  239. package/src/props/setProp.js +0 -42
  240. package/src/props/setProp.test.js +0 -59
  241. package/src/props/setProps.d.ts +0 -14
  242. package/src/props/setProps.js +0 -47
  243. package/src/props/setProps.test.js +0 -97
  244. package/src/props/subscribeProp.d.ts +0 -16
  245. package/src/props/subscribeProp.js +0 -47
  246. package/src/props/subscribeProp.test.js +0 -81
  247. package/src/ramda/compose.d.ts +0 -10
  248. package/src/ramda/compose.js +0 -36
  249. package/src/ramda/compose.test.js +0 -73
  250. package/src/ramda/cond.d.ts +0 -12
  251. package/src/ramda/cond.js +0 -29
  252. package/src/ramda/cond.test.js +0 -88
  253. package/src/ramda/fold.d.ts +0 -13
  254. package/src/ramda/fold.js +0 -20
  255. package/src/ramda/fold.test.js +0 -51
  256. package/src/ramda/index.d.ts +0 -6
  257. package/src/ramda/index.js +0 -6
  258. package/src/ramda/pipe.d.ts +0 -13
  259. package/src/ramda/pipe.js +0 -27
  260. package/src/ramda/pipe.test.js +0 -77
  261. package/src/ramda/unfold.d.ts +0 -11
  262. package/src/ramda/unfold.js +0 -20
  263. package/src/ramda/unfold.test.js +0 -29
  264. package/src/unquoted-json/ajax.test.js +0 -1074
  265. package/src/unquoted-json/index.d.ts +0 -13
  266. package/src/unquoted-json/index.js +0 -12
  267. package/src/unquoted-json/queryStringify.d.ts +0 -8
  268. package/src/unquoted-json/queryStringify.js +0 -70
  269. package/src/unquoted-json/queryStringify.test.js +0 -110
  270. package/src/unquoted-json/stringifyKey.d.ts +0 -7
  271. package/src/unquoted-json/stringifyKey.js +0 -16
  272. package/src/unquoted-json/stringifyKey.test.js +0 -51
  273. package/src/unquoted-json/stringifyStringValue.d.ts +0 -7
  274. package/src/unquoted-json/stringifyStringValue.js +0 -17
  275. package/src/unquoted-json/stringifyStringValue.test.js +0 -52
  276. package/src/unquoted-json/unquotedJsonStringify.d.ts +0 -7
  277. package/src/unquoted-json/unquotedJsonStringify.js +0 -39
  278. package/src/unquoted-json/unquotedJsonStringify.test.js +0 -52
@@ -1,55 +0,0 @@
1
- import { normalizeChildNodes } from './normalizeChildNodes';
2
-
3
- describe('normalizeChildNodes', () => {
4
- beforeEach(() => {
5
- jest.clearAllMocks();
6
- });
7
-
8
- test('should return an empty array when no child nodes are provided', () => {
9
- const result = normalizeChildNodes([]);
10
- expect(result).toEqual([]);
11
- });
12
-
13
- test('should handle a single node', () => {
14
- const div = document.createElement('div');
15
- const result = normalizeChildNodes([div]);
16
- expect(result).toEqual([div]);
17
- });
18
-
19
- test('should handle multiple nodes', () => {
20
- const div1 = document.createElement('div');
21
- const div2 = document.createElement('div');
22
-
23
- const result = normalizeChildNodes([div1, div2]);
24
- expect(result).toEqual([div1, div2]);
25
- });
26
-
27
- test('should handle an array of nodes', () => {
28
- const div1 = document.createElement('div');
29
- const div2 = document.createElement('div');
30
-
31
- const result = normalizeChildNodes([[div1, div2]]);
32
- expect(result).toEqual([div1, div2]);
33
- });
34
-
35
- test('should convert non-node values to text nodes', () => {
36
-
37
- const result = normalizeChildNodes(['Hello', 123, true]);
38
- expect(result.length).toBe(3);
39
- expect(result[0].nodeType).toBe(Node.TEXT_NODE);
40
- expect(result[0].textContent).toBe('Hello');
41
- expect(result[1].textContent).toBe('123');
42
- expect(result[2].textContent).toBe('true');
43
- });
44
-
45
- test('should handle mixed nodes and non-nodes', () => {
46
- const div = document.createElement('div');
47
-
48
- const result = normalizeChildNodes([div, 'Text', 42]);
49
- expect(result.length).toBe(3);
50
- expect(result[0]).toBe(div);
51
- expect(result[1].nodeType).toBe(Node.TEXT_NODE);
52
- expect(result[1].textContent).toBe('Text');
53
- expect(result[2].textContent).toBe('42');
54
- });
55
- });
@@ -1,10 +0,0 @@
1
- /**
2
- * 解析 hyperscript 风格的参数,返回 props 和 childNodes。
3
- *
4
- * @param args - hyperscript 风格的参数数组。
5
- * @returns 包含 props(对象)和 childNodes(数组)的对象。
6
- * @throws 如果参数不是数组会抛出错误。
7
- */
8
- export function parseHyperscriptArgs(
9
- args: any[]
10
- ): { props: Record<string, any>, childNodes: any[] };
@@ -1,57 +0,0 @@
1
- /**
2
- * 解析 hyperscript 风格的参数,返回 props 和 childNodes。
3
- *
4
- * @param {any[]} args - hyperscript 风格的参数数组。
5
- * @returns {{ props: Record<string, any>, childNodes: any[] }} 包含 props(对象)和 childNodes(数组)的对象。
6
- * @throws 如果参数不是数组会抛出错误。
7
- */
8
-
9
- export function parseHyperscriptArgs(args) {
10
- // 参数验证,确保 args 是一个数组
11
- if (!Array.isArray(args)) {
12
- throw new Error('参数 "args" 必须是一个数组。');
13
- }
14
-
15
- if (args.length === 0) {
16
- return { props: {}, childNodes: [] };
17
- } else {
18
- let [first, ...rest] = args;
19
-
20
- //
21
- if (isProps(first)) {
22
- return {
23
- props: first ? first : {},
24
- childNodes: rest
25
- };
26
- } else {
27
- // 如果第一个参数不是对象,则所有参数作为子节点
28
- return { props: {}, childNodes: args };
29
- }
30
- }
31
- }
32
-
33
- /**
34
- * 如果第一个参数是 undefined、null 或普通对象(非数组),则返回 true。
35
- * 否则返回 false。
36
- * @param {unknown} value - 要检查的值
37
- * @returns {boolean}
38
- *
39
- */
40
- function isProps(value) {
41
- //// 基本检查: 空作为props的占位符(不建议,作为兼容)
42
- if (value === undefined || value === null) {
43
- return true;
44
- }
45
-
46
- // 基本检查:非对象直接返回false
47
- if (typeof value !== 'object') {
48
- return false;
49
- }
50
-
51
- // 检查原型链
52
- const proto = Object.getPrototypeOf(value);
53
-
54
- // 1. 原型为null(如Object.create(null)创建的对象)
55
- // 2. 原型等于Object.prototype(普通对象)
56
- return proto === null || proto === Object.prototype;
57
- }
@@ -1,85 +0,0 @@
1
- import { parseHyperscriptArgs } from './parseHyperscriptArgs';
2
-
3
- describe('parseHyperscriptArgs', () => {
4
- test('should handle empty arguments', () => {
5
- expect(parseHyperscriptArgs([])).toEqual({
6
- props: {},
7
- childNodes: [],
8
- });
9
- });
10
-
11
- test('should handle single props object', () => {
12
- expect(parseHyperscriptArgs([{}])).toEqual({
13
- props: {},
14
- childNodes: [],
15
- });
16
-
17
- expect(parseHyperscriptArgs([{ id: 'test' }])).toEqual({
18
- props: { id: 'test' },
19
- childNodes: [],
20
- });
21
-
22
- expect(parseHyperscriptArgs([null])).toEqual({
23
- props: {},
24
- childNodes: [],
25
- });
26
-
27
- expect(parseHyperscriptArgs([undefined])).toEqual({
28
- props: {},
29
- childNodes: [],
30
- });
31
- });
32
-
33
- test('should handle single childNodes', () => {
34
- expect(parseHyperscriptArgs([1])).toEqual({
35
- props: {},
36
- childNodes: [1],
37
- });
38
-
39
- expect(parseHyperscriptArgs(['Hello'])).toEqual({
40
- props: {},
41
- childNodes: ['Hello'],
42
- });
43
-
44
- expect(parseHyperscriptArgs([1, 2, 3])).toEqual({
45
- props: {},
46
- childNodes: [1, 2, 3],
47
- });
48
- });
49
-
50
- test('should handle props and childNodes', () => {
51
- expect(parseHyperscriptArgs([{ id: 'test' }, 'Hello'])).toEqual({
52
- props: { id: 'test' },
53
- childNodes: ['Hello'],
54
- });
55
-
56
- expect(parseHyperscriptArgs([{ id: 'test' }, 'Hello', 'World'])).toEqual({
57
- props: { id: 'test' },
58
- childNodes: ['Hello', 'World'],
59
- });
60
-
61
- expect(parseHyperscriptArgs([{ className: 'container' }, 1, 2, 3])).toEqual({
62
- props: { className: 'container' },
63
- childNodes: [1, 2, 3],
64
- });
65
- });
66
-
67
- test('should handle only childNodes when first argument is not an object', () => {
68
- expect(parseHyperscriptArgs([1, 2, 3])).toEqual({
69
- props: {},
70
- childNodes: [1, 2, 3],
71
- });
72
-
73
- expect(parseHyperscriptArgs(['Hello', 'World'])).toEqual({
74
- props: {},
75
- childNodes: ['Hello', 'World'],
76
- });
77
- });
78
-
79
- test('should throw an error if args is not an array', () => {
80
- expect(() => parseHyperscriptArgs(null)).toThrow('参数 "args" 必须是一个数组。');
81
- expect(() => parseHyperscriptArgs(undefined)).toThrow('参数 "args" 必须是一个数组。');
82
- expect(() => parseHyperscriptArgs({})).toThrow('参数 "args" 必须是一个数组。');
83
- expect(() => parseHyperscriptArgs('string')).toThrow('参数 "args" 必须是一个数组。');
84
- });
85
- });
@@ -1,15 +0,0 @@
1
- import { Observable, Subscription } from 'rxjs';
2
-
3
- /**
4
- * 为指定的 DOM 元素订阅事件流,并通过 pipe 对事件流进行处理。
5
- *
6
- * @param elem - 要订阅事件的 DOM 元素。
7
- * @returns 一个函数,接受事件名称和处理函数(接收事件流 Observable,返回 Subscription),用于订阅和处理事件,返回元素本身。
8
- * @throws 如果参数无效会抛出错误。
9
- */
10
- export function pipeEvent(
11
- elem: HTMLElement
12
- ): (
13
- event: string,
14
- subscriber: (event$: Observable<Event>) => Subscription
15
- ) => HTMLElement;
@@ -1,49 +0,0 @@
1
- import { fromEvent } from 'rxjs';
2
- import { attachSubscriptionToNode } from './attachSubscriptionToNode';
3
- import { Observable, Subscription } from 'rxjs';
4
-
5
- /**
6
- * 为指定的 DOM 元素订阅事件流,并通过 pipe 对事件流进行处理。
7
- *
8
- * @param {HTMLElement} elem - 要订阅事件的 DOM 元素。
9
- * @returns {(e:string,s:(event$: Observable<Event>) => Subscription)=>HTMLElement} - 返回一个函数,该函数接受事件名称和处理函数,用于订阅和处理事件。
10
- * @throws {Error} 如果参数无效。
11
- */
12
- export function pipeEvent(elem) {
13
- // 参数检查,确保 elem 是一个有效的 DOM 元素
14
- if (!(elem instanceof HTMLElement)) {
15
- throw new Error('参数 "elem" 必须是一个有效的 DOM 元素。');
16
- }
17
-
18
- return (
19
- /**
20
- *
21
- * @param {string} event
22
- * @param {(event$: Observable<Event>) => Subscription} subscriber
23
- * @returns
24
- */
25
- function (event, subscriber) {
26
- // 参数检查,确保 event 是字符串,subscriber 是函数
27
- if (typeof event !== 'string') {
28
- throw new Error('参数 "event" 必须是一个字符串。');
29
- }
30
- if (typeof subscriber !== 'function') {
31
- throw new Error('参数 "subscriber" 必须是一个函数。');
32
- }
33
- let event$ = fromEvent(elem, event)// 创建事件流 Observable
34
-
35
- try {
36
- let subscription = subscriber(event$); // 订阅事件流并处理
37
- attachSubscriptionToNode(elem, subscription); // 将订阅附加到 DOM 元素,便于管理
38
-
39
- } catch (error) {
40
- console.error(`处理事件 "${event}" 时发生错误:`, error);
41
- throw error;
42
- }
43
-
44
- // 返回元素本身,支持链式调用
45
- return elem;
46
- }
47
- )
48
-
49
- }
@@ -1,97 +0,0 @@
1
- import { fromEvent } from 'rxjs';
2
- import { pipeEvent } from './pipeEvent';
3
- import { attachSubscriptionToNode } from './attachSubscriptionToNode';
4
-
5
- jest.mock('rxjs', () => ({
6
- fromEvent: jest.fn((elem, event) => ({
7
- pipe: jest.fn(() => ({
8
- subscribe: jest.fn(),
9
- })),
10
- })),
11
- }));
12
-
13
- jest.mock('./attachSubscriptionToNode');
14
-
15
- describe('pipeEvent', () => {
16
- let elem;
17
-
18
- beforeEach(() => {
19
- elem = document.createElement('div');
20
- document.body.appendChild(elem);
21
- jest.clearAllMocks();
22
- });
23
-
24
- afterEach(() => {
25
- document.body.removeChild(elem);
26
- });
27
-
28
- test('should throw an error if elem is not a valid DOM element', () => {
29
- expect(() => pipeEvent(null)).toThrow('参数 "elem" 必须是一个有效的 DOM 元素。');
30
- expect(() => pipeEvent({})).toThrow('参数 "elem" 必须是一个有效的 DOM 元素。');
31
- });
32
-
33
- test('should throw an error if event is not a string', () => {
34
- const pipe = pipeEvent(elem);
35
- expect(() => pipe(null, jest.fn())).toThrow('参数 "event" 必须是一个字符串。');
36
- expect(() => pipe(123, jest.fn())).toThrow('参数 "event" 必须是一个字符串。');
37
- });
38
-
39
- test('should throw an error if subscriber is not a function', () => {
40
- const pipe = pipeEvent(elem);
41
- expect(() => pipe('click', null)).toThrow('参数 "subscriber" 必须是一个函数。');
42
- expect(() => pipe('click', 123)).toThrow('参数 "subscriber" 必须是一个函数。');
43
- });
44
-
45
- test('should process the event stream and attach the subscription to the node', () => {
46
- const mockEvent$ = {
47
- pipe: jest.fn(() => ({
48
- subscribe: jest.fn(),
49
- })),
50
- };
51
- fromEvent.mockReturnValue(mockEvent$);
52
-
53
- const subscriber = jest.fn((event$) => event$.pipe());
54
- const pipe = pipeEvent(elem);
55
-
56
- pipe('click', subscriber);
57
-
58
- expect(fromEvent).toHaveBeenCalledWith(elem, 'click');
59
- expect(subscriber).toHaveBeenCalledWith(mockEvent$);
60
- expect(attachSubscriptionToNode).toHaveBeenCalledWith(elem, expect.any(Object));
61
- });
62
-
63
- test('should log an error and rethrow if subscriber fails', () => {
64
- const mockEvent$ = {
65
- pipe: jest.fn(() => ({
66
- subscribe: jest.fn(),
67
- })),
68
- };
69
- fromEvent.mockReturnValue(mockEvent$);
70
-
71
- console.error = jest.fn();
72
-
73
- const subscriber = jest.fn(() => {
74
- throw new Error('Subscriber failed');
75
- });
76
- const pipe = pipeEvent(elem);
77
-
78
- expect(() => pipe('click', subscriber)).toThrow('Subscriber failed');
79
- expect(console.error).toHaveBeenCalledWith('处理事件 "click" 时发生错误:', expect.any(Error));
80
- });
81
-
82
- test('should return the element itself for chainable calls', () => {
83
- const mockEvent$ = {
84
- pipe: jest.fn(() => ({
85
- subscribe: jest.fn(),
86
- })),
87
- };
88
- fromEvent.mockReturnValue(mockEvent$);
89
-
90
- const subscriber = jest.fn((event$) => event$.pipe());
91
- const pipe = pipeEvent(elem);
92
-
93
- const result = pipe('click', subscriber);
94
-
95
- expect(result).toBe(elem);
96
- });
97
- });
@@ -1,15 +0,0 @@
1
- import { Observer } from 'rxjs';
2
-
3
- /**
4
- * 为指定的 DOM 元素订阅事件流,并将订阅与元素绑定,便于管理。
5
- *
6
- * @param elem - 要订阅事件的 DOM 元素。
7
- * @returns 一个函数,接受事件名称和观察者(函数或观察者对象),用于订阅事件,返回元素本身。
8
- * @throws 如果参数无效会抛出错误。
9
- */
10
- export function subscribeEvent(
11
- elem: HTMLElement
12
- ): (
13
- event: string,
14
- observer: ((value: Event) => void) | Partial<Observer<Event>>
15
- ) => HTMLElement;
@@ -1,56 +0,0 @@
1
- import { fromEvent } from 'rxjs';
2
- import { attachSubscriptionToNode } from './attachSubscriptionToNode';
3
-
4
- /**
5
- * @template T
6
- * @typedef { import('rxjs').Observer<T> } Observer
7
- */
8
-
9
- /**
10
- * 为指定的 DOM 元素订阅事件流,并将订阅与元素绑定,便于管理。
11
- *
12
- * @param {HTMLElement} elem - 要订阅事件的 DOM 元素。
13
- * @returns {(e:string, o:((value: Event) => void) | Partial<Observer<Event>>) => HTMLElement} - 返回一个函数,该函数接受事件名称和观察者,用于订阅事件。
14
- * @throws {Error} 如果参数无效。
15
- *
16
- */
17
- export function subscribeEvent(elem) {
18
- // 参数检查,确保 elem 是一个有效的 DOM 元素
19
- if (!(elem instanceof HTMLElement)) {
20
- throw new Error('参数 "elem" 必须是一个有效的 DOM 元素。');
21
- }
22
-
23
- return (
24
- /**
25
- * @param {string} event
26
- * @param {((value: Event) => void) | Partial<Observer<Event>>} observer
27
- * @returns
28
- */
29
- (event, observer) => {
30
- // 参数检查,确保 event 是字符串,observer 是函数或观察者对象
31
- if (typeof event !== 'string') {
32
- throw new Error('参数 "event" 必须是一个字符串。');
33
- }
34
- if ((typeof observer !== 'function' && typeof observer !== 'object') || observer === null) {
35
- throw new Error('参数 "observer" 必须是一个函数或观察者对象。');
36
- }
37
-
38
- // 创建事件流 Observable
39
- let event$ = fromEvent(elem, event);
40
-
41
- // 订阅事件流
42
- let subscription;
43
- try {
44
- subscription = event$.subscribe(observer);
45
- } catch (error) {
46
- console.error(`订阅事件 "${event}" 时发生错误:`, error);
47
- throw error;
48
- }
49
-
50
- // 将订阅附加到 DOM 元素,便于管理
51
- attachSubscriptionToNode(elem, subscription);
52
-
53
- // 返回元素本身,支持链式调用
54
- return elem;
55
- });
56
- }
@@ -1,88 +0,0 @@
1
- import { fromEvent } from 'rxjs';
2
- import { subscribeEvent } from './subscribeEvent';
3
- import { attachSubscriptionToNode } from './attachSubscriptionToNode';
4
-
5
- jest.mock('rxjs', () => ({
6
- fromEvent: jest.fn((elem, event) => ({
7
- subscribe: jest.fn((observer) => {
8
- // 模拟事件触发
9
- elem.addEventListener(event, observer);
10
- return {
11
- unsubscribe: () => elem.removeEventListener(event, observer), // 模拟取消订阅
12
- };
13
- }),
14
- })),
15
- }));
16
-
17
- jest.mock('./attachSubscriptionToNode');
18
-
19
- describe('subscribeEvent', () => {
20
- let elem;
21
-
22
- beforeEach(() => {
23
- elem = document.createElement('div');
24
- jest.clearAllMocks();
25
- });
26
-
27
- test('should throw an error if elem is not a valid DOM element', () => {
28
- expect(() => subscribeEvent(null)).toThrow('参数 "elem" 必须是一个有效的 DOM 元素。');
29
- expect(() => subscribeEvent({})).toThrow('参数 "elem" 必须是一个有效的 DOM 元素。');
30
- });
31
-
32
- test('should throw an error if event is not a string', () => {
33
- const subscribe = subscribeEvent(elem);
34
- expect(() => subscribe(null, jest.fn())).toThrow('参数 "event" 必须是一个字符串。');
35
- expect(() => subscribe(123, jest.fn())).toThrow('参数 "event" 必须是一个字符串。');
36
- });
37
-
38
- test('should throw an error if observer is not a function or object', () => {
39
- const subscribe = subscribeEvent(elem);
40
- expect(() => subscribe('click', null)).toThrow('参数 "observer" 必须是一个函数或观察者对象。');
41
- expect(() => subscribe('click', 123)).toThrow('参数 "observer" 必须是一个函数或观察者对象。');
42
- });
43
-
44
- test('should subscribe to the event and attach the subscription to the node', () => {
45
- const observer = jest.fn();
46
- const subscribe = subscribeEvent(elem);
47
-
48
- subscribe('click', observer);
49
-
50
- expect(fromEvent).toHaveBeenCalledWith(elem, 'click');
51
- expect(attachSubscriptionToNode).toHaveBeenCalledWith(elem, expect.any(Object));
52
-
53
- // 模拟点击事件
54
- elem.click();
55
- expect(observer).toHaveBeenCalledTimes(1);
56
- });
57
-
58
- test('should return the element itself for chainable calls', () => {
59
- const observer = jest.fn();
60
- const subscribe = subscribeEvent(elem);
61
-
62
- const result = subscribe('click', observer);
63
-
64
- expect(result).toBe(elem);
65
- });
66
-
67
- test('should log an error and rethrow if subscription fails', () => {
68
- const mockEvent$ = {
69
- subscribe: jest.fn(() => {
70
- throw new Error('Subscription failed');
71
- }),
72
- };
73
- fromEvent.mockReturnValue(mockEvent$);
74
-
75
- console.error = jest.fn();
76
-
77
- const observer = jest.fn();
78
- const subscribe = subscribeEvent(elem);
79
-
80
- expect(() => subscribe('click', observer)).toThrow('Subscription failed');
81
- expect(console.error).toHaveBeenCalledWith('订阅事件 "click" 时发生错误:', expect.any(Error));
82
- // 还原环境
83
- fromEvent.mockReset(); // 清除 fromEvent 的模拟
84
- console.error.mockRestore(); // 还原 console.error
85
-
86
- });
87
-
88
- });
@@ -1,10 +0,0 @@
1
- export * from './intersectObject'
2
- export * from './isEmptyObject'
3
- export * from './isPlainObject'
4
- export * from './nestedCombineLatest'
5
- export * from './nestedMerge'
6
- export * from './pickBehaviorSubject'
7
- export * from './pluckProperty'
8
- export * from './restore'
9
- export * from './splitObjectByObservable'
10
-
@@ -1,11 +0,0 @@
1
- export * from './intersectObject'
2
- export * from './isEmptyObject'
3
- export * from './isPlainObject'
4
- export * from './nestedCombineLatest'
5
- export * from './nestedMerge'
6
- export * from './pickBehaviorSubject'
7
- export * from './pluckProperty'
8
- export * from './restore'
9
- export * from './splitObjectByObservable'
10
-
11
-
@@ -1,12 +0,0 @@
1
- /**
2
- * 创建一个新对象,仅包含指定 keys 的属性。
3
- *
4
- * @param obj - 源对象。
5
- * @param keys - 要保留的属性名数组。
6
- * @returns 新对象,仅包含指定属性。
7
- * @throws 如果 obj 不是对象或 keys 不是数组会抛出 TypeError。
8
- */
9
- export function intersectObject(
10
- obj: Record<string,any>,
11
- keys: string[]
12
- ): Record<string,any>;
@@ -1,23 +0,0 @@
1
- /**
2
- * Creates an object composed of the picked object properties.
3
- * @param {Record<string,any>} obj - Source object
4
- * @param {string[]} keys - Array of property keys to pick
5
- * @returns {Record<string,any>} New object with picked properties
6
- * @throws {TypeError} If obj is not an object or keys is not an array
7
- */
8
- export function intersectObject(obj, keys) {
9
- // 类型检查
10
- if (typeof obj !== 'object' || obj === null) {
11
- throw new TypeError('First argument must be an object');
12
- }
13
-
14
- if (!Array.isArray(keys)) {
15
- throw new TypeError('Second argument must be an array');
16
- }
17
-
18
- return Object.fromEntries(
19
- keys
20
- .filter(key => key in obj)
21
- .map(key => [key, obj[key]])
22
- );
23
- }
@@ -1,69 +0,0 @@
1
- import { intersectObject } from './intersectObject.js'
2
-
3
- describe('intersectObject', () => {
4
- // 基础测试用例
5
- test('should pick existing properties from object', () => {
6
- const obj = { a: 1, b: 2, c: 3, d: 4, e: 5 };
7
- const keys = ['a', 'd', 'e'];
8
- const result = intersectObject(obj, keys);
9
- expect(result).toEqual({ a: 1, d: 4, e: 5 });
10
- });
11
-
12
- // 1. 测试部分键不存在的情况
13
- test('should ignore non-existent keys', () => {
14
- const obj = { name: 'Alice', age: 25 };
15
- const keys = ['name', 'city', 'country'];
16
- const result = intersectObject(obj, keys);
17
- expect(result).toEqual({ name: 'Alice' });
18
- });
19
-
20
- // 2. 测试空键数组的情况
21
- test('should return empty object for empty keys array', () => {
22
- const obj = { a: 1, b: 2 };
23
- const keys = [];
24
- const result = intersectObject(obj, keys);
25
- expect(result).toEqual({});
26
- });
27
-
28
- // 3. 测试空对象的情况
29
- test('should return empty object when source is empty', () => {
30
- const obj = {};
31
- const keys = ['a', 'b', 'c'];
32
- const result = intersectObject(obj, keys);
33
- expect(result).toEqual({});
34
- });
35
-
36
- // 4. 测试继承属性的情况
37
- test('should include inherited properties when using "in" operator', () => {
38
- const parent = { inheritedProp: 'value' };
39
- const obj = Object.create(parent);
40
- obj.ownProp = 'ownValue';
41
- const keys = ['inheritedProp', 'ownProp', 'nonExistent'];
42
- const result = intersectObject(obj, keys);
43
- expect(result).toEqual({ inheritedProp: 'value', ownProp: 'ownValue' });
44
- });
45
-
46
- // 扩展建议1: 类型检查
47
- describe('type checking', () => {
48
- test('should throw error when first argument is not an object', () => {
49
- expect(() => intersectObject(null, ['a'])).toThrow();
50
- expect(() => intersectObject(123, ['a'])).toThrow();
51
- expect(() => intersectObject('string', ['a'])).toThrow();
52
- });
53
-
54
- test('should throw error when second argument is not an array', () => {
55
- expect(() => intersectObject({}, null)).toThrow();
56
- expect(() => intersectObject({}, 123)).toThrow();
57
- expect(() => intersectObject({}, 'string')).toThrow();
58
- });
59
- });
60
-
61
- // 可选: 测试Symbol键的情况
62
- test('should work with Symbol keys', () => {
63
- const sym = Symbol('symbolKey');
64
- const obj = { [sym]: 'symbolValue', regularKey: 'regularValue' };
65
- const keys = [sym, 'regularKey'];
66
- const result = intersectObject(obj, keys);
67
- expect(result).toEqual({ [sym]: 'symbolValue', regularKey: 'regularValue' });
68
- });
69
- });
@@ -1,7 +0,0 @@
1
- /**
2
- * 判断对象是否为空对象(非数组、非 null,且无自有属性)。
3
- *
4
- * @param obj - 要判断的对象。
5
- * @returns 如果是空对象返回 true,否则返回 false。
6
- */
7
- export function isEmptyObject(obj: unknown): boolean;