sygnal 5.3.7 → 6.0.0

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 (438) hide show
  1. package/CHANGELOG.md +646 -0
  2. package/README.md +77 -47
  3. package/dist/astro/client.cjs.js +33 -8114
  4. package/dist/astro/client.cjs.js.map +1 -0
  5. package/dist/astro/client.mjs +33 -8114
  6. package/dist/astro/client.mjs.map +1 -0
  7. package/dist/astro/index.cjs.js +1039 -9
  8. package/dist/astro/index.cjs.js.map +1 -0
  9. package/dist/astro/index.mjs +1038 -9
  10. package/dist/astro/index.mjs.map +1 -0
  11. package/dist/astro/server.cjs.js +3400 -166
  12. package/dist/astro/server.cjs.js.map +1 -0
  13. package/dist/astro/server.mjs +3400 -166
  14. package/dist/astro/server.mjs.map +1 -0
  15. package/dist/devtools.cjs.js +1431 -0
  16. package/dist/devtools.cjs.js.map +1 -0
  17. package/dist/devtools.esm.js +1419 -0
  18. package/dist/devtools.esm.js.map +1 -0
  19. package/dist/diagnostics.cjs.js +4033 -0
  20. package/dist/diagnostics.cjs.js.map +1 -0
  21. package/dist/diagnostics.esm.js +4003 -0
  22. package/dist/diagnostics.esm.js.map +1 -0
  23. package/dist/element.cjs.js +230 -0
  24. package/dist/element.cjs.js.map +1 -0
  25. package/dist/element.esm.js +228 -0
  26. package/dist/element.esm.js.map +1 -0
  27. package/dist/guide/accessibility.md +257 -0
  28. package/dist/guide/adapters.md +221 -0
  29. package/dist/guide/behaviors.md +312 -0
  30. package/dist/guide/browser-sources.md +203 -0
  31. package/dist/guide/drag-and-drop.md +342 -0
  32. package/dist/guide/element-commands.md +306 -0
  33. package/dist/guide/error-boundaries.md +169 -0
  34. package/dist/guide/forms-reference.md +381 -0
  35. package/dist/guide/forms.md +250 -0
  36. package/dist/guide/http.md +299 -0
  37. package/dist/guide/inputs.md +173 -0
  38. package/dist/guide/persistence.md +245 -0
  39. package/dist/guide/recipes/carousel.md +155 -0
  40. package/dist/guide/recipes/charts.md +177 -0
  41. package/dist/guide/recipes/code-editor.md +135 -0
  42. package/dist/guide/recipes/data-grid.md +155 -0
  43. package/dist/guide/recipes/data-table.md +196 -0
  44. package/dist/guide/recipes/i18n.md +222 -0
  45. package/dist/guide/recipes/icons.md +115 -0
  46. package/dist/guide/recipes/overview.md +33 -0
  47. package/dist/guide/recipes/rich-text.md +154 -0
  48. package/dist/guide/resources.md +471 -0
  49. package/dist/guide/ssr.md +255 -0
  50. package/dist/guide/timers.md +178 -0
  51. package/dist/guide/ui/accordion.md +93 -0
  52. package/dist/guide/ui/combobox.md +144 -0
  53. package/dist/guide/ui/dialog.md +124 -0
  54. package/dist/guide/ui/disclosure.md +60 -0
  55. package/dist/guide/ui/menu.md +125 -0
  56. package/dist/guide/ui/overview.md +166 -0
  57. package/dist/guide/ui/popover.md +101 -0
  58. package/dist/guide/ui/select.md +114 -0
  59. package/dist/guide/ui/tabs.md +161 -0
  60. package/dist/guide/ui/toaster.md +152 -0
  61. package/dist/guide/ui/tooltip.md +103 -0
  62. package/dist/guide/undo.md +178 -0
  63. package/dist/guide/virtual-collections.md +183 -0
  64. package/dist/guide/web-components.md +179 -0
  65. package/dist/guide/widgets.md +217 -0
  66. package/dist/index.cjs.js +15283 -6279
  67. package/dist/index.cjs.js.map +1 -0
  68. package/dist/index.d.ts +3739 -370
  69. package/dist/index.esm.js +15230 -6274
  70. package/dist/index.esm.js.map +1 -0
  71. package/dist/jsx-dev-runtime.cjs.js +27 -329
  72. package/dist/jsx-dev-runtime.cjs.js.map +1 -0
  73. package/dist/jsx-dev-runtime.esm.js +20 -322
  74. package/dist/jsx-dev-runtime.esm.js.map +1 -0
  75. package/dist/jsx-runtime.cjs.js +27 -329
  76. package/dist/jsx-runtime.cjs.js.map +1 -0
  77. package/dist/jsx-runtime.esm.js +20 -322
  78. package/dist/jsx-runtime.esm.js.map +1 -0
  79. package/dist/jsx.cjs.js +11 -309
  80. package/dist/jsx.cjs.js.map +1 -0
  81. package/dist/jsx.esm.js +9 -310
  82. package/dist/jsx.esm.js.map +1 -0
  83. package/dist/react.cjs.js +117 -0
  84. package/dist/react.cjs.js.map +1 -0
  85. package/dist/react.esm.js +115 -0
  86. package/dist/react.esm.js.map +1 -0
  87. package/dist/shims/globalthis.cjs +20 -0
  88. package/dist/sygnal.min.js +2 -1
  89. package/dist/sygnal.min.js.map +1 -0
  90. package/dist/ui-combobox.cjs.js +169 -0
  91. package/dist/ui-combobox.cjs.js.map +1 -0
  92. package/dist/ui-combobox.esm.js +148 -0
  93. package/dist/ui-combobox.esm.js.map +1 -0
  94. package/dist/ui-menu.cjs.js +87 -0
  95. package/dist/ui-menu.cjs.js.map +1 -0
  96. package/dist/ui-menu.esm.js +66 -0
  97. package/dist/ui-menu.esm.js.map +1 -0
  98. package/dist/ui-select.cjs.js +104 -0
  99. package/dist/ui-select.cjs.js.map +1 -0
  100. package/dist/ui-select.esm.js +83 -0
  101. package/dist/ui-select.esm.js.map +1 -0
  102. package/dist/ui.cjs.js +738 -0
  103. package/dist/ui.cjs.js.map +1 -0
  104. package/dist/ui.esm.js +727 -0
  105. package/dist/ui.esm.js.map +1 -0
  106. package/dist/vike/ClientOnly.cjs.js +5 -14
  107. package/dist/vike/ClientOnly.cjs.js.map +1 -0
  108. package/dist/vike/ClientOnly.mjs +5 -14
  109. package/dist/vike/ClientOnly.mjs.map +1 -0
  110. package/dist/vike/{+config.js → config/+config.js} +10 -1
  111. package/dist/vike/config/+config.js.map +1 -0
  112. package/dist/vike/config/package.json +6 -0
  113. package/dist/vike/onRenderClient.cjs.js +166 -95
  114. package/dist/vike/onRenderClient.cjs.js.map +1 -0
  115. package/dist/vike/onRenderClient.mjs +166 -95
  116. package/dist/vike/onRenderClient.mjs.map +1 -0
  117. package/dist/vike/onRenderHtml.cjs.js +60 -24
  118. package/dist/vike/onRenderHtml.cjs.js.map +1 -0
  119. package/dist/vike/onRenderHtml.mjs +61 -25
  120. package/dist/vike/onRenderHtml.mjs.map +1 -0
  121. package/dist/vite/plugin.cjs.js +926 -65
  122. package/dist/vite/plugin.cjs.js.map +1 -0
  123. package/dist/vite/plugin.mjs +925 -65
  124. package/dist/vite/plugin.mjs.map +1 -0
  125. package/dist/zag.cjs.js +408 -0
  126. package/dist/zag.cjs.js.map +1 -0
  127. package/dist/zag.esm.js +405 -0
  128. package/dist/zag.esm.js.map +1 -0
  129. package/llms.txt +313 -0
  130. package/package.json +109 -16
  131. package/src/astro/client.ts +40 -18
  132. package/src/astro/index.d.ts +48 -1
  133. package/src/astro/index.ts +106 -9
  134. package/src/astro/server.ts +11 -3
  135. package/src/collection.ts +6 -90
  136. package/src/core/actions.ts +134 -0
  137. package/src/core/cell.ts +202 -0
  138. package/src/core/debug.ts +23 -0
  139. package/src/core/define.ts +242 -0
  140. package/src/core/hooks.ts +314 -0
  141. package/src/core/hosts/collection.ts +325 -0
  142. package/src/core/hosts/switchable.ts +146 -0
  143. package/src/core/instance.ts +592 -0
  144. package/src/core/markers/clientonly.ts +13 -0
  145. package/src/core/markers/lazy.ts +40 -0
  146. package/src/core/markers/portal.ts +96 -0
  147. package/src/core/markers/suspense.ts +41 -0
  148. package/src/core/markers/transition.ts +70 -0
  149. package/src/core/registry.ts +25 -0
  150. package/src/core/runtime.ts +573 -0
  151. package/src/core/statics.ts +104 -0
  152. package/src/core/teardown.ts +60 -0
  153. package/src/core/view.ts +37 -0
  154. package/src/cycle/dom/DocumentDOMSource.ts +13 -8
  155. package/src/cycle/dom/ElementFinder.ts +7 -9
  156. package/src/cycle/dom/EventDelegator.ts +174 -223
  157. package/src/cycle/dom/IsolateModule.ts +65 -35
  158. package/src/cycle/dom/MainDOMSource.ts +13 -2
  159. package/src/cycle/dom/PriorityQueue.ts +4 -2
  160. package/src/cycle/dom/SymbolTree.ts +18 -47
  161. package/src/cycle/dom/classNameModule.ts +76 -0
  162. package/src/cycle/dom/controlledInputModule.ts +50 -0
  163. package/src/cycle/dom/enrichEventStream.ts +29 -45
  164. package/src/cycle/dom/fragment.ts +7 -0
  165. package/src/cycle/dom/isolate.ts +30 -27
  166. package/src/cycle/dom/makeDOMDriver.ts +115 -57
  167. package/src/cycle/dom/mockDOMSource.ts +83 -9
  168. package/src/cycle/dom/modules.ts +21 -4
  169. package/src/cycle/dom/propsModule.ts +65 -0
  170. package/src/cycle/dom/selectModule.ts +22 -17
  171. package/src/cycle/dom/snabbdom.ts +1 -6
  172. package/src/cycle/dom/thunk.ts +3 -0
  173. package/src/cycle/dom/utils.ts +98 -0
  174. package/src/cycle/dom/viewTransition.ts +43 -0
  175. package/src/cycle/state/StateSource.ts +20 -4
  176. package/src/cycle/state/objIsEqual.ts +50 -0
  177. package/src/cycle/state/types.ts +0 -10
  178. package/src/defineComponent.ts +34 -0
  179. package/src/devtools.d.ts +151 -0
  180. package/src/devtools.ts +34 -0
  181. package/src/element.d.ts +59 -0
  182. package/src/element.ts +235 -0
  183. package/src/extra/backoff.ts +9 -0
  184. package/src/extra/behaviors.ts +169 -0
  185. package/src/extra/browserSignals.ts +23 -0
  186. package/src/extra/browserSources.ts +326 -0
  187. package/src/extra/command.ts +3 -3
  188. package/src/extra/controls.ts +47 -0
  189. package/src/extra/copyAsTest.ts +286 -0
  190. package/src/extra/devtools.ts +109 -31
  191. package/src/extra/devtoolsActions.ts +379 -0
  192. package/src/extra/devtoolsHook.ts +9 -0
  193. package/src/extra/devtoolsNext.ts +83 -0
  194. package/src/extra/diagnostics/checks/actionLog.ts +108 -0
  195. package/src/extra/diagnostics/checks/behaviors.ts +49 -0
  196. package/src/extra/diagnostics/checks/browserSources.ts +96 -0
  197. package/src/extra/diagnostics/checks/collections.ts +67 -0
  198. package/src/extra/diagnostics/checks/controls.ts +148 -0
  199. package/src/extra/diagnostics/checks/dataset.ts +57 -0
  200. package/src/extra/diagnostics/checks/dom.ts +250 -0
  201. package/src/extra/diagnostics/checks/elementCommands.ts +175 -0
  202. package/src/extra/diagnostics/checks/events.ts +83 -0
  203. package/src/extra/diagnostics/checks/fetch.ts +135 -0
  204. package/src/extra/diagnostics/checks/forms.ts +163 -0
  205. package/src/extra/diagnostics/checks/index.ts +202 -0
  206. package/src/extra/diagnostics/checks/inspect.ts +427 -0
  207. package/src/extra/diagnostics/checks/next.ts +417 -0
  208. package/src/extra/diagnostics/checks/persist.ts +54 -0
  209. package/src/extra/diagnostics/checks/props.ts +56 -0
  210. package/src/extra/diagnostics/checks/public.d.ts +302 -0
  211. package/src/extra/diagnostics/checks/replies.ts +128 -0
  212. package/src/extra/diagnostics/checks/router.ts +100 -0
  213. package/src/extra/diagnostics/checks/rxjsHints.ts +88 -0
  214. package/src/extra/diagnostics/checks/shared.ts +203 -0
  215. package/src/extra/diagnostics/checks/shorthand.ts +115 -0
  216. package/src/extra/diagnostics/checks/sortable.ts +129 -0
  217. package/src/extra/diagnostics/checks/state.ts +148 -0
  218. package/src/extra/diagnostics/checks/statics.ts +48 -0
  219. package/src/extra/diagnostics/checks/strict.ts +55 -0
  220. package/src/extra/diagnostics/checks/timers.ts +80 -0
  221. package/src/extra/diagnostics/checks/viewTransitions.ts +47 -0
  222. package/src/extra/diagnostics/checks/virtual.ts +73 -0
  223. package/src/extra/diagnostics/checks/widgets.ts +109 -0
  224. package/src/extra/diagnostics/checks/wiring.ts +121 -0
  225. package/src/extra/diagnostics/codes.ts +477 -0
  226. package/src/extra/diagnostics/index.ts +353 -0
  227. package/src/extra/diagnostics/legacy.ts +76 -0
  228. package/src/extra/driverFactories.ts +172 -60
  229. package/src/extra/elementCommands.ts +53 -0
  230. package/src/extra/eventDriver.ts +4 -0
  231. package/src/extra/fetchDriver.ts +519 -0
  232. package/src/extra/flatten.ts +75 -0
  233. package/src/extra/focusWithin.ts +27 -0
  234. package/src/extra/form.ts +268 -0
  235. package/src/extra/formHelpers.ts +139 -0
  236. package/src/extra/head.ts +106 -0
  237. package/src/extra/hmr.ts +2 -3
  238. package/src/extra/owned.ts +24 -0
  239. package/src/extra/pager.ts +50 -0
  240. package/src/extra/persist.ts +133 -0
  241. package/src/extra/pwa.ts +1 -1
  242. package/src/extra/queryCache.ts +107 -0
  243. package/src/extra/reducers.ts +13 -6
  244. package/src/extra/reduxDevtools.ts +92 -0
  245. package/src/extra/replies.ts +54 -0
  246. package/src/extra/router.ts +323 -0
  247. package/src/extra/run.ts +94 -210
  248. package/src/extra/selection.ts +76 -0
  249. package/src/extra/socketDriver.ts +265 -0
  250. package/src/extra/sortable.ts +377 -0
  251. package/src/extra/ssr.ts +427 -160
  252. package/src/extra/standardSchema.ts +27 -0
  253. package/src/extra/testing.ts +3158 -190
  254. package/src/extra/timers.ts +95 -0
  255. package/src/extra/undo.ts +261 -0
  256. package/src/extra/viewTransitions.ts +38 -0
  257. package/src/extra/virtual.ts +513 -0
  258. package/src/extra/widget.ts +201 -0
  259. package/src/extra/xstreamExtras.ts +269 -0
  260. package/src/index.d.ts +3012 -87
  261. package/src/index.ts +32 -10
  262. package/src/jsx-runtime.ts +15 -1
  263. package/src/jsx.ts +2 -1
  264. package/src/lazy.ts +50 -7
  265. package/src/portal.ts +3 -1
  266. package/src/pragma/index.ts +262 -134
  267. package/src/react-peers.d.ts +5 -0
  268. package/src/react.d.ts +43 -0
  269. package/src/react.ts +110 -0
  270. package/src/shared.ts +48 -0
  271. package/src/slot.ts +1 -1
  272. package/src/suspense.ts +3 -1
  273. package/src/switchable.ts +6 -119
  274. package/src/transition.ts +3 -1
  275. package/src/ui/accordion.ts +64 -0
  276. package/src/ui/dialog.ts +129 -0
  277. package/src/ui/disclosure.ts +35 -0
  278. package/src/ui/popover.ts +45 -0
  279. package/src/ui/shared.ts +94 -0
  280. package/src/ui/tabs.ts +82 -0
  281. package/src/ui/toaster.ts +198 -0
  282. package/src/ui/tooltip.ts +70 -0
  283. package/src/ui/zag/combobox.ts +115 -0
  284. package/src/ui/zag/menu.ts +40 -0
  285. package/src/ui/zag/select.ts +54 -0
  286. package/src/ui/zag/shared.ts +43 -0
  287. package/src/ui-combobox.d.ts +20 -0
  288. package/src/ui-combobox.ts +6 -0
  289. package/src/ui-menu.d.ts +30 -0
  290. package/src/ui-menu.ts +6 -0
  291. package/src/ui-select.d.ts +17 -0
  292. package/src/ui-select.ts +6 -0
  293. package/src/ui-zag-types.d.ts +42 -0
  294. package/src/ui.d.ts +208 -0
  295. package/src/ui.ts +15 -0
  296. package/src/vike/+config.ts +9 -1
  297. package/src/vike/ClientOnly.ts +1 -1
  298. package/src/vike/onRenderClient.ts +144 -96
  299. package/src/vike/onRenderHtml.ts +69 -26
  300. package/src/vike/types.ts +27 -4
  301. package/src/vite/globalthis-shim.ts +18 -0
  302. package/src/vite/globalthis.ts +56 -0
  303. package/src/vite/plugin.d.ts +114 -2
  304. package/src/vite/plugin.ts +920 -56
  305. package/src/zag.d.ts +64 -0
  306. package/src/zag.ts +238 -0
  307. package/dist/astro/astro/client.d.ts +0 -5
  308. package/dist/astro/astro/index.d.ts +0 -16
  309. package/dist/astro/astro/server.d.ts +0 -12
  310. package/dist/astro/client.d.ts +0 -5
  311. package/dist/astro/client.esm.js +0 -4665
  312. package/dist/astro/collection.d.ts +0 -12
  313. package/dist/astro/component.d.ts +0 -22
  314. package/dist/astro/cycle/dom/BodyDOMSource.d.ts +0 -10
  315. package/dist/astro/cycle/dom/DOMSource.d.ts +0 -11
  316. package/dist/astro/cycle/dom/DocumentDOMSource.d.ts +0 -12
  317. package/dist/astro/cycle/dom/ElementFinder.d.ts +0 -8
  318. package/dist/astro/cycle/dom/EventDelegator.d.ts +0 -34
  319. package/dist/astro/cycle/dom/IsolateModule.d.ts +0 -23
  320. package/dist/astro/cycle/dom/MainDOMSource.d.ts +0 -32
  321. package/dist/astro/cycle/dom/PriorityQueue.d.ts +0 -7
  322. package/dist/astro/cycle/dom/ScopeChecker.d.ts +0 -9
  323. package/dist/astro/cycle/dom/SymbolTree.d.ts +0 -9
  324. package/dist/astro/cycle/dom/VNodeWrapper.d.ts +0 -8
  325. package/dist/astro/cycle/dom/enrichEventStream.d.ts +0 -24
  326. package/dist/astro/cycle/dom/fromEvent.d.ts +0 -6
  327. package/dist/astro/cycle/dom/index.d.ts +0 -8
  328. package/dist/astro/cycle/dom/isolate.d.ts +0 -9
  329. package/dist/astro/cycle/dom/makeDOMDriver.d.ts +0 -11
  330. package/dist/astro/cycle/dom/mockDOMSource.d.ts +0 -17
  331. package/dist/astro/cycle/dom/modules.d.ts +0 -5
  332. package/dist/astro/cycle/dom/snabbdom.d.ts +0 -22
  333. package/dist/astro/cycle/dom/styleModule.d.ts +0 -13
  334. package/dist/astro/cycle/dom/thunk.d.ts +0 -11
  335. package/dist/astro/cycle/dom/utils.d.ts +0 -8
  336. package/dist/astro/cycle/isolate/index.d.ts +0 -42
  337. package/dist/astro/cycle/run/adapt.d.ts +0 -6
  338. package/dist/astro/cycle/run/index.d.ts +0 -36
  339. package/dist/astro/cycle/run/internals.d.ts +0 -8
  340. package/dist/astro/cycle/run/types.d.ts +0 -49
  341. package/dist/astro/cycle/state/Collection.d.ts +0 -29
  342. package/dist/astro/cycle/state/StateSource.d.ts +0 -20
  343. package/dist/astro/cycle/state/index.d.ts +0 -5
  344. package/dist/astro/cycle/state/pickCombine.d.ts +0 -3
  345. package/dist/astro/cycle/state/pickMerge.d.ts +0 -3
  346. package/dist/astro/cycle/state/types.d.ts +0 -18
  347. package/dist/astro/cycle/state/withState.d.ts +0 -17
  348. package/dist/astro/extra/classes.d.ts +0 -7
  349. package/dist/astro/extra/devtools.d.ts +0 -78
  350. package/dist/astro/extra/dragDriver.d.ts +0 -20
  351. package/dist/astro/extra/driverFactories.d.ts +0 -12
  352. package/dist/astro/extra/eventDriver.d.ts +0 -9
  353. package/dist/astro/extra/exactState.d.ts +0 -1
  354. package/dist/astro/extra/hmr.d.ts +0 -17
  355. package/dist/astro/extra/logDriver.d.ts +0 -2
  356. package/dist/astro/extra/processDrag.d.ts +0 -19
  357. package/dist/astro/extra/processForm.d.ts +0 -15
  358. package/dist/astro/extra/run.d.ts +0 -13
  359. package/dist/astro/extra/xstreamCompat.d.ts +0 -5
  360. package/dist/astro/index.d.ts +0 -19
  361. package/dist/astro/index.esm.js +0 -27
  362. package/dist/astro/jsx-dev-runtime.d.ts +0 -1
  363. package/dist/astro/jsx-runtime.d.ts +0 -4
  364. package/dist/astro/jsx.d.ts +0 -2
  365. package/dist/astro/pragma/fn.d.ts +0 -7
  366. package/dist/astro/pragma/index.d.ts +0 -7
  367. package/dist/astro/pragma/is.d.ts +0 -10
  368. package/dist/astro/server.d.ts +0 -12
  369. package/dist/astro/server.esm.js +0 -25
  370. package/dist/astro/switchable.d.ts +0 -7
  371. package/dist/collection.d.ts +0 -12
  372. package/dist/component.d.ts +0 -22
  373. package/dist/cycle/dom/BodyDOMSource.d.ts +0 -10
  374. package/dist/cycle/dom/DOMSource.d.ts +0 -11
  375. package/dist/cycle/dom/DocumentDOMSource.d.ts +0 -12
  376. package/dist/cycle/dom/ElementFinder.d.ts +0 -8
  377. package/dist/cycle/dom/EventDelegator.d.ts +0 -34
  378. package/dist/cycle/dom/IsolateModule.d.ts +0 -23
  379. package/dist/cycle/dom/MainDOMSource.d.ts +0 -32
  380. package/dist/cycle/dom/PriorityQueue.d.ts +0 -7
  381. package/dist/cycle/dom/ScopeChecker.d.ts +0 -9
  382. package/dist/cycle/dom/SymbolTree.d.ts +0 -9
  383. package/dist/cycle/dom/VNodeWrapper.d.ts +0 -8
  384. package/dist/cycle/dom/enrichEventStream.d.ts +0 -24
  385. package/dist/cycle/dom/fromEvent.d.ts +0 -6
  386. package/dist/cycle/dom/index.d.ts +0 -8
  387. package/dist/cycle/dom/isolate.d.ts +0 -9
  388. package/dist/cycle/dom/makeDOMDriver.d.ts +0 -11
  389. package/dist/cycle/dom/mockDOMSource.d.ts +0 -17
  390. package/dist/cycle/dom/modules.d.ts +0 -5
  391. package/dist/cycle/dom/snabbdom.d.ts +0 -22
  392. package/dist/cycle/dom/styleModule.d.ts +0 -13
  393. package/dist/cycle/dom/thunk.d.ts +0 -11
  394. package/dist/cycle/dom/utils.d.ts +0 -8
  395. package/dist/cycle/isolate/index.d.ts +0 -42
  396. package/dist/cycle/run/adapt.d.ts +0 -6
  397. package/dist/cycle/run/index.d.ts +0 -36
  398. package/dist/cycle/run/internals.d.ts +0 -8
  399. package/dist/cycle/run/types.d.ts +0 -49
  400. package/dist/cycle/state/Collection.d.ts +0 -29
  401. package/dist/cycle/state/StateSource.d.ts +0 -20
  402. package/dist/cycle/state/index.d.ts +0 -5
  403. package/dist/cycle/state/pickCombine.d.ts +0 -3
  404. package/dist/cycle/state/pickMerge.d.ts +0 -3
  405. package/dist/cycle/state/types.d.ts +0 -18
  406. package/dist/cycle/state/withState.d.ts +0 -17
  407. package/dist/extra/classes.d.ts +0 -7
  408. package/dist/extra/devtools.d.ts +0 -78
  409. package/dist/extra/dragDriver.d.ts +0 -20
  410. package/dist/extra/driverFactories.d.ts +0 -12
  411. package/dist/extra/eventDriver.d.ts +0 -9
  412. package/dist/extra/exactState.d.ts +0 -1
  413. package/dist/extra/hmr.d.ts +0 -17
  414. package/dist/extra/logDriver.d.ts +0 -2
  415. package/dist/extra/processDrag.d.ts +0 -19
  416. package/dist/extra/processForm.d.ts +0 -15
  417. package/dist/extra/run.d.ts +0 -13
  418. package/dist/extra/xstreamCompat.d.ts +0 -5
  419. package/dist/jsx-dev-runtime.d.ts +0 -1
  420. package/dist/jsx-dev-runtime.js +0 -224
  421. package/dist/jsx-runtime.d.ts +0 -4
  422. package/dist/jsx-runtime.js +0 -224
  423. package/dist/jsx.d.ts +0 -2
  424. package/dist/pragma/fn.d.ts +0 -7
  425. package/dist/pragma/index.d.ts +0 -7
  426. package/dist/pragma/is.d.ts +0 -10
  427. package/dist/switchable.d.ts +0 -7
  428. package/dist/vike/+config.cjs.js +0 -65
  429. package/src/component.ts +0 -2256
  430. package/src/cycle/isolate/index.ts +0 -196
  431. package/src/cycle/run/index.ts +0 -151
  432. package/src/cycle/run/internals.ts +0 -143
  433. package/src/cycle/state/Collection.ts +0 -174
  434. package/src/cycle/state/index.ts +0 -5
  435. package/src/cycle/state/pickCombine.ts +0 -167
  436. package/src/cycle/state/pickMerge.ts +0 -122
  437. package/src/cycle/state/withState.ts +0 -47
  438. package/src/pragma/fn.ts +0 -55
@@ -1,4665 +0,0 @@
1
- import { setup } from '@cycle/run';
2
- import { makeCollection, StateSource, withState } from '@cycle/state';
3
- import { makeDOMDriver } from '@cycle/dom';
4
- import xs$1, { Stream as Stream$1 } from 'xstream';
5
- import isolate from '@cycle/isolate';
6
-
7
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
8
-
9
- var adapt$1 = {};
10
-
11
- Object.defineProperty(adapt$1, "__esModule", { value: true });
12
- function getGlobal$1() {
13
- var globalObj;
14
- if (typeof window !== 'undefined') {
15
- globalObj = window;
16
- }
17
- else if (typeof commonjsGlobal !== 'undefined') {
18
- globalObj = commonjsGlobal;
19
- }
20
- else {
21
- globalObj = this;
22
- }
23
- globalObj.Cyclejs = globalObj.Cyclejs || {};
24
- globalObj = globalObj.Cyclejs;
25
- globalObj.adaptStream = globalObj.adaptStream || (function (x) { return x; });
26
- return globalObj;
27
- }
28
- function setAdapt(f) {
29
- getGlobal$1().adaptStream = f;
30
- }
31
- adapt$1.setAdapt = setAdapt;
32
- function adapt(stream) {
33
- return getGlobal$1().adaptStream(stream);
34
- }
35
- var adapt_2 = adapt$1.adapt = adapt;
36
-
37
- function eventBusDriver(out$) {
38
- const events = new EventTarget();
39
-
40
- out$.subscribe({
41
- next: event => events.dispatchEvent(new CustomEvent('data', { detail: event }))
42
- });
43
-
44
- return {
45
- select: (type) => {
46
- const all = !type;
47
- const _type = (Array.isArray(type)) ? type : [type];
48
- let cb;
49
- const in$ = xs$1.create({
50
- start: (listener) => {
51
- cb = ({detail: event}) => {
52
- const data = (event && event.data) || null;
53
- if (all || _type.includes(event.type)) listener.next(data);
54
- };
55
- events.addEventListener('data', cb);
56
- },
57
- stop: _ => events.removeEventListener('data', cb)
58
- });
59
-
60
- return adapt_2(in$)
61
- }
62
- }
63
- }
64
-
65
- function logDriver(out$) {
66
- out$.addListener({
67
- next: (val) => {
68
- console.log(val);
69
- }
70
- });
71
- }
72
-
73
- function collection(component, stateLense, opts={}) {
74
- const {
75
- combineList = ['DOM'],
76
- globalList = ['EVENTS'],
77
- stateSourceName = 'STATE',
78
- domSourceName = 'DOM',
79
- container = 'div',
80
- containerClass
81
- } = opts;
82
-
83
- return (sources) => {
84
- const key = Date.now();
85
- const collectionOpts = {
86
- item: component,
87
- itemKey: (state, ind) => typeof state.id !== 'undefined' ? state.id : ind,
88
- itemScope: key => key,
89
- channel: stateSourceName,
90
- collectSinks: instances => {
91
- return Object.entries(sources).reduce((acc, [name, stream]) => {
92
- if (combineList.includes(name)) {
93
- const combined = instances.pickCombine(name);
94
- if (name === domSourceName && container) {
95
- acc[domSourceName] = combined.map(children => {
96
- const data = (containerClass) ? { props: { className: containerClass } } : {};
97
- return { sel: container, data, children, key, text: undefined, elm: undefined}
98
- });
99
- } else {
100
- // console.warn('Collections without wrapping containers will fail in unpredictable ways when used inside JSX fragments')
101
- acc[name] = combined;
102
- }
103
- } else {
104
- acc[name] = instances.pickMerge(name);
105
- }
106
- return acc
107
- }, {})
108
- }
109
- };
110
-
111
- const isolateOpts = {[stateSourceName]: stateLense};
112
-
113
- globalList.forEach(global => isolateOpts[global] = null);
114
- combineList.forEach(combine => isolateOpts[combine] = null);
115
-
116
- return makeIsolatedCollection(collectionOpts, isolateOpts, sources)
117
- }
118
- }
119
-
120
- /**
121
- * instantiate a cycle collection and isolate
122
- * (makes the code for doing isolated collections more readable)
123
- *
124
- * @param {Object} collectionOpts options for the makeCollection function (see cycle/state documentation)
125
- * @param {String|Object} isolateOpts options for the isolate function (see cycle/isolate documentation)
126
- * @param {Object} sources object of cycle style sources to use for the created collection
127
- * @return {Object} collection of component sinks
128
- */
129
- function makeIsolatedCollection (collectionOpts, isolateOpts, sources) {
130
- return isolate(makeCollection(collectionOpts), isolateOpts)(sources)
131
- }
132
-
133
- var dropRepeats$1 = {};
134
-
135
- var xstream = {};
136
-
137
- var ponyfill$1 = {};
138
-
139
- (function (exports) {
140
-
141
- Object.defineProperty(exports, "__esModule", {
142
- value: true
143
- });
144
- exports['default'] = symbolObservablePonyfill;
145
- function symbolObservablePonyfill(root) {
146
- var result;
147
- var _Symbol = root.Symbol;
148
-
149
- if (typeof _Symbol === 'function') {
150
- if (_Symbol.observable) {
151
- result = _Symbol.observable;
152
- } else {
153
-
154
- // This just needs to be something that won't trample other user's Symbol.for use
155
- // It also will guide people to the source of their issues, if this is problematic.
156
- // META: It's a resource locator!
157
- result = _Symbol['for']('https://github.com/benlesh/symbol-observable');
158
- try {
159
- _Symbol.observable = result;
160
- } catch (err) {
161
- // Do nothing. In some environments, users have frozen `Symbol` for security reasons,
162
- // if it is frozen assigning to it will throw. In this case, we don't care, because
163
- // they will need to use the returned value from the ponyfill.
164
- }
165
- }
166
- } else {
167
- result = '@@observable';
168
- }
169
-
170
- return result;
171
- }} (ponyfill$1));
172
-
173
- var ponyfill = ponyfill$1;
174
-
175
- var toStr$2 = Object.prototype.toString;
176
-
177
- var isArguments = function isArguments(value) {
178
- var str = toStr$2.call(value);
179
- var isArgs = str === '[object Arguments]';
180
- if (!isArgs) {
181
- isArgs = str !== '[object Array]' &&
182
- value !== null &&
183
- typeof value === 'object' &&
184
- typeof value.length === 'number' &&
185
- value.length >= 0 &&
186
- toStr$2.call(value.callee) === '[object Function]';
187
- }
188
- return isArgs;
189
- };
190
-
191
- var implementation$5;
192
- var hasRequiredImplementation;
193
-
194
- function requireImplementation () {
195
- if (hasRequiredImplementation) return implementation$5;
196
- hasRequiredImplementation = 1;
197
-
198
- var keysShim;
199
- if (!Object.keys) {
200
- // modified from https://github.com/es-shims/es5-shim
201
- var has = Object.prototype.hasOwnProperty;
202
- var toStr = Object.prototype.toString;
203
- var isArgs = isArguments; // eslint-disable-line global-require
204
- var isEnumerable = Object.prototype.propertyIsEnumerable;
205
- var hasDontEnumBug = !isEnumerable.call({ toString: null }, 'toString');
206
- var hasProtoEnumBug = isEnumerable.call(function () {}, 'prototype');
207
- var dontEnums = [
208
- 'toString',
209
- 'toLocaleString',
210
- 'valueOf',
211
- 'hasOwnProperty',
212
- 'isPrototypeOf',
213
- 'propertyIsEnumerable',
214
- 'constructor'
215
- ];
216
- var equalsConstructorPrototype = function (o) {
217
- var ctor = o.constructor;
218
- return ctor && ctor.prototype === o;
219
- };
220
- var excludedKeys = {
221
- $applicationCache: true,
222
- $console: true,
223
- $external: true,
224
- $frame: true,
225
- $frameElement: true,
226
- $frames: true,
227
- $innerHeight: true,
228
- $innerWidth: true,
229
- $onmozfullscreenchange: true,
230
- $onmozfullscreenerror: true,
231
- $outerHeight: true,
232
- $outerWidth: true,
233
- $pageXOffset: true,
234
- $pageYOffset: true,
235
- $parent: true,
236
- $scrollLeft: true,
237
- $scrollTop: true,
238
- $scrollX: true,
239
- $scrollY: true,
240
- $self: true,
241
- $webkitIndexedDB: true,
242
- $webkitStorageInfo: true,
243
- $window: true
244
- };
245
- var hasAutomationEqualityBug = (function () {
246
- /* global window */
247
- if (typeof window === 'undefined') { return false; }
248
- for (var k in window) {
249
- try {
250
- if (!excludedKeys['$' + k] && has.call(window, k) && window[k] !== null && typeof window[k] === 'object') {
251
- try {
252
- equalsConstructorPrototype(window[k]);
253
- } catch (e) {
254
- return true;
255
- }
256
- }
257
- } catch (e) {
258
- return true;
259
- }
260
- }
261
- return false;
262
- }());
263
- var equalsConstructorPrototypeIfNotBuggy = function (o) {
264
- /* global window */
265
- if (typeof window === 'undefined' || !hasAutomationEqualityBug) {
266
- return equalsConstructorPrototype(o);
267
- }
268
- try {
269
- return equalsConstructorPrototype(o);
270
- } catch (e) {
271
- return false;
272
- }
273
- };
274
-
275
- keysShim = function keys(object) {
276
- var isObject = object !== null && typeof object === 'object';
277
- var isFunction = toStr.call(object) === '[object Function]';
278
- var isArguments = isArgs(object);
279
- var isString = isObject && toStr.call(object) === '[object String]';
280
- var theKeys = [];
281
-
282
- if (!isObject && !isFunction && !isArguments) {
283
- throw new TypeError('Object.keys called on a non-object');
284
- }
285
-
286
- var skipProto = hasProtoEnumBug && isFunction;
287
- if (isString && object.length > 0 && !has.call(object, 0)) {
288
- for (var i = 0; i < object.length; ++i) {
289
- theKeys.push(String(i));
290
- }
291
- }
292
-
293
- if (isArguments && object.length > 0) {
294
- for (var j = 0; j < object.length; ++j) {
295
- theKeys.push(String(j));
296
- }
297
- } else {
298
- for (var name in object) {
299
- if (!(skipProto && name === 'prototype') && has.call(object, name)) {
300
- theKeys.push(String(name));
301
- }
302
- }
303
- }
304
-
305
- if (hasDontEnumBug) {
306
- var skipConstructor = equalsConstructorPrototypeIfNotBuggy(object);
307
-
308
- for (var k = 0; k < dontEnums.length; ++k) {
309
- if (!(skipConstructor && dontEnums[k] === 'constructor') && has.call(object, dontEnums[k])) {
310
- theKeys.push(dontEnums[k]);
311
- }
312
- }
313
- }
314
- return theKeys;
315
- };
316
- }
317
- implementation$5 = keysShim;
318
- return implementation$5;
319
- }
320
-
321
- var slice$1 = Array.prototype.slice;
322
- var isArgs = isArguments;
323
-
324
- var origKeys = Object.keys;
325
- var keysShim = origKeys ? function keys(o) { return origKeys(o); } : requireImplementation();
326
-
327
- var originalKeys = Object.keys;
328
-
329
- keysShim.shim = function shimObjectKeys() {
330
- if (Object.keys) {
331
- var keysWorksWithArguments = (function () {
332
- // Safari 5.0 bug
333
- var args = Object.keys(arguments);
334
- return args && args.length === arguments.length;
335
- }(1, 2));
336
- if (!keysWorksWithArguments) {
337
- Object.keys = function keys(object) { // eslint-disable-line func-name-matching
338
- if (isArgs(object)) {
339
- return originalKeys(slice$1.call(object));
340
- }
341
- return originalKeys(object);
342
- };
343
- }
344
- } else {
345
- Object.keys = keysShim;
346
- }
347
- return Object.keys || keysShim;
348
- };
349
-
350
- var objectKeys = keysShim;
351
-
352
- /* eslint complexity: [2, 18], max-statements: [2, 33] */
353
- var shams = function hasSymbols() {
354
- if (typeof Symbol !== 'function' || typeof Object.getOwnPropertySymbols !== 'function') { return false; }
355
- if (typeof Symbol.iterator === 'symbol') { return true; }
356
-
357
- var obj = {};
358
- var sym = Symbol('test');
359
- var symObj = Object(sym);
360
- if (typeof sym === 'string') { return false; }
361
-
362
- if (Object.prototype.toString.call(sym) !== '[object Symbol]') { return false; }
363
- if (Object.prototype.toString.call(symObj) !== '[object Symbol]') { return false; }
364
-
365
- // temp disabled per https://github.com/ljharb/object.assign/issues/17
366
- // if (sym instanceof Symbol) { return false; }
367
- // temp disabled per https://github.com/WebReflection/get-own-property-symbols/issues/4
368
- // if (!(symObj instanceof Symbol)) { return false; }
369
-
370
- // if (typeof Symbol.prototype.toString !== 'function') { return false; }
371
- // if (String(sym) !== Symbol.prototype.toString.call(sym)) { return false; }
372
-
373
- var symVal = 42;
374
- obj[sym] = symVal;
375
- for (sym in obj) { return false; } // eslint-disable-line no-restricted-syntax, no-unreachable-loop
376
- if (typeof Object.keys === 'function' && Object.keys(obj).length !== 0) { return false; }
377
-
378
- if (typeof Object.getOwnPropertyNames === 'function' && Object.getOwnPropertyNames(obj).length !== 0) { return false; }
379
-
380
- var syms = Object.getOwnPropertySymbols(obj);
381
- if (syms.length !== 1 || syms[0] !== sym) { return false; }
382
-
383
- if (!Object.prototype.propertyIsEnumerable.call(obj, sym)) { return false; }
384
-
385
- if (typeof Object.getOwnPropertyDescriptor === 'function') {
386
- var descriptor = Object.getOwnPropertyDescriptor(obj, sym);
387
- if (descriptor.value !== symVal || descriptor.enumerable !== true) { return false; }
388
- }
389
-
390
- return true;
391
- };
392
-
393
- var origSymbol = typeof Symbol !== 'undefined' && Symbol;
394
- var hasSymbolSham = shams;
395
-
396
- var hasSymbols$2 = function hasNativeSymbols() {
397
- if (typeof origSymbol !== 'function') { return false; }
398
- if (typeof Symbol !== 'function') { return false; }
399
- if (typeof origSymbol('foo') !== 'symbol') { return false; }
400
- if (typeof Symbol('bar') !== 'symbol') { return false; }
401
-
402
- return hasSymbolSham();
403
- };
404
-
405
- var test = {
406
- foo: {}
407
- };
408
-
409
- var $Object = Object;
410
-
411
- var hasProto$1 = function hasProto() {
412
- return { __proto__: test }.foo === test.foo && !({ __proto__: null } instanceof $Object);
413
- };
414
-
415
- /* eslint no-invalid-this: 1 */
416
-
417
- var ERROR_MESSAGE = 'Function.prototype.bind called on incompatible ';
418
- var slice = Array.prototype.slice;
419
- var toStr$1 = Object.prototype.toString;
420
- var funcType = '[object Function]';
421
-
422
- var implementation$4 = function bind(that) {
423
- var target = this;
424
- if (typeof target !== 'function' || toStr$1.call(target) !== funcType) {
425
- throw new TypeError(ERROR_MESSAGE + target);
426
- }
427
- var args = slice.call(arguments, 1);
428
-
429
- var bound;
430
- var binder = function () {
431
- if (this instanceof bound) {
432
- var result = target.apply(
433
- this,
434
- args.concat(slice.call(arguments))
435
- );
436
- if (Object(result) === result) {
437
- return result;
438
- }
439
- return this;
440
- } else {
441
- return target.apply(
442
- that,
443
- args.concat(slice.call(arguments))
444
- );
445
- }
446
- };
447
-
448
- var boundLength = Math.max(0, target.length - args.length);
449
- var boundArgs = [];
450
- for (var i = 0; i < boundLength; i++) {
451
- boundArgs.push('$' + i);
452
- }
453
-
454
- bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this,arguments); }')(binder);
455
-
456
- if (target.prototype) {
457
- var Empty = function Empty() {};
458
- Empty.prototype = target.prototype;
459
- bound.prototype = new Empty();
460
- Empty.prototype = null;
461
- }
462
-
463
- return bound;
464
- };
465
-
466
- var implementation$3 = implementation$4;
467
-
468
- var functionBind = Function.prototype.bind || implementation$3;
469
-
470
- var bind$1 = functionBind;
471
-
472
- var src = bind$1.call(Function.call, Object.prototype.hasOwnProperty);
473
-
474
- var undefined$1;
475
-
476
- var $SyntaxError = SyntaxError;
477
- var $Function = Function;
478
- var $TypeError = TypeError;
479
-
480
- // eslint-disable-next-line consistent-return
481
- var getEvalledConstructor = function (expressionSyntax) {
482
- try {
483
- return $Function('"use strict"; return (' + expressionSyntax + ').constructor;')();
484
- } catch (e) {}
485
- };
486
-
487
- var $gOPD = Object.getOwnPropertyDescriptor;
488
- if ($gOPD) {
489
- try {
490
- $gOPD({}, '');
491
- } catch (e) {
492
- $gOPD = null; // this is IE 8, which has a broken gOPD
493
- }
494
- }
495
-
496
- var throwTypeError = function () {
497
- throw new $TypeError();
498
- };
499
- var ThrowTypeError = $gOPD
500
- ? (function () {
501
- try {
502
- // eslint-disable-next-line no-unused-expressions, no-caller, no-restricted-properties
503
- arguments.callee; // IE 8 does not throw here
504
- return throwTypeError;
505
- } catch (calleeThrows) {
506
- try {
507
- // IE 8 throws on Object.getOwnPropertyDescriptor(arguments, '')
508
- return $gOPD(arguments, 'callee').get;
509
- } catch (gOPDthrows) {
510
- return throwTypeError;
511
- }
512
- }
513
- }())
514
- : throwTypeError;
515
-
516
- var hasSymbols$1 = hasSymbols$2();
517
- var hasProto = hasProto$1();
518
-
519
- var getProto = Object.getPrototypeOf || (
520
- hasProto
521
- ? function (x) { return x.__proto__; } // eslint-disable-line no-proto
522
- : null
523
- );
524
-
525
- var needsEval = {};
526
-
527
- var TypedArray = typeof Uint8Array === 'undefined' || !getProto ? undefined$1 : getProto(Uint8Array);
528
-
529
- var INTRINSICS = {
530
- '%AggregateError%': typeof AggregateError === 'undefined' ? undefined$1 : AggregateError,
531
- '%Array%': Array,
532
- '%ArrayBuffer%': typeof ArrayBuffer === 'undefined' ? undefined$1 : ArrayBuffer,
533
- '%ArrayIteratorPrototype%': hasSymbols$1 && getProto ? getProto([][Symbol.iterator]()) : undefined$1,
534
- '%AsyncFromSyncIteratorPrototype%': undefined$1,
535
- '%AsyncFunction%': needsEval,
536
- '%AsyncGenerator%': needsEval,
537
- '%AsyncGeneratorFunction%': needsEval,
538
- '%AsyncIteratorPrototype%': needsEval,
539
- '%Atomics%': typeof Atomics === 'undefined' ? undefined$1 : Atomics,
540
- '%BigInt%': typeof BigInt === 'undefined' ? undefined$1 : BigInt,
541
- '%BigInt64Array%': typeof BigInt64Array === 'undefined' ? undefined$1 : BigInt64Array,
542
- '%BigUint64Array%': typeof BigUint64Array === 'undefined' ? undefined$1 : BigUint64Array,
543
- '%Boolean%': Boolean,
544
- '%DataView%': typeof DataView === 'undefined' ? undefined$1 : DataView,
545
- '%Date%': Date,
546
- '%decodeURI%': decodeURI,
547
- '%decodeURIComponent%': decodeURIComponent,
548
- '%encodeURI%': encodeURI,
549
- '%encodeURIComponent%': encodeURIComponent,
550
- '%Error%': Error,
551
- '%eval%': eval, // eslint-disable-line no-eval
552
- '%EvalError%': EvalError,
553
- '%Float32Array%': typeof Float32Array === 'undefined' ? undefined$1 : Float32Array,
554
- '%Float64Array%': typeof Float64Array === 'undefined' ? undefined$1 : Float64Array,
555
- '%FinalizationRegistry%': typeof FinalizationRegistry === 'undefined' ? undefined$1 : FinalizationRegistry,
556
- '%Function%': $Function,
557
- '%GeneratorFunction%': needsEval,
558
- '%Int8Array%': typeof Int8Array === 'undefined' ? undefined$1 : Int8Array,
559
- '%Int16Array%': typeof Int16Array === 'undefined' ? undefined$1 : Int16Array,
560
- '%Int32Array%': typeof Int32Array === 'undefined' ? undefined$1 : Int32Array,
561
- '%isFinite%': isFinite,
562
- '%isNaN%': isNaN,
563
- '%IteratorPrototype%': hasSymbols$1 && getProto ? getProto(getProto([][Symbol.iterator]())) : undefined$1,
564
- '%JSON%': typeof JSON === 'object' ? JSON : undefined$1,
565
- '%Map%': typeof Map === 'undefined' ? undefined$1 : Map,
566
- '%MapIteratorPrototype%': typeof Map === 'undefined' || !hasSymbols$1 || !getProto ? undefined$1 : getProto(new Map()[Symbol.iterator]()),
567
- '%Math%': Math,
568
- '%Number%': Number,
569
- '%Object%': Object,
570
- '%parseFloat%': parseFloat,
571
- '%parseInt%': parseInt,
572
- '%Promise%': typeof Promise === 'undefined' ? undefined$1 : Promise,
573
- '%Proxy%': typeof Proxy === 'undefined' ? undefined$1 : Proxy,
574
- '%RangeError%': RangeError,
575
- '%ReferenceError%': ReferenceError,
576
- '%Reflect%': typeof Reflect === 'undefined' ? undefined$1 : Reflect,
577
- '%RegExp%': RegExp,
578
- '%Set%': typeof Set === 'undefined' ? undefined$1 : Set,
579
- '%SetIteratorPrototype%': typeof Set === 'undefined' || !hasSymbols$1 || !getProto ? undefined$1 : getProto(new Set()[Symbol.iterator]()),
580
- '%SharedArrayBuffer%': typeof SharedArrayBuffer === 'undefined' ? undefined$1 : SharedArrayBuffer,
581
- '%String%': String,
582
- '%StringIteratorPrototype%': hasSymbols$1 && getProto ? getProto(''[Symbol.iterator]()) : undefined$1,
583
- '%Symbol%': hasSymbols$1 ? Symbol : undefined$1,
584
- '%SyntaxError%': $SyntaxError,
585
- '%ThrowTypeError%': ThrowTypeError,
586
- '%TypedArray%': TypedArray,
587
- '%TypeError%': $TypeError,
588
- '%Uint8Array%': typeof Uint8Array === 'undefined' ? undefined$1 : Uint8Array,
589
- '%Uint8ClampedArray%': typeof Uint8ClampedArray === 'undefined' ? undefined$1 : Uint8ClampedArray,
590
- '%Uint16Array%': typeof Uint16Array === 'undefined' ? undefined$1 : Uint16Array,
591
- '%Uint32Array%': typeof Uint32Array === 'undefined' ? undefined$1 : Uint32Array,
592
- '%URIError%': URIError,
593
- '%WeakMap%': typeof WeakMap === 'undefined' ? undefined$1 : WeakMap,
594
- '%WeakRef%': typeof WeakRef === 'undefined' ? undefined$1 : WeakRef,
595
- '%WeakSet%': typeof WeakSet === 'undefined' ? undefined$1 : WeakSet
596
- };
597
-
598
- if (getProto) {
599
- try {
600
- null.error; // eslint-disable-line no-unused-expressions
601
- } catch (e) {
602
- // https://github.com/tc39/proposal-shadowrealm/pull/384#issuecomment-1364264229
603
- var errorProto = getProto(getProto(e));
604
- INTRINSICS['%Error.prototype%'] = errorProto;
605
- }
606
- }
607
-
608
- var doEval = function doEval(name) {
609
- var value;
610
- if (name === '%AsyncFunction%') {
611
- value = getEvalledConstructor('async function () {}');
612
- } else if (name === '%GeneratorFunction%') {
613
- value = getEvalledConstructor('function* () {}');
614
- } else if (name === '%AsyncGeneratorFunction%') {
615
- value = getEvalledConstructor('async function* () {}');
616
- } else if (name === '%AsyncGenerator%') {
617
- var fn = doEval('%AsyncGeneratorFunction%');
618
- if (fn) {
619
- value = fn.prototype;
620
- }
621
- } else if (name === '%AsyncIteratorPrototype%') {
622
- var gen = doEval('%AsyncGenerator%');
623
- if (gen && getProto) {
624
- value = getProto(gen.prototype);
625
- }
626
- }
627
-
628
- INTRINSICS[name] = value;
629
-
630
- return value;
631
- };
632
-
633
- var LEGACY_ALIASES = {
634
- '%ArrayBufferPrototype%': ['ArrayBuffer', 'prototype'],
635
- '%ArrayPrototype%': ['Array', 'prototype'],
636
- '%ArrayProto_entries%': ['Array', 'prototype', 'entries'],
637
- '%ArrayProto_forEach%': ['Array', 'prototype', 'forEach'],
638
- '%ArrayProto_keys%': ['Array', 'prototype', 'keys'],
639
- '%ArrayProto_values%': ['Array', 'prototype', 'values'],
640
- '%AsyncFunctionPrototype%': ['AsyncFunction', 'prototype'],
641
- '%AsyncGenerator%': ['AsyncGeneratorFunction', 'prototype'],
642
- '%AsyncGeneratorPrototype%': ['AsyncGeneratorFunction', 'prototype', 'prototype'],
643
- '%BooleanPrototype%': ['Boolean', 'prototype'],
644
- '%DataViewPrototype%': ['DataView', 'prototype'],
645
- '%DatePrototype%': ['Date', 'prototype'],
646
- '%ErrorPrototype%': ['Error', 'prototype'],
647
- '%EvalErrorPrototype%': ['EvalError', 'prototype'],
648
- '%Float32ArrayPrototype%': ['Float32Array', 'prototype'],
649
- '%Float64ArrayPrototype%': ['Float64Array', 'prototype'],
650
- '%FunctionPrototype%': ['Function', 'prototype'],
651
- '%Generator%': ['GeneratorFunction', 'prototype'],
652
- '%GeneratorPrototype%': ['GeneratorFunction', 'prototype', 'prototype'],
653
- '%Int8ArrayPrototype%': ['Int8Array', 'prototype'],
654
- '%Int16ArrayPrototype%': ['Int16Array', 'prototype'],
655
- '%Int32ArrayPrototype%': ['Int32Array', 'prototype'],
656
- '%JSONParse%': ['JSON', 'parse'],
657
- '%JSONStringify%': ['JSON', 'stringify'],
658
- '%MapPrototype%': ['Map', 'prototype'],
659
- '%NumberPrototype%': ['Number', 'prototype'],
660
- '%ObjectPrototype%': ['Object', 'prototype'],
661
- '%ObjProto_toString%': ['Object', 'prototype', 'toString'],
662
- '%ObjProto_valueOf%': ['Object', 'prototype', 'valueOf'],
663
- '%PromisePrototype%': ['Promise', 'prototype'],
664
- '%PromiseProto_then%': ['Promise', 'prototype', 'then'],
665
- '%Promise_all%': ['Promise', 'all'],
666
- '%Promise_reject%': ['Promise', 'reject'],
667
- '%Promise_resolve%': ['Promise', 'resolve'],
668
- '%RangeErrorPrototype%': ['RangeError', 'prototype'],
669
- '%ReferenceErrorPrototype%': ['ReferenceError', 'prototype'],
670
- '%RegExpPrototype%': ['RegExp', 'prototype'],
671
- '%SetPrototype%': ['Set', 'prototype'],
672
- '%SharedArrayBufferPrototype%': ['SharedArrayBuffer', 'prototype'],
673
- '%StringPrototype%': ['String', 'prototype'],
674
- '%SymbolPrototype%': ['Symbol', 'prototype'],
675
- '%SyntaxErrorPrototype%': ['SyntaxError', 'prototype'],
676
- '%TypedArrayPrototype%': ['TypedArray', 'prototype'],
677
- '%TypeErrorPrototype%': ['TypeError', 'prototype'],
678
- '%Uint8ArrayPrototype%': ['Uint8Array', 'prototype'],
679
- '%Uint8ClampedArrayPrototype%': ['Uint8ClampedArray', 'prototype'],
680
- '%Uint16ArrayPrototype%': ['Uint16Array', 'prototype'],
681
- '%Uint32ArrayPrototype%': ['Uint32Array', 'prototype'],
682
- '%URIErrorPrototype%': ['URIError', 'prototype'],
683
- '%WeakMapPrototype%': ['WeakMap', 'prototype'],
684
- '%WeakSetPrototype%': ['WeakSet', 'prototype']
685
- };
686
-
687
- var bind = functionBind;
688
- var hasOwn = src;
689
- var $concat = bind.call(Function.call, Array.prototype.concat);
690
- var $spliceApply = bind.call(Function.apply, Array.prototype.splice);
691
- var $replace = bind.call(Function.call, String.prototype.replace);
692
- var $strSlice = bind.call(Function.call, String.prototype.slice);
693
- var $exec = bind.call(Function.call, RegExp.prototype.exec);
694
-
695
- /* adapted from https://github.com/lodash/lodash/blob/4.17.15/dist/lodash.js#L6735-L6744 */
696
- var rePropName = /[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g;
697
- var reEscapeChar = /\\(\\)?/g; /** Used to match backslashes in property paths. */
698
- var stringToPath = function stringToPath(string) {
699
- var first = $strSlice(string, 0, 1);
700
- var last = $strSlice(string, -1);
701
- if (first === '%' && last !== '%') {
702
- throw new $SyntaxError('invalid intrinsic syntax, expected closing `%`');
703
- } else if (last === '%' && first !== '%') {
704
- throw new $SyntaxError('invalid intrinsic syntax, expected opening `%`');
705
- }
706
- var result = [];
707
- $replace(string, rePropName, function (match, number, quote, subString) {
708
- result[result.length] = quote ? $replace(subString, reEscapeChar, '$1') : number || match;
709
- });
710
- return result;
711
- };
712
- /* end adaptation */
713
-
714
- var getBaseIntrinsic = function getBaseIntrinsic(name, allowMissing) {
715
- var intrinsicName = name;
716
- var alias;
717
- if (hasOwn(LEGACY_ALIASES, intrinsicName)) {
718
- alias = LEGACY_ALIASES[intrinsicName];
719
- intrinsicName = '%' + alias[0] + '%';
720
- }
721
-
722
- if (hasOwn(INTRINSICS, intrinsicName)) {
723
- var value = INTRINSICS[intrinsicName];
724
- if (value === needsEval) {
725
- value = doEval(intrinsicName);
726
- }
727
- if (typeof value === 'undefined' && !allowMissing) {
728
- throw new $TypeError('intrinsic ' + name + ' exists, but is not available. Please file an issue!');
729
- }
730
-
731
- return {
732
- alias: alias,
733
- name: intrinsicName,
734
- value: value
735
- };
736
- }
737
-
738
- throw new $SyntaxError('intrinsic ' + name + ' does not exist!');
739
- };
740
-
741
- var getIntrinsic = function GetIntrinsic(name, allowMissing) {
742
- if (typeof name !== 'string' || name.length === 0) {
743
- throw new $TypeError('intrinsic name must be a non-empty string');
744
- }
745
- if (arguments.length > 1 && typeof allowMissing !== 'boolean') {
746
- throw new $TypeError('"allowMissing" argument must be a boolean');
747
- }
748
-
749
- if ($exec(/^%?[^%]*%?$/, name) === null) {
750
- throw new $SyntaxError('`%` may not be present anywhere but at the beginning and end of the intrinsic name');
751
- }
752
- var parts = stringToPath(name);
753
- var intrinsicBaseName = parts.length > 0 ? parts[0] : '';
754
-
755
- var intrinsic = getBaseIntrinsic('%' + intrinsicBaseName + '%', allowMissing);
756
- var intrinsicRealName = intrinsic.name;
757
- var value = intrinsic.value;
758
- var skipFurtherCaching = false;
759
-
760
- var alias = intrinsic.alias;
761
- if (alias) {
762
- intrinsicBaseName = alias[0];
763
- $spliceApply(parts, $concat([0, 1], alias));
764
- }
765
-
766
- for (var i = 1, isOwn = true; i < parts.length; i += 1) {
767
- var part = parts[i];
768
- var first = $strSlice(part, 0, 1);
769
- var last = $strSlice(part, -1);
770
- if (
771
- (
772
- (first === '"' || first === "'" || first === '`')
773
- || (last === '"' || last === "'" || last === '`')
774
- )
775
- && first !== last
776
- ) {
777
- throw new $SyntaxError('property names with quotes must have matching quotes');
778
- }
779
- if (part === 'constructor' || !isOwn) {
780
- skipFurtherCaching = true;
781
- }
782
-
783
- intrinsicBaseName += '.' + part;
784
- intrinsicRealName = '%' + intrinsicBaseName + '%';
785
-
786
- if (hasOwn(INTRINSICS, intrinsicRealName)) {
787
- value = INTRINSICS[intrinsicRealName];
788
- } else if (value != null) {
789
- if (!(part in value)) {
790
- if (!allowMissing) {
791
- throw new $TypeError('base intrinsic for ' + name + ' exists, but the property is not available.');
792
- }
793
- return void undefined$1;
794
- }
795
- if ($gOPD && (i + 1) >= parts.length) {
796
- var desc = $gOPD(value, part);
797
- isOwn = !!desc;
798
-
799
- // By convention, when a data property is converted to an accessor
800
- // property to emulate a data property that does not suffer from
801
- // the override mistake, that accessor's getter is marked with
802
- // an `originalValue` property. Here, when we detect this, we
803
- // uphold the illusion by pretending to see that original data
804
- // property, i.e., returning the value rather than the getter
805
- // itself.
806
- if (isOwn && 'get' in desc && !('originalValue' in desc.get)) {
807
- value = desc.get;
808
- } else {
809
- value = value[part];
810
- }
811
- } else {
812
- isOwn = hasOwn(value, part);
813
- value = value[part];
814
- }
815
-
816
- if (isOwn && !skipFurtherCaching) {
817
- INTRINSICS[intrinsicRealName] = value;
818
- }
819
- }
820
- }
821
- return value;
822
- };
823
-
824
- var GetIntrinsic = getIntrinsic;
825
-
826
- var $defineProperty = GetIntrinsic('%Object.defineProperty%', true);
827
-
828
- var hasPropertyDescriptors$1 = function hasPropertyDescriptors() {
829
- if ($defineProperty) {
830
- try {
831
- $defineProperty({}, 'a', { value: 1 });
832
- return true;
833
- } catch (e) {
834
- // IE 8 has a broken defineProperty
835
- return false;
836
- }
837
- }
838
- return false;
839
- };
840
-
841
- hasPropertyDescriptors$1.hasArrayLengthDefineBug = function hasArrayLengthDefineBug() {
842
- // node v0.6 has a bug where array lengths can be Set but not Defined
843
- if (!hasPropertyDescriptors$1()) {
844
- return null;
845
- }
846
- try {
847
- return $defineProperty([], 'length', { value: 1 }).length !== 1;
848
- } catch (e) {
849
- // In Firefox 4-22, defining length on an array throws an exception.
850
- return true;
851
- }
852
- };
853
-
854
- var hasPropertyDescriptors_1 = hasPropertyDescriptors$1;
855
-
856
- var keys = objectKeys;
857
- var hasSymbols = typeof Symbol === 'function' && typeof Symbol('foo') === 'symbol';
858
-
859
- var toStr = Object.prototype.toString;
860
- var concat$2 = Array.prototype.concat;
861
- var origDefineProperty = Object.defineProperty;
862
-
863
- var isFunction = function (fn) {
864
- return typeof fn === 'function' && toStr.call(fn) === '[object Function]';
865
- };
866
-
867
- var hasPropertyDescriptors = hasPropertyDescriptors_1();
868
-
869
- var supportsDescriptors = origDefineProperty && hasPropertyDescriptors;
870
-
871
- var defineProperty = function (object, name, value, predicate) {
872
- if (name in object) {
873
- if (predicate === true) {
874
- if (object[name] === value) {
875
- return;
876
- }
877
- } else if (!isFunction(predicate) || !predicate()) {
878
- return;
879
- }
880
- }
881
- if (supportsDescriptors) {
882
- origDefineProperty(object, name, {
883
- configurable: true,
884
- enumerable: false,
885
- value: value,
886
- writable: true
887
- });
888
- } else {
889
- object[name] = value; // eslint-disable-line no-param-reassign
890
- }
891
- };
892
-
893
- var defineProperties$1 = function (object, map) {
894
- var predicates = arguments.length > 2 ? arguments[2] : {};
895
- var props = keys(map);
896
- if (hasSymbols) {
897
- props = concat$2.call(props, Object.getOwnPropertySymbols(map));
898
- }
899
- for (var i = 0; i < props.length; i += 1) {
900
- defineProperty(object, props[i], map[props[i]], predicates[props[i]]);
901
- }
902
- };
903
-
904
- defineProperties$1.supportsDescriptors = !!supportsDescriptors;
905
-
906
- var defineProperties_1 = defineProperties$1;
907
-
908
- var implementation$2 = commonjsGlobal;
909
-
910
- var implementation$1 = implementation$2;
911
-
912
- var polyfill$1 = function getPolyfill() {
913
- if (typeof commonjsGlobal !== 'object' || !commonjsGlobal || commonjsGlobal.Math !== Math || commonjsGlobal.Array !== Array) {
914
- return implementation$1;
915
- }
916
- return commonjsGlobal;
917
- };
918
-
919
- var define = defineProperties_1;
920
- var getPolyfill$1 = polyfill$1;
921
-
922
- var shim$1 = function shimGlobal() {
923
- var polyfill = getPolyfill$1();
924
- if (define.supportsDescriptors) {
925
- var descriptor = Object.getOwnPropertyDescriptor(polyfill, 'globalThis');
926
- if (!descriptor || (descriptor.configurable && (descriptor.enumerable || !descriptor.writable || globalThis !== polyfill))) { // eslint-disable-line max-len
927
- Object.defineProperty(polyfill, 'globalThis', {
928
- configurable: true,
929
- enumerable: false,
930
- value: polyfill,
931
- writable: true
932
- });
933
- }
934
- } else if (typeof globalThis !== 'object' || globalThis !== polyfill) {
935
- polyfill.globalThis = polyfill;
936
- }
937
- return polyfill;
938
- };
939
-
940
- var defineProperties = defineProperties_1;
941
-
942
- var implementation = implementation$2;
943
- var getPolyfill = polyfill$1;
944
- var shim = shim$1;
945
-
946
- var polyfill = getPolyfill();
947
-
948
- var getGlobal = function () { return polyfill; };
949
-
950
- defineProperties(getGlobal, {
951
- getPolyfill: getPolyfill,
952
- implementation: implementation,
953
- shim: shim
954
- });
955
-
956
- var globalthis = getGlobal;
957
-
958
- var __extends = (commonjsGlobal && commonjsGlobal.__extends) || (function () {
959
- var extendStatics = function (d, b) {
960
- extendStatics = Object.setPrototypeOf ||
961
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
962
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
963
- return extendStatics(d, b);
964
- };
965
- return function (d, b) {
966
- extendStatics(d, b);
967
- function __() { this.constructor = d; }
968
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
969
- };
970
- })();
971
- Object.defineProperty(xstream, "__esModule", { value: true });
972
- xstream.NO_IL = xstream.NO = xstream.MemoryStream = xstream.Stream = void 0;
973
- var ponyfill_1 = ponyfill;
974
- var globalthis_1 = globalthis;
975
- var $$observable = ponyfill_1.default(globalthis_1.getPolyfill());
976
- var NO = {};
977
- xstream.NO = NO;
978
- function noop() { }
979
- function cp(a) {
980
- var l = a.length;
981
- var b = Array(l);
982
- for (var i = 0; i < l; ++i)
983
- b[i] = a[i];
984
- return b;
985
- }
986
- function and(f1, f2) {
987
- return function andFn(t) {
988
- return f1(t) && f2(t);
989
- };
990
- }
991
- function _try(c, t, u) {
992
- try {
993
- return c.f(t);
994
- }
995
- catch (e) {
996
- u._e(e);
997
- return NO;
998
- }
999
- }
1000
- var NO_IL = {
1001
- _n: noop,
1002
- _e: noop,
1003
- _c: noop,
1004
- };
1005
- xstream.NO_IL = NO_IL;
1006
- // mutates the input
1007
- function internalizeProducer(producer) {
1008
- producer._start = function _start(il) {
1009
- il.next = il._n;
1010
- il.error = il._e;
1011
- il.complete = il._c;
1012
- this.start(il);
1013
- };
1014
- producer._stop = producer.stop;
1015
- }
1016
- var StreamSub = /** @class */ (function () {
1017
- function StreamSub(_stream, _listener) {
1018
- this._stream = _stream;
1019
- this._listener = _listener;
1020
- }
1021
- StreamSub.prototype.unsubscribe = function () {
1022
- this._stream._remove(this._listener);
1023
- };
1024
- return StreamSub;
1025
- }());
1026
- var Observer = /** @class */ (function () {
1027
- function Observer(_listener) {
1028
- this._listener = _listener;
1029
- }
1030
- Observer.prototype.next = function (value) {
1031
- this._listener._n(value);
1032
- };
1033
- Observer.prototype.error = function (err) {
1034
- this._listener._e(err);
1035
- };
1036
- Observer.prototype.complete = function () {
1037
- this._listener._c();
1038
- };
1039
- return Observer;
1040
- }());
1041
- var FromObservable = /** @class */ (function () {
1042
- function FromObservable(observable) {
1043
- this.type = 'fromObservable';
1044
- this.ins = observable;
1045
- this.active = false;
1046
- }
1047
- FromObservable.prototype._start = function (out) {
1048
- this.out = out;
1049
- this.active = true;
1050
- this._sub = this.ins.subscribe(new Observer(out));
1051
- if (!this.active)
1052
- this._sub.unsubscribe();
1053
- };
1054
- FromObservable.prototype._stop = function () {
1055
- if (this._sub)
1056
- this._sub.unsubscribe();
1057
- this.active = false;
1058
- };
1059
- return FromObservable;
1060
- }());
1061
- var Merge = /** @class */ (function () {
1062
- function Merge(insArr) {
1063
- this.type = 'merge';
1064
- this.insArr = insArr;
1065
- this.out = NO;
1066
- this.ac = 0;
1067
- }
1068
- Merge.prototype._start = function (out) {
1069
- this.out = out;
1070
- var s = this.insArr;
1071
- var L = s.length;
1072
- this.ac = L;
1073
- for (var i = 0; i < L; i++)
1074
- s[i]._add(this);
1075
- };
1076
- Merge.prototype._stop = function () {
1077
- var s = this.insArr;
1078
- var L = s.length;
1079
- for (var i = 0; i < L; i++)
1080
- s[i]._remove(this);
1081
- this.out = NO;
1082
- };
1083
- Merge.prototype._n = function (t) {
1084
- var u = this.out;
1085
- if (u === NO)
1086
- return;
1087
- u._n(t);
1088
- };
1089
- Merge.prototype._e = function (err) {
1090
- var u = this.out;
1091
- if (u === NO)
1092
- return;
1093
- u._e(err);
1094
- };
1095
- Merge.prototype._c = function () {
1096
- if (--this.ac <= 0) {
1097
- var u = this.out;
1098
- if (u === NO)
1099
- return;
1100
- u._c();
1101
- }
1102
- };
1103
- return Merge;
1104
- }());
1105
- var CombineListener = /** @class */ (function () {
1106
- function CombineListener(i, out, p) {
1107
- this.i = i;
1108
- this.out = out;
1109
- this.p = p;
1110
- p.ils.push(this);
1111
- }
1112
- CombineListener.prototype._n = function (t) {
1113
- var p = this.p, out = this.out;
1114
- if (out === NO)
1115
- return;
1116
- if (p.up(t, this.i)) {
1117
- var b = cp(p.vals);
1118
- out._n(b);
1119
- }
1120
- };
1121
- CombineListener.prototype._e = function (err) {
1122
- var out = this.out;
1123
- if (out === NO)
1124
- return;
1125
- out._e(err);
1126
- };
1127
- CombineListener.prototype._c = function () {
1128
- var p = this.p;
1129
- if (p.out === NO)
1130
- return;
1131
- if (--p.Nc === 0)
1132
- p.out._c();
1133
- };
1134
- return CombineListener;
1135
- }());
1136
- var Combine = /** @class */ (function () {
1137
- function Combine(insArr) {
1138
- this.type = 'combine';
1139
- this.insArr = insArr;
1140
- this.out = NO;
1141
- this.ils = [];
1142
- this.Nc = this.Nn = 0;
1143
- this.vals = [];
1144
- }
1145
- Combine.prototype.up = function (t, i) {
1146
- var v = this.vals[i];
1147
- var Nn = !this.Nn ? 0 : v === NO ? --this.Nn : this.Nn;
1148
- this.vals[i] = t;
1149
- return Nn === 0;
1150
- };
1151
- Combine.prototype._start = function (out) {
1152
- this.out = out;
1153
- var s = this.insArr;
1154
- var n = this.Nc = this.Nn = s.length;
1155
- var vals = this.vals = new Array(n);
1156
- if (n === 0) {
1157
- out._n([]);
1158
- out._c();
1159
- }
1160
- else {
1161
- for (var i = 0; i < n; i++) {
1162
- vals[i] = NO;
1163
- s[i]._add(new CombineListener(i, out, this));
1164
- }
1165
- }
1166
- };
1167
- Combine.prototype._stop = function () {
1168
- var s = this.insArr;
1169
- var n = s.length;
1170
- var ils = this.ils;
1171
- for (var i = 0; i < n; i++)
1172
- s[i]._remove(ils[i]);
1173
- this.out = NO;
1174
- this.ils = [];
1175
- this.vals = [];
1176
- };
1177
- return Combine;
1178
- }());
1179
- var FromArray = /** @class */ (function () {
1180
- function FromArray(a) {
1181
- this.type = 'fromArray';
1182
- this.a = a;
1183
- }
1184
- FromArray.prototype._start = function (out) {
1185
- var a = this.a;
1186
- for (var i = 0, n = a.length; i < n; i++)
1187
- out._n(a[i]);
1188
- out._c();
1189
- };
1190
- FromArray.prototype._stop = function () {
1191
- };
1192
- return FromArray;
1193
- }());
1194
- var FromPromise = /** @class */ (function () {
1195
- function FromPromise(p) {
1196
- this.type = 'fromPromise';
1197
- this.on = false;
1198
- this.p = p;
1199
- }
1200
- FromPromise.prototype._start = function (out) {
1201
- var prod = this;
1202
- this.on = true;
1203
- this.p.then(function (v) {
1204
- if (prod.on) {
1205
- out._n(v);
1206
- out._c();
1207
- }
1208
- }, function (e) {
1209
- out._e(e);
1210
- }).then(noop, function (err) {
1211
- setTimeout(function () { throw err; });
1212
- });
1213
- };
1214
- FromPromise.prototype._stop = function () {
1215
- this.on = false;
1216
- };
1217
- return FromPromise;
1218
- }());
1219
- var Periodic = /** @class */ (function () {
1220
- function Periodic(period) {
1221
- this.type = 'periodic';
1222
- this.period = period;
1223
- this.intervalID = -1;
1224
- this.i = 0;
1225
- }
1226
- Periodic.prototype._start = function (out) {
1227
- var self = this;
1228
- function intervalHandler() { out._n(self.i++); }
1229
- this.intervalID = setInterval(intervalHandler, this.period);
1230
- };
1231
- Periodic.prototype._stop = function () {
1232
- if (this.intervalID !== -1)
1233
- clearInterval(this.intervalID);
1234
- this.intervalID = -1;
1235
- this.i = 0;
1236
- };
1237
- return Periodic;
1238
- }());
1239
- var Debug = /** @class */ (function () {
1240
- function Debug(ins, arg) {
1241
- this.type = 'debug';
1242
- this.ins = ins;
1243
- this.out = NO;
1244
- this.s = noop;
1245
- this.l = '';
1246
- if (typeof arg === 'string')
1247
- this.l = arg;
1248
- else if (typeof arg === 'function')
1249
- this.s = arg;
1250
- }
1251
- Debug.prototype._start = function (out) {
1252
- this.out = out;
1253
- this.ins._add(this);
1254
- };
1255
- Debug.prototype._stop = function () {
1256
- this.ins._remove(this);
1257
- this.out = NO;
1258
- };
1259
- Debug.prototype._n = function (t) {
1260
- var u = this.out;
1261
- if (u === NO)
1262
- return;
1263
- var s = this.s, l = this.l;
1264
- if (s !== noop) {
1265
- try {
1266
- s(t);
1267
- }
1268
- catch (e) {
1269
- u._e(e);
1270
- }
1271
- }
1272
- else if (l)
1273
- console.log(l + ':', t);
1274
- else
1275
- console.log(t);
1276
- u._n(t);
1277
- };
1278
- Debug.prototype._e = function (err) {
1279
- var u = this.out;
1280
- if (u === NO)
1281
- return;
1282
- u._e(err);
1283
- };
1284
- Debug.prototype._c = function () {
1285
- var u = this.out;
1286
- if (u === NO)
1287
- return;
1288
- u._c();
1289
- };
1290
- return Debug;
1291
- }());
1292
- var Drop = /** @class */ (function () {
1293
- function Drop(max, ins) {
1294
- this.type = 'drop';
1295
- this.ins = ins;
1296
- this.out = NO;
1297
- this.max = max;
1298
- this.dropped = 0;
1299
- }
1300
- Drop.prototype._start = function (out) {
1301
- this.out = out;
1302
- this.dropped = 0;
1303
- this.ins._add(this);
1304
- };
1305
- Drop.prototype._stop = function () {
1306
- this.ins._remove(this);
1307
- this.out = NO;
1308
- };
1309
- Drop.prototype._n = function (t) {
1310
- var u = this.out;
1311
- if (u === NO)
1312
- return;
1313
- if (this.dropped++ >= this.max)
1314
- u._n(t);
1315
- };
1316
- Drop.prototype._e = function (err) {
1317
- var u = this.out;
1318
- if (u === NO)
1319
- return;
1320
- u._e(err);
1321
- };
1322
- Drop.prototype._c = function () {
1323
- var u = this.out;
1324
- if (u === NO)
1325
- return;
1326
- u._c();
1327
- };
1328
- return Drop;
1329
- }());
1330
- var EndWhenListener = /** @class */ (function () {
1331
- function EndWhenListener(out, op) {
1332
- this.out = out;
1333
- this.op = op;
1334
- }
1335
- EndWhenListener.prototype._n = function () {
1336
- this.op.end();
1337
- };
1338
- EndWhenListener.prototype._e = function (err) {
1339
- this.out._e(err);
1340
- };
1341
- EndWhenListener.prototype._c = function () {
1342
- this.op.end();
1343
- };
1344
- return EndWhenListener;
1345
- }());
1346
- var EndWhen = /** @class */ (function () {
1347
- function EndWhen(o, ins) {
1348
- this.type = 'endWhen';
1349
- this.ins = ins;
1350
- this.out = NO;
1351
- this.o = o;
1352
- this.oil = NO_IL;
1353
- }
1354
- EndWhen.prototype._start = function (out) {
1355
- this.out = out;
1356
- this.o._add(this.oil = new EndWhenListener(out, this));
1357
- this.ins._add(this);
1358
- };
1359
- EndWhen.prototype._stop = function () {
1360
- this.ins._remove(this);
1361
- this.o._remove(this.oil);
1362
- this.out = NO;
1363
- this.oil = NO_IL;
1364
- };
1365
- EndWhen.prototype.end = function () {
1366
- var u = this.out;
1367
- if (u === NO)
1368
- return;
1369
- u._c();
1370
- };
1371
- EndWhen.prototype._n = function (t) {
1372
- var u = this.out;
1373
- if (u === NO)
1374
- return;
1375
- u._n(t);
1376
- };
1377
- EndWhen.prototype._e = function (err) {
1378
- var u = this.out;
1379
- if (u === NO)
1380
- return;
1381
- u._e(err);
1382
- };
1383
- EndWhen.prototype._c = function () {
1384
- this.end();
1385
- };
1386
- return EndWhen;
1387
- }());
1388
- var Filter = /** @class */ (function () {
1389
- function Filter(passes, ins) {
1390
- this.type = 'filter';
1391
- this.ins = ins;
1392
- this.out = NO;
1393
- this.f = passes;
1394
- }
1395
- Filter.prototype._start = function (out) {
1396
- this.out = out;
1397
- this.ins._add(this);
1398
- };
1399
- Filter.prototype._stop = function () {
1400
- this.ins._remove(this);
1401
- this.out = NO;
1402
- };
1403
- Filter.prototype._n = function (t) {
1404
- var u = this.out;
1405
- if (u === NO)
1406
- return;
1407
- var r = _try(this, t, u);
1408
- if (r === NO || !r)
1409
- return;
1410
- u._n(t);
1411
- };
1412
- Filter.prototype._e = function (err) {
1413
- var u = this.out;
1414
- if (u === NO)
1415
- return;
1416
- u._e(err);
1417
- };
1418
- Filter.prototype._c = function () {
1419
- var u = this.out;
1420
- if (u === NO)
1421
- return;
1422
- u._c();
1423
- };
1424
- return Filter;
1425
- }());
1426
- var FlattenListener = /** @class */ (function () {
1427
- function FlattenListener(out, op) {
1428
- this.out = out;
1429
- this.op = op;
1430
- }
1431
- FlattenListener.prototype._n = function (t) {
1432
- this.out._n(t);
1433
- };
1434
- FlattenListener.prototype._e = function (err) {
1435
- this.out._e(err);
1436
- };
1437
- FlattenListener.prototype._c = function () {
1438
- this.op.inner = NO;
1439
- this.op.less();
1440
- };
1441
- return FlattenListener;
1442
- }());
1443
- var Flatten = /** @class */ (function () {
1444
- function Flatten(ins) {
1445
- this.type = 'flatten';
1446
- this.ins = ins;
1447
- this.out = NO;
1448
- this.open = true;
1449
- this.inner = NO;
1450
- this.il = NO_IL;
1451
- }
1452
- Flatten.prototype._start = function (out) {
1453
- this.out = out;
1454
- this.open = true;
1455
- this.inner = NO;
1456
- this.il = NO_IL;
1457
- this.ins._add(this);
1458
- };
1459
- Flatten.prototype._stop = function () {
1460
- this.ins._remove(this);
1461
- if (this.inner !== NO)
1462
- this.inner._remove(this.il);
1463
- this.out = NO;
1464
- this.open = true;
1465
- this.inner = NO;
1466
- this.il = NO_IL;
1467
- };
1468
- Flatten.prototype.less = function () {
1469
- var u = this.out;
1470
- if (u === NO)
1471
- return;
1472
- if (!this.open && this.inner === NO)
1473
- u._c();
1474
- };
1475
- Flatten.prototype._n = function (s) {
1476
- var u = this.out;
1477
- if (u === NO)
1478
- return;
1479
- var _a = this, inner = _a.inner, il = _a.il;
1480
- if (inner !== NO && il !== NO_IL)
1481
- inner._remove(il);
1482
- (this.inner = s)._add(this.il = new FlattenListener(u, this));
1483
- };
1484
- Flatten.prototype._e = function (err) {
1485
- var u = this.out;
1486
- if (u === NO)
1487
- return;
1488
- u._e(err);
1489
- };
1490
- Flatten.prototype._c = function () {
1491
- this.open = false;
1492
- this.less();
1493
- };
1494
- return Flatten;
1495
- }());
1496
- var Fold = /** @class */ (function () {
1497
- function Fold(f, seed, ins) {
1498
- var _this = this;
1499
- this.type = 'fold';
1500
- this.ins = ins;
1501
- this.out = NO;
1502
- this.f = function (t) { return f(_this.acc, t); };
1503
- this.acc = this.seed = seed;
1504
- }
1505
- Fold.prototype._start = function (out) {
1506
- this.out = out;
1507
- this.acc = this.seed;
1508
- out._n(this.acc);
1509
- this.ins._add(this);
1510
- };
1511
- Fold.prototype._stop = function () {
1512
- this.ins._remove(this);
1513
- this.out = NO;
1514
- this.acc = this.seed;
1515
- };
1516
- Fold.prototype._n = function (t) {
1517
- var u = this.out;
1518
- if (u === NO)
1519
- return;
1520
- var r = _try(this, t, u);
1521
- if (r === NO)
1522
- return;
1523
- u._n(this.acc = r);
1524
- };
1525
- Fold.prototype._e = function (err) {
1526
- var u = this.out;
1527
- if (u === NO)
1528
- return;
1529
- u._e(err);
1530
- };
1531
- Fold.prototype._c = function () {
1532
- var u = this.out;
1533
- if (u === NO)
1534
- return;
1535
- u._c();
1536
- };
1537
- return Fold;
1538
- }());
1539
- var Last = /** @class */ (function () {
1540
- function Last(ins) {
1541
- this.type = 'last';
1542
- this.ins = ins;
1543
- this.out = NO;
1544
- this.has = false;
1545
- this.val = NO;
1546
- }
1547
- Last.prototype._start = function (out) {
1548
- this.out = out;
1549
- this.has = false;
1550
- this.ins._add(this);
1551
- };
1552
- Last.prototype._stop = function () {
1553
- this.ins._remove(this);
1554
- this.out = NO;
1555
- this.val = NO;
1556
- };
1557
- Last.prototype._n = function (t) {
1558
- this.has = true;
1559
- this.val = t;
1560
- };
1561
- Last.prototype._e = function (err) {
1562
- var u = this.out;
1563
- if (u === NO)
1564
- return;
1565
- u._e(err);
1566
- };
1567
- Last.prototype._c = function () {
1568
- var u = this.out;
1569
- if (u === NO)
1570
- return;
1571
- if (this.has) {
1572
- u._n(this.val);
1573
- u._c();
1574
- }
1575
- else
1576
- u._e(new Error('last() failed because input stream completed'));
1577
- };
1578
- return Last;
1579
- }());
1580
- var MapOp = /** @class */ (function () {
1581
- function MapOp(project, ins) {
1582
- this.type = 'map';
1583
- this.ins = ins;
1584
- this.out = NO;
1585
- this.f = project;
1586
- }
1587
- MapOp.prototype._start = function (out) {
1588
- this.out = out;
1589
- this.ins._add(this);
1590
- };
1591
- MapOp.prototype._stop = function () {
1592
- this.ins._remove(this);
1593
- this.out = NO;
1594
- };
1595
- MapOp.prototype._n = function (t) {
1596
- var u = this.out;
1597
- if (u === NO)
1598
- return;
1599
- var r = _try(this, t, u);
1600
- if (r === NO)
1601
- return;
1602
- u._n(r);
1603
- };
1604
- MapOp.prototype._e = function (err) {
1605
- var u = this.out;
1606
- if (u === NO)
1607
- return;
1608
- u._e(err);
1609
- };
1610
- MapOp.prototype._c = function () {
1611
- var u = this.out;
1612
- if (u === NO)
1613
- return;
1614
- u._c();
1615
- };
1616
- return MapOp;
1617
- }());
1618
- var Remember = /** @class */ (function () {
1619
- function Remember(ins) {
1620
- this.type = 'remember';
1621
- this.ins = ins;
1622
- this.out = NO;
1623
- }
1624
- Remember.prototype._start = function (out) {
1625
- this.out = out;
1626
- this.ins._add(out);
1627
- };
1628
- Remember.prototype._stop = function () {
1629
- this.ins._remove(this.out);
1630
- this.out = NO;
1631
- };
1632
- return Remember;
1633
- }());
1634
- var ReplaceError = /** @class */ (function () {
1635
- function ReplaceError(replacer, ins) {
1636
- this.type = 'replaceError';
1637
- this.ins = ins;
1638
- this.out = NO;
1639
- this.f = replacer;
1640
- }
1641
- ReplaceError.prototype._start = function (out) {
1642
- this.out = out;
1643
- this.ins._add(this);
1644
- };
1645
- ReplaceError.prototype._stop = function () {
1646
- this.ins._remove(this);
1647
- this.out = NO;
1648
- };
1649
- ReplaceError.prototype._n = function (t) {
1650
- var u = this.out;
1651
- if (u === NO)
1652
- return;
1653
- u._n(t);
1654
- };
1655
- ReplaceError.prototype._e = function (err) {
1656
- var u = this.out;
1657
- if (u === NO)
1658
- return;
1659
- try {
1660
- this.ins._remove(this);
1661
- (this.ins = this.f(err))._add(this);
1662
- }
1663
- catch (e) {
1664
- u._e(e);
1665
- }
1666
- };
1667
- ReplaceError.prototype._c = function () {
1668
- var u = this.out;
1669
- if (u === NO)
1670
- return;
1671
- u._c();
1672
- };
1673
- return ReplaceError;
1674
- }());
1675
- var StartWith = /** @class */ (function () {
1676
- function StartWith(ins, val) {
1677
- this.type = 'startWith';
1678
- this.ins = ins;
1679
- this.out = NO;
1680
- this.val = val;
1681
- }
1682
- StartWith.prototype._start = function (out) {
1683
- this.out = out;
1684
- this.out._n(this.val);
1685
- this.ins._add(out);
1686
- };
1687
- StartWith.prototype._stop = function () {
1688
- this.ins._remove(this.out);
1689
- this.out = NO;
1690
- };
1691
- return StartWith;
1692
- }());
1693
- var Take = /** @class */ (function () {
1694
- function Take(max, ins) {
1695
- this.type = 'take';
1696
- this.ins = ins;
1697
- this.out = NO;
1698
- this.max = max;
1699
- this.taken = 0;
1700
- }
1701
- Take.prototype._start = function (out) {
1702
- this.out = out;
1703
- this.taken = 0;
1704
- if (this.max <= 0)
1705
- out._c();
1706
- else
1707
- this.ins._add(this);
1708
- };
1709
- Take.prototype._stop = function () {
1710
- this.ins._remove(this);
1711
- this.out = NO;
1712
- };
1713
- Take.prototype._n = function (t) {
1714
- var u = this.out;
1715
- if (u === NO)
1716
- return;
1717
- var m = ++this.taken;
1718
- if (m < this.max)
1719
- u._n(t);
1720
- else if (m === this.max) {
1721
- u._n(t);
1722
- u._c();
1723
- }
1724
- };
1725
- Take.prototype._e = function (err) {
1726
- var u = this.out;
1727
- if (u === NO)
1728
- return;
1729
- u._e(err);
1730
- };
1731
- Take.prototype._c = function () {
1732
- var u = this.out;
1733
- if (u === NO)
1734
- return;
1735
- u._c();
1736
- };
1737
- return Take;
1738
- }());
1739
- var Stream = /** @class */ (function () {
1740
- function Stream(producer) {
1741
- this._prod = producer || NO;
1742
- this._ils = [];
1743
- this._stopID = NO;
1744
- this._dl = NO;
1745
- this._d = false;
1746
- this._target = null;
1747
- this._err = NO;
1748
- }
1749
- Stream.prototype._n = function (t) {
1750
- var a = this._ils;
1751
- var L = a.length;
1752
- if (this._d)
1753
- this._dl._n(t);
1754
- if (L == 1)
1755
- a[0]._n(t);
1756
- else if (L == 0)
1757
- return;
1758
- else {
1759
- var b = cp(a);
1760
- for (var i = 0; i < L; i++)
1761
- b[i]._n(t);
1762
- }
1763
- };
1764
- Stream.prototype._e = function (err) {
1765
- if (this._err !== NO)
1766
- return;
1767
- this._err = err;
1768
- var a = this._ils;
1769
- var L = a.length;
1770
- this._x();
1771
- if (this._d)
1772
- this._dl._e(err);
1773
- if (L == 1)
1774
- a[0]._e(err);
1775
- else if (L == 0)
1776
- return;
1777
- else {
1778
- var b = cp(a);
1779
- for (var i = 0; i < L; i++)
1780
- b[i]._e(err);
1781
- }
1782
- if (!this._d && L == 0)
1783
- throw this._err;
1784
- };
1785
- Stream.prototype._c = function () {
1786
- var a = this._ils;
1787
- var L = a.length;
1788
- this._x();
1789
- if (this._d)
1790
- this._dl._c();
1791
- if (L == 1)
1792
- a[0]._c();
1793
- else if (L == 0)
1794
- return;
1795
- else {
1796
- var b = cp(a);
1797
- for (var i = 0; i < L; i++)
1798
- b[i]._c();
1799
- }
1800
- };
1801
- Stream.prototype._x = function () {
1802
- if (this._ils.length === 0)
1803
- return;
1804
- if (this._prod !== NO)
1805
- this._prod._stop();
1806
- this._err = NO;
1807
- this._ils = [];
1808
- };
1809
- Stream.prototype._stopNow = function () {
1810
- // WARNING: code that calls this method should
1811
- // first check if this._prod is valid (not `NO`)
1812
- this._prod._stop();
1813
- this._err = NO;
1814
- this._stopID = NO;
1815
- };
1816
- Stream.prototype._add = function (il) {
1817
- var ta = this._target;
1818
- if (ta)
1819
- return ta._add(il);
1820
- var a = this._ils;
1821
- a.push(il);
1822
- if (a.length > 1)
1823
- return;
1824
- if (this._stopID !== NO) {
1825
- clearTimeout(this._stopID);
1826
- this._stopID = NO;
1827
- }
1828
- else {
1829
- var p = this._prod;
1830
- if (p !== NO)
1831
- p._start(this);
1832
- }
1833
- };
1834
- Stream.prototype._remove = function (il) {
1835
- var _this = this;
1836
- var ta = this._target;
1837
- if (ta)
1838
- return ta._remove(il);
1839
- var a = this._ils;
1840
- var i = a.indexOf(il);
1841
- if (i > -1) {
1842
- a.splice(i, 1);
1843
- if (this._prod !== NO && a.length <= 0) {
1844
- this._err = NO;
1845
- this._stopID = setTimeout(function () { return _this._stopNow(); });
1846
- }
1847
- else if (a.length === 1) {
1848
- this._pruneCycles();
1849
- }
1850
- }
1851
- };
1852
- // If all paths stemming from `this` stream eventually end at `this`
1853
- // stream, then we remove the single listener of `this` stream, to
1854
- // force it to end its execution and dispose resources. This method
1855
- // assumes as a precondition that this._ils has just one listener.
1856
- Stream.prototype._pruneCycles = function () {
1857
- if (this._hasNoSinks(this, []))
1858
- this._remove(this._ils[0]);
1859
- };
1860
- // Checks whether *there is no* path starting from `x` that leads to an end
1861
- // listener (sink) in the stream graph, following edges A->B where B is a
1862
- // listener of A. This means these paths constitute a cycle somehow. Is given
1863
- // a trace of all visited nodes so far.
1864
- Stream.prototype._hasNoSinks = function (x, trace) {
1865
- if (trace.indexOf(x) !== -1)
1866
- return true;
1867
- else if (x.out === this)
1868
- return true;
1869
- else if (x.out && x.out !== NO)
1870
- return this._hasNoSinks(x.out, trace.concat(x));
1871
- else if (x._ils) {
1872
- for (var i = 0, N = x._ils.length; i < N; i++)
1873
- if (!this._hasNoSinks(x._ils[i], trace.concat(x)))
1874
- return false;
1875
- return true;
1876
- }
1877
- else
1878
- return false;
1879
- };
1880
- Stream.prototype.ctor = function () {
1881
- return this instanceof MemoryStream ? MemoryStream : Stream;
1882
- };
1883
- /**
1884
- * Adds a Listener to the Stream.
1885
- *
1886
- * @param {Listener} listener
1887
- */
1888
- Stream.prototype.addListener = function (listener) {
1889
- listener._n = listener.next || noop;
1890
- listener._e = listener.error || noop;
1891
- listener._c = listener.complete || noop;
1892
- this._add(listener);
1893
- };
1894
- /**
1895
- * Removes a Listener from the Stream, assuming the Listener was added to it.
1896
- *
1897
- * @param {Listener<T>} listener
1898
- */
1899
- Stream.prototype.removeListener = function (listener) {
1900
- this._remove(listener);
1901
- };
1902
- /**
1903
- * Adds a Listener to the Stream returning a Subscription to remove that
1904
- * listener.
1905
- *
1906
- * @param {Listener} listener
1907
- * @returns {Subscription}
1908
- */
1909
- Stream.prototype.subscribe = function (listener) {
1910
- this.addListener(listener);
1911
- return new StreamSub(this, listener);
1912
- };
1913
- /**
1914
- * Add interop between most.js and RxJS 5
1915
- *
1916
- * @returns {Stream}
1917
- */
1918
- Stream.prototype[$$observable] = function () {
1919
- return this;
1920
- };
1921
- /**
1922
- * Creates a new Stream given a Producer.
1923
- *
1924
- * @factory true
1925
- * @param {Producer} producer An optional Producer that dictates how to
1926
- * start, generate events, and stop the Stream.
1927
- * @return {Stream}
1928
- */
1929
- Stream.create = function (producer) {
1930
- if (producer) {
1931
- if (typeof producer.start !== 'function'
1932
- || typeof producer.stop !== 'function')
1933
- throw new Error('producer requires both start and stop functions');
1934
- internalizeProducer(producer); // mutates the input
1935
- }
1936
- return new Stream(producer);
1937
- };
1938
- /**
1939
- * Creates a new MemoryStream given a Producer.
1940
- *
1941
- * @factory true
1942
- * @param {Producer} producer An optional Producer that dictates how to
1943
- * start, generate events, and stop the Stream.
1944
- * @return {MemoryStream}
1945
- */
1946
- Stream.createWithMemory = function (producer) {
1947
- if (producer)
1948
- internalizeProducer(producer); // mutates the input
1949
- return new MemoryStream(producer);
1950
- };
1951
- /**
1952
- * Creates a Stream that does nothing when started. It never emits any event.
1953
- *
1954
- * Marble diagram:
1955
- *
1956
- * ```text
1957
- * never
1958
- * -----------------------
1959
- * ```
1960
- *
1961
- * @factory true
1962
- * @return {Stream}
1963
- */
1964
- Stream.never = function () {
1965
- return new Stream({ _start: noop, _stop: noop });
1966
- };
1967
- /**
1968
- * Creates a Stream that immediately emits the "complete" notification when
1969
- * started, and that's it.
1970
- *
1971
- * Marble diagram:
1972
- *
1973
- * ```text
1974
- * empty
1975
- * -|
1976
- * ```
1977
- *
1978
- * @factory true
1979
- * @return {Stream}
1980
- */
1981
- Stream.empty = function () {
1982
- return new Stream({
1983
- _start: function (il) { il._c(); },
1984
- _stop: noop,
1985
- });
1986
- };
1987
- /**
1988
- * Creates a Stream that immediately emits an "error" notification with the
1989
- * value you passed as the `error` argument when the stream starts, and that's
1990
- * it.
1991
- *
1992
- * Marble diagram:
1993
- *
1994
- * ```text
1995
- * throw(X)
1996
- * -X
1997
- * ```
1998
- *
1999
- * @factory true
2000
- * @param error The error event to emit on the created stream.
2001
- * @return {Stream}
2002
- */
2003
- Stream.throw = function (error) {
2004
- return new Stream({
2005
- _start: function (il) { il._e(error); },
2006
- _stop: noop,
2007
- });
2008
- };
2009
- /**
2010
- * Creates a stream from an Array, Promise, or an Observable.
2011
- *
2012
- * @factory true
2013
- * @param {Array|PromiseLike|Observable} input The input to make a stream from.
2014
- * @return {Stream}
2015
- */
2016
- Stream.from = function (input) {
2017
- if (typeof input[$$observable] === 'function')
2018
- return Stream.fromObservable(input);
2019
- else if (typeof input.then === 'function')
2020
- return Stream.fromPromise(input);
2021
- else if (Array.isArray(input))
2022
- return Stream.fromArray(input);
2023
- throw new TypeError("Type of input to from() must be an Array, Promise, or Observable");
2024
- };
2025
- /**
2026
- * Creates a Stream that immediately emits the arguments that you give to
2027
- * *of*, then completes.
2028
- *
2029
- * Marble diagram:
2030
- *
2031
- * ```text
2032
- * of(1,2,3)
2033
- * 123|
2034
- * ```
2035
- *
2036
- * @factory true
2037
- * @param a The first value you want to emit as an event on the stream.
2038
- * @param b The second value you want to emit as an event on the stream. One
2039
- * or more of these values may be given as arguments.
2040
- * @return {Stream}
2041
- */
2042
- Stream.of = function () {
2043
- var items = [];
2044
- for (var _i = 0; _i < arguments.length; _i++) {
2045
- items[_i] = arguments[_i];
2046
- }
2047
- return Stream.fromArray(items);
2048
- };
2049
- /**
2050
- * Converts an array to a stream. The returned stream will emit synchronously
2051
- * all the items in the array, and then complete.
2052
- *
2053
- * Marble diagram:
2054
- *
2055
- * ```text
2056
- * fromArray([1,2,3])
2057
- * 123|
2058
- * ```
2059
- *
2060
- * @factory true
2061
- * @param {Array} array The array to be converted as a stream.
2062
- * @return {Stream}
2063
- */
2064
- Stream.fromArray = function (array) {
2065
- return new Stream(new FromArray(array));
2066
- };
2067
- /**
2068
- * Converts a promise to a stream. The returned stream will emit the resolved
2069
- * value of the promise, and then complete. However, if the promise is
2070
- * rejected, the stream will emit the corresponding error.
2071
- *
2072
- * Marble diagram:
2073
- *
2074
- * ```text
2075
- * fromPromise( ----42 )
2076
- * -----------------42|
2077
- * ```
2078
- *
2079
- * @factory true
2080
- * @param {PromiseLike} promise The promise to be converted as a stream.
2081
- * @return {Stream}
2082
- */
2083
- Stream.fromPromise = function (promise) {
2084
- return new Stream(new FromPromise(promise));
2085
- };
2086
- /**
2087
- * Converts an Observable into a Stream.
2088
- *
2089
- * @factory true
2090
- * @param {any} observable The observable to be converted as a stream.
2091
- * @return {Stream}
2092
- */
2093
- Stream.fromObservable = function (obs) {
2094
- if (obs.endWhen !== undefined)
2095
- return obs;
2096
- var o = typeof obs[$$observable] === 'function' ? obs[$$observable]() : obs;
2097
- return new Stream(new FromObservable(o));
2098
- };
2099
- /**
2100
- * Creates a stream that periodically emits incremental numbers, every
2101
- * `period` milliseconds.
2102
- *
2103
- * Marble diagram:
2104
- *
2105
- * ```text
2106
- * periodic(1000)
2107
- * ---0---1---2---3---4---...
2108
- * ```
2109
- *
2110
- * @factory true
2111
- * @param {number} period The interval in milliseconds to use as a rate of
2112
- * emission.
2113
- * @return {Stream}
2114
- */
2115
- Stream.periodic = function (period) {
2116
- return new Stream(new Periodic(period));
2117
- };
2118
- Stream.prototype._map = function (project) {
2119
- return new (this.ctor())(new MapOp(project, this));
2120
- };
2121
- /**
2122
- * Transforms each event from the input Stream through a `project` function,
2123
- * to get a Stream that emits those transformed events.
2124
- *
2125
- * Marble diagram:
2126
- *
2127
- * ```text
2128
- * --1---3--5-----7------
2129
- * map(i => i * 10)
2130
- * --10--30-50----70-----
2131
- * ```
2132
- *
2133
- * @param {Function} project A function of type `(t: T) => U` that takes event
2134
- * `t` of type `T` from the input Stream and produces an event of type `U`, to
2135
- * be emitted on the output Stream.
2136
- * @return {Stream}
2137
- */
2138
- Stream.prototype.map = function (project) {
2139
- return this._map(project);
2140
- };
2141
- /**
2142
- * It's like `map`, but transforms each input event to always the same
2143
- * constant value on the output Stream.
2144
- *
2145
- * Marble diagram:
2146
- *
2147
- * ```text
2148
- * --1---3--5-----7-----
2149
- * mapTo(10)
2150
- * --10--10-10----10----
2151
- * ```
2152
- *
2153
- * @param projectedValue A value to emit on the output Stream whenever the
2154
- * input Stream emits any value.
2155
- * @return {Stream}
2156
- */
2157
- Stream.prototype.mapTo = function (projectedValue) {
2158
- var s = this.map(function () { return projectedValue; });
2159
- var op = s._prod;
2160
- op.type = 'mapTo';
2161
- return s;
2162
- };
2163
- /**
2164
- * Only allows events that pass the test given by the `passes` argument.
2165
- *
2166
- * Each event from the input stream is given to the `passes` function. If the
2167
- * function returns `true`, the event is forwarded to the output stream,
2168
- * otherwise it is ignored and not forwarded.
2169
- *
2170
- * Marble diagram:
2171
- *
2172
- * ```text
2173
- * --1---2--3-----4-----5---6--7-8--
2174
- * filter(i => i % 2 === 0)
2175
- * ------2--------4---------6----8--
2176
- * ```
2177
- *
2178
- * @param {Function} passes A function of type `(t: T) => boolean` that takes
2179
- * an event from the input stream and checks if it passes, by returning a
2180
- * boolean.
2181
- * @return {Stream}
2182
- */
2183
- Stream.prototype.filter = function (passes) {
2184
- var p = this._prod;
2185
- if (p instanceof Filter)
2186
- return new Stream(new Filter(and(p.f, passes), p.ins));
2187
- return new Stream(new Filter(passes, this));
2188
- };
2189
- /**
2190
- * Lets the first `amount` many events from the input stream pass to the
2191
- * output stream, then makes the output stream complete.
2192
- *
2193
- * Marble diagram:
2194
- *
2195
- * ```text
2196
- * --a---b--c----d---e--
2197
- * take(3)
2198
- * --a---b--c|
2199
- * ```
2200
- *
2201
- * @param {number} amount How many events to allow from the input stream
2202
- * before completing the output stream.
2203
- * @return {Stream}
2204
- */
2205
- Stream.prototype.take = function (amount) {
2206
- return new (this.ctor())(new Take(amount, this));
2207
- };
2208
- /**
2209
- * Ignores the first `amount` many events from the input stream, and then
2210
- * after that starts forwarding events from the input stream to the output
2211
- * stream.
2212
- *
2213
- * Marble diagram:
2214
- *
2215
- * ```text
2216
- * --a---b--c----d---e--
2217
- * drop(3)
2218
- * --------------d---e--
2219
- * ```
2220
- *
2221
- * @param {number} amount How many events to ignore from the input stream
2222
- * before forwarding all events from the input stream to the output stream.
2223
- * @return {Stream}
2224
- */
2225
- Stream.prototype.drop = function (amount) {
2226
- return new Stream(new Drop(amount, this));
2227
- };
2228
- /**
2229
- * When the input stream completes, the output stream will emit the last event
2230
- * emitted by the input stream, and then will also complete.
2231
- *
2232
- * Marble diagram:
2233
- *
2234
- * ```text
2235
- * --a---b--c--d----|
2236
- * last()
2237
- * -----------------d|
2238
- * ```
2239
- *
2240
- * @return {Stream}
2241
- */
2242
- Stream.prototype.last = function () {
2243
- return new Stream(new Last(this));
2244
- };
2245
- /**
2246
- * Prepends the given `initial` value to the sequence of events emitted by the
2247
- * input stream. The returned stream is a MemoryStream, which means it is
2248
- * already `remember()`'d.
2249
- *
2250
- * Marble diagram:
2251
- *
2252
- * ```text
2253
- * ---1---2-----3---
2254
- * startWith(0)
2255
- * 0--1---2-----3---
2256
- * ```
2257
- *
2258
- * @param initial The value or event to prepend.
2259
- * @return {MemoryStream}
2260
- */
2261
- Stream.prototype.startWith = function (initial) {
2262
- return new MemoryStream(new StartWith(this, initial));
2263
- };
2264
- /**
2265
- * Uses another stream to determine when to complete the current stream.
2266
- *
2267
- * When the given `other` stream emits an event or completes, the output
2268
- * stream will complete. Before that happens, the output stream will behaves
2269
- * like the input stream.
2270
- *
2271
- * Marble diagram:
2272
- *
2273
- * ```text
2274
- * ---1---2-----3--4----5----6---
2275
- * endWhen( --------a--b--| )
2276
- * ---1---2-----3--4--|
2277
- * ```
2278
- *
2279
- * @param other Some other stream that is used to know when should the output
2280
- * stream of this operator complete.
2281
- * @return {Stream}
2282
- */
2283
- Stream.prototype.endWhen = function (other) {
2284
- return new (this.ctor())(new EndWhen(other, this));
2285
- };
2286
- /**
2287
- * "Folds" the stream onto itself.
2288
- *
2289
- * Combines events from the past throughout
2290
- * the entire execution of the input stream, allowing you to accumulate them
2291
- * together. It's essentially like `Array.prototype.reduce`. The returned
2292
- * stream is a MemoryStream, which means it is already `remember()`'d.
2293
- *
2294
- * The output stream starts by emitting the `seed` which you give as argument.
2295
- * Then, when an event happens on the input stream, it is combined with that
2296
- * seed value through the `accumulate` function, and the output value is
2297
- * emitted on the output stream. `fold` remembers that output value as `acc`
2298
- * ("accumulator"), and then when a new input event `t` happens, `acc` will be
2299
- * combined with that to produce the new `acc` and so forth.
2300
- *
2301
- * Marble diagram:
2302
- *
2303
- * ```text
2304
- * ------1-----1--2----1----1------
2305
- * fold((acc, x) => acc + x, 3)
2306
- * 3-----4-----5--7----8----9------
2307
- * ```
2308
- *
2309
- * @param {Function} accumulate A function of type `(acc: R, t: T) => R` that
2310
- * takes the previous accumulated value `acc` and the incoming event from the
2311
- * input stream and produces the new accumulated value.
2312
- * @param seed The initial accumulated value, of type `R`.
2313
- * @return {MemoryStream}
2314
- */
2315
- Stream.prototype.fold = function (accumulate, seed) {
2316
- return new MemoryStream(new Fold(accumulate, seed, this));
2317
- };
2318
- /**
2319
- * Replaces an error with another stream.
2320
- *
2321
- * When (and if) an error happens on the input stream, instead of forwarding
2322
- * that error to the output stream, *replaceError* will call the `replace`
2323
- * function which returns the stream that the output stream will replicate.
2324
- * And, in case that new stream also emits an error, `replace` will be called
2325
- * again to get another stream to start replicating.
2326
- *
2327
- * Marble diagram:
2328
- *
2329
- * ```text
2330
- * --1---2-----3--4-----X
2331
- * replaceError( () => --10--| )
2332
- * --1---2-----3--4--------10--|
2333
- * ```
2334
- *
2335
- * @param {Function} replace A function of type `(err) => Stream` that takes
2336
- * the error that occurred on the input stream or on the previous replacement
2337
- * stream and returns a new stream. The output stream will behave like the
2338
- * stream that this function returns.
2339
- * @return {Stream}
2340
- */
2341
- Stream.prototype.replaceError = function (replace) {
2342
- return new (this.ctor())(new ReplaceError(replace, this));
2343
- };
2344
- /**
2345
- * Flattens a "stream of streams", handling only one nested stream at a time
2346
- * (no concurrency).
2347
- *
2348
- * If the input stream is a stream that emits streams, then this operator will
2349
- * return an output stream which is a flat stream: emits regular events. The
2350
- * flattening happens without concurrency. It works like this: when the input
2351
- * stream emits a nested stream, *flatten* will start imitating that nested
2352
- * one. However, as soon as the next nested stream is emitted on the input
2353
- * stream, *flatten* will forget the previous nested one it was imitating, and
2354
- * will start imitating the new nested one.
2355
- *
2356
- * Marble diagram:
2357
- *
2358
- * ```text
2359
- * --+--------+---------------
2360
- * \ \
2361
- * \ ----1----2---3--
2362
- * --a--b----c----d--------
2363
- * flatten
2364
- * -----a--b------1----2---3--
2365
- * ```
2366
- *
2367
- * @return {Stream}
2368
- */
2369
- Stream.prototype.flatten = function () {
2370
- return new Stream(new Flatten(this));
2371
- };
2372
- /**
2373
- * Passes the input stream to a custom operator, to produce an output stream.
2374
- *
2375
- * *compose* is a handy way of using an existing function in a chained style.
2376
- * Instead of writing `outStream = f(inStream)` you can write
2377
- * `outStream = inStream.compose(f)`.
2378
- *
2379
- * @param {function} operator A function that takes a stream as input and
2380
- * returns a stream as well.
2381
- * @return {Stream}
2382
- */
2383
- Stream.prototype.compose = function (operator) {
2384
- return operator(this);
2385
- };
2386
- /**
2387
- * Returns an output stream that behaves like the input stream, but also
2388
- * remembers the most recent event that happens on the input stream, so that a
2389
- * newly added listener will immediately receive that memorised event.
2390
- *
2391
- * @return {MemoryStream}
2392
- */
2393
- Stream.prototype.remember = function () {
2394
- return new MemoryStream(new Remember(this));
2395
- };
2396
- /**
2397
- * Returns an output stream that identically behaves like the input stream,
2398
- * but also runs a `spy` function for each event, to help you debug your app.
2399
- *
2400
- * *debug* takes a `spy` function as argument, and runs that for each event
2401
- * happening on the input stream. If you don't provide the `spy` argument,
2402
- * then *debug* will just `console.log` each event. This helps you to
2403
- * understand the flow of events through some operator chain.
2404
- *
2405
- * Please note that if the output stream has no listeners, then it will not
2406
- * start, which means `spy` will never run because no actual event happens in
2407
- * that case.
2408
- *
2409
- * Marble diagram:
2410
- *
2411
- * ```text
2412
- * --1----2-----3-----4--
2413
- * debug
2414
- * --1----2-----3-----4--
2415
- * ```
2416
- *
2417
- * @param {function} labelOrSpy A string to use as the label when printing
2418
- * debug information on the console, or a 'spy' function that takes an event
2419
- * as argument, and does not need to return anything.
2420
- * @return {Stream}
2421
- */
2422
- Stream.prototype.debug = function (labelOrSpy) {
2423
- return new (this.ctor())(new Debug(this, labelOrSpy));
2424
- };
2425
- /**
2426
- * *imitate* changes this current Stream to emit the same events that the
2427
- * `other` given Stream does. This method returns nothing.
2428
- *
2429
- * This method exists to allow one thing: **circular dependency of streams**.
2430
- * For instance, let's imagine that for some reason you need to create a
2431
- * circular dependency where stream `first$` depends on stream `second$`
2432
- * which in turn depends on `first$`:
2433
- *
2434
- * <!-- skip-example -->
2435
- * ```js
2436
- * import delay from 'xstream/extra/delay'
2437
- *
2438
- * var first$ = second$.map(x => x * 10).take(3);
2439
- * var second$ = first$.map(x => x + 1).startWith(1).compose(delay(100));
2440
- * ```
2441
- *
2442
- * However, that is invalid JavaScript, because `second$` is undefined
2443
- * on the first line. This is how *imitate* can help solve it:
2444
- *
2445
- * ```js
2446
- * import delay from 'xstream/extra/delay'
2447
- *
2448
- * var secondProxy$ = xs.create();
2449
- * var first$ = secondProxy$.map(x => x * 10).take(3);
2450
- * var second$ = first$.map(x => x + 1).startWith(1).compose(delay(100));
2451
- * secondProxy$.imitate(second$);
2452
- * ```
2453
- *
2454
- * We create `secondProxy$` before the others, so it can be used in the
2455
- * declaration of `first$`. Then, after both `first$` and `second$` are
2456
- * defined, we hook `secondProxy$` with `second$` with `imitate()` to tell
2457
- * that they are "the same". `imitate` will not trigger the start of any
2458
- * stream, it just binds `secondProxy$` and `second$` together.
2459
- *
2460
- * The following is an example where `imitate()` is important in Cycle.js
2461
- * applications. A parent component contains some child components. A child
2462
- * has an action stream which is given to the parent to define its state:
2463
- *
2464
- * <!-- skip-example -->
2465
- * ```js
2466
- * const childActionProxy$ = xs.create();
2467
- * const parent = Parent({...sources, childAction$: childActionProxy$});
2468
- * const childAction$ = parent.state$.map(s => s.child.action$).flatten();
2469
- * childActionProxy$.imitate(childAction$);
2470
- * ```
2471
- *
2472
- * Note, though, that **`imitate()` does not support MemoryStreams**. If we
2473
- * would attempt to imitate a MemoryStream in a circular dependency, we would
2474
- * either get a race condition (where the symptom would be "nothing happens")
2475
- * or an infinite cyclic emission of values. It's useful to think about
2476
- * MemoryStreams as cells in a spreadsheet. It doesn't make any sense to
2477
- * define a spreadsheet cell `A1` with a formula that depends on `B1` and
2478
- * cell `B1` defined with a formula that depends on `A1`.
2479
- *
2480
- * If you find yourself wanting to use `imitate()` with a
2481
- * MemoryStream, you should rework your code around `imitate()` to use a
2482
- * Stream instead. Look for the stream in the circular dependency that
2483
- * represents an event stream, and that would be a candidate for creating a
2484
- * proxy Stream which then imitates the target Stream.
2485
- *
2486
- * @param {Stream} target The other stream to imitate on the current one. Must
2487
- * not be a MemoryStream.
2488
- */
2489
- Stream.prototype.imitate = function (target) {
2490
- if (target instanceof MemoryStream)
2491
- throw new Error('A MemoryStream was given to imitate(), but it only ' +
2492
- 'supports a Stream. Read more about this restriction here: ' +
2493
- 'https://github.com/staltz/xstream#faq');
2494
- this._target = target;
2495
- for (var ils = this._ils, N = ils.length, i = 0; i < N; i++)
2496
- target._add(ils[i]);
2497
- this._ils = [];
2498
- };
2499
- /**
2500
- * Forces the Stream to emit the given value to its listeners.
2501
- *
2502
- * As the name indicates, if you use this, you are most likely doing something
2503
- * The Wrong Way. Please try to understand the reactive way before using this
2504
- * method. Use it only when you know what you are doing.
2505
- *
2506
- * @param value The "next" value you want to broadcast to all listeners of
2507
- * this Stream.
2508
- */
2509
- Stream.prototype.shamefullySendNext = function (value) {
2510
- this._n(value);
2511
- };
2512
- /**
2513
- * Forces the Stream to emit the given error to its listeners.
2514
- *
2515
- * As the name indicates, if you use this, you are most likely doing something
2516
- * The Wrong Way. Please try to understand the reactive way before using this
2517
- * method. Use it only when you know what you are doing.
2518
- *
2519
- * @param {any} error The error you want to broadcast to all the listeners of
2520
- * this Stream.
2521
- */
2522
- Stream.prototype.shamefullySendError = function (error) {
2523
- this._e(error);
2524
- };
2525
- /**
2526
- * Forces the Stream to emit the "completed" event to its listeners.
2527
- *
2528
- * As the name indicates, if you use this, you are most likely doing something
2529
- * The Wrong Way. Please try to understand the reactive way before using this
2530
- * method. Use it only when you know what you are doing.
2531
- */
2532
- Stream.prototype.shamefullySendComplete = function () {
2533
- this._c();
2534
- };
2535
- /**
2536
- * Adds a "debug" listener to the stream. There can only be one debug
2537
- * listener, that's why this is 'setDebugListener'. To remove the debug
2538
- * listener, just call setDebugListener(null).
2539
- *
2540
- * A debug listener is like any other listener. The only difference is that a
2541
- * debug listener is "stealthy": its presence/absence does not trigger the
2542
- * start/stop of the stream (or the producer inside the stream). This is
2543
- * useful so you can inspect what is going on without changing the behavior
2544
- * of the program. If you have an idle stream and you add a normal listener to
2545
- * it, the stream will start executing. But if you set a debug listener on an
2546
- * idle stream, it won't start executing (not until the first normal listener
2547
- * is added).
2548
- *
2549
- * As the name indicates, we don't recommend using this method to build app
2550
- * logic. In fact, in most cases the debug operator works just fine. Only use
2551
- * this one if you know what you're doing.
2552
- *
2553
- * @param {Listener<T>} listener
2554
- */
2555
- Stream.prototype.setDebugListener = function (listener) {
2556
- if (!listener) {
2557
- this._d = false;
2558
- this._dl = NO;
2559
- }
2560
- else {
2561
- this._d = true;
2562
- listener._n = listener.next || noop;
2563
- listener._e = listener.error || noop;
2564
- listener._c = listener.complete || noop;
2565
- this._dl = listener;
2566
- }
2567
- };
2568
- /**
2569
- * Blends multiple streams together, emitting events from all of them
2570
- * concurrently.
2571
- *
2572
- * *merge* takes multiple streams as arguments, and creates a stream that
2573
- * behaves like each of the argument streams, in parallel.
2574
- *
2575
- * Marble diagram:
2576
- *
2577
- * ```text
2578
- * --1----2-----3--------4---
2579
- * ----a-----b----c---d------
2580
- * merge
2581
- * --1-a--2--b--3-c---d--4---
2582
- * ```
2583
- *
2584
- * @factory true
2585
- * @param {Stream} stream1 A stream to merge together with other streams.
2586
- * @param {Stream} stream2 A stream to merge together with other streams. Two
2587
- * or more streams may be given as arguments.
2588
- * @return {Stream}
2589
- */
2590
- Stream.merge = function merge() {
2591
- var streams = [];
2592
- for (var _i = 0; _i < arguments.length; _i++) {
2593
- streams[_i] = arguments[_i];
2594
- }
2595
- return new Stream(new Merge(streams));
2596
- };
2597
- /**
2598
- * Combines multiple input streams together to return a stream whose events
2599
- * are arrays that collect the latest events from each input stream.
2600
- *
2601
- * *combine* internally remembers the most recent event from each of the input
2602
- * streams. When any of the input streams emits an event, that event together
2603
- * with all the other saved events are combined into an array. That array will
2604
- * be emitted on the output stream. It's essentially a way of joining together
2605
- * the events from multiple streams.
2606
- *
2607
- * Marble diagram:
2608
- *
2609
- * ```text
2610
- * --1----2-----3--------4---
2611
- * ----a-----b-----c--d------
2612
- * combine
2613
- * ----1a-2a-2b-3b-3c-3d-4d--
2614
- * ```
2615
- *
2616
- * @factory true
2617
- * @param {Stream} stream1 A stream to combine together with other streams.
2618
- * @param {Stream} stream2 A stream to combine together with other streams.
2619
- * Multiple streams, not just two, may be given as arguments.
2620
- * @return {Stream}
2621
- */
2622
- Stream.combine = function combine() {
2623
- var streams = [];
2624
- for (var _i = 0; _i < arguments.length; _i++) {
2625
- streams[_i] = arguments[_i];
2626
- }
2627
- return new Stream(new Combine(streams));
2628
- };
2629
- return Stream;
2630
- }());
2631
- xstream.Stream = Stream;
2632
- var MemoryStream = /** @class */ (function (_super) {
2633
- __extends(MemoryStream, _super);
2634
- function MemoryStream(producer) {
2635
- var _this = _super.call(this, producer) || this;
2636
- _this._has = false;
2637
- return _this;
2638
- }
2639
- MemoryStream.prototype._n = function (x) {
2640
- this._v = x;
2641
- this._has = true;
2642
- _super.prototype._n.call(this, x);
2643
- };
2644
- MemoryStream.prototype._add = function (il) {
2645
- var ta = this._target;
2646
- if (ta)
2647
- return ta._add(il);
2648
- var a = this._ils;
2649
- a.push(il);
2650
- if (a.length > 1) {
2651
- if (this._has)
2652
- il._n(this._v);
2653
- return;
2654
- }
2655
- if (this._stopID !== NO) {
2656
- if (this._has)
2657
- il._n(this._v);
2658
- clearTimeout(this._stopID);
2659
- this._stopID = NO;
2660
- }
2661
- else if (this._has)
2662
- il._n(this._v);
2663
- else {
2664
- var p = this._prod;
2665
- if (p !== NO)
2666
- p._start(this);
2667
- }
2668
- };
2669
- MemoryStream.prototype._stopNow = function () {
2670
- this._has = false;
2671
- _super.prototype._stopNow.call(this);
2672
- };
2673
- MemoryStream.prototype._x = function () {
2674
- this._has = false;
2675
- _super.prototype._x.call(this);
2676
- };
2677
- MemoryStream.prototype.map = function (project) {
2678
- return this._map(project);
2679
- };
2680
- MemoryStream.prototype.mapTo = function (projectedValue) {
2681
- return _super.prototype.mapTo.call(this, projectedValue);
2682
- };
2683
- MemoryStream.prototype.take = function (amount) {
2684
- return _super.prototype.take.call(this, amount);
2685
- };
2686
- MemoryStream.prototype.endWhen = function (other) {
2687
- return _super.prototype.endWhen.call(this, other);
2688
- };
2689
- MemoryStream.prototype.replaceError = function (replace) {
2690
- return _super.prototype.replaceError.call(this, replace);
2691
- };
2692
- MemoryStream.prototype.remember = function () {
2693
- return this;
2694
- };
2695
- MemoryStream.prototype.debug = function (labelOrSpy) {
2696
- return _super.prototype.debug.call(this, labelOrSpy);
2697
- };
2698
- return MemoryStream;
2699
- }(Stream));
2700
- xstream.MemoryStream = MemoryStream;
2701
- var xs = Stream;
2702
- xstream.default = xs;
2703
-
2704
- Object.defineProperty(dropRepeats$1, "__esModule", { value: true });
2705
- dropRepeats$1.DropRepeatsOperator = void 0;
2706
- var index_1$3 = xstream;
2707
- var empty = {};
2708
- var DropRepeatsOperator = /** @class */ (function () {
2709
- function DropRepeatsOperator(ins, fn) {
2710
- this.ins = ins;
2711
- this.type = 'dropRepeats';
2712
- this.out = null;
2713
- this.v = empty;
2714
- this.isEq = fn ? fn : function (x, y) { return x === y; };
2715
- }
2716
- DropRepeatsOperator.prototype._start = function (out) {
2717
- this.out = out;
2718
- this.ins._add(this);
2719
- };
2720
- DropRepeatsOperator.prototype._stop = function () {
2721
- this.ins._remove(this);
2722
- this.out = null;
2723
- this.v = empty;
2724
- };
2725
- DropRepeatsOperator.prototype._n = function (t) {
2726
- var u = this.out;
2727
- if (!u)
2728
- return;
2729
- var v = this.v;
2730
- if (v !== empty && this.isEq(t, v))
2731
- return;
2732
- this.v = t;
2733
- u._n(t);
2734
- };
2735
- DropRepeatsOperator.prototype._e = function (err) {
2736
- var u = this.out;
2737
- if (!u)
2738
- return;
2739
- u._e(err);
2740
- };
2741
- DropRepeatsOperator.prototype._c = function () {
2742
- var u = this.out;
2743
- if (!u)
2744
- return;
2745
- u._c();
2746
- };
2747
- return DropRepeatsOperator;
2748
- }());
2749
- dropRepeats$1.DropRepeatsOperator = DropRepeatsOperator;
2750
- /**
2751
- * Drops consecutive duplicate values in a stream.
2752
- *
2753
- * Marble diagram:
2754
- *
2755
- * ```text
2756
- * --1--2--1--1--1--2--3--4--3--3|
2757
- * dropRepeats
2758
- * --1--2--1--------2--3--4--3---|
2759
- * ```
2760
- *
2761
- * Example:
2762
- *
2763
- * ```js
2764
- * import dropRepeats from 'xstream/extra/dropRepeats'
2765
- *
2766
- * const stream = xs.of(1, 2, 1, 1, 1, 2, 3, 4, 3, 3)
2767
- * .compose(dropRepeats())
2768
- *
2769
- * stream.addListener({
2770
- * next: i => console.log(i),
2771
- * error: err => console.error(err),
2772
- * complete: () => console.log('completed')
2773
- * })
2774
- * ```
2775
- *
2776
- * ```text
2777
- * > 1
2778
- * > 2
2779
- * > 1
2780
- * > 2
2781
- * > 3
2782
- * > 4
2783
- * > 3
2784
- * > completed
2785
- * ```
2786
- *
2787
- * Example with a custom isEqual function:
2788
- *
2789
- * ```js
2790
- * import dropRepeats from 'xstream/extra/dropRepeats'
2791
- *
2792
- * const stream = xs.of('a', 'b', 'a', 'A', 'B', 'b')
2793
- * .compose(dropRepeats((x, y) => x.toLowerCase() === y.toLowerCase()))
2794
- *
2795
- * stream.addListener({
2796
- * next: i => console.log(i),
2797
- * error: err => console.error(err),
2798
- * complete: () => console.log('completed')
2799
- * })
2800
- * ```
2801
- *
2802
- * ```text
2803
- * > a
2804
- * > b
2805
- * > a
2806
- * > B
2807
- * > completed
2808
- * ```
2809
- *
2810
- * @param {Function} isEqual An optional function of type
2811
- * `(x: T, y: T) => boolean` that takes an event from the input stream and
2812
- * checks if it is equal to previous event, by returning a boolean.
2813
- * @return {Stream}
2814
- */
2815
- function dropRepeats(isEqual) {
2816
- if (isEqual === void 0) { isEqual = void 0; }
2817
- return function dropRepeatsOperator(ins) {
2818
- return new index_1$3.Stream(new DropRepeatsOperator(ins, isEqual));
2819
- };
2820
- }
2821
- var _default$3 = dropRepeats$1.default = dropRepeats;
2822
-
2823
- function switchable(factories, name$, initial, opts={}) {
2824
- const {
2825
- switched=['DOM'],
2826
- stateSourceName='STATE'
2827
- } = opts;
2828
- const nameType = typeof name$;
2829
-
2830
- if (!name$) throw new Error(`Missing 'name$' parameter for switchable()`)
2831
- if (!(nameType === 'string' || nameType === 'function' || name$ instanceof Stream$1)) {
2832
- throw new Error(`Invalid 'name$' parameter for switchable(): expects Stream, String, or Function`)
2833
- }
2834
-
2835
- if (name$ instanceof Stream$1) {
2836
- const withInitial$ = name$
2837
- .compose(_default$3())
2838
- .startWith(initial)
2839
- .remember();
2840
- return sources => _switchable(factories, sources, withInitial$, switched)
2841
- } else {
2842
- const mapFunction = (nameType === 'function' && name$) || (state => state[name$]);
2843
- return sources => {
2844
- const state$ = sources && ((typeof stateSourceName === 'string' && sources[stateSourceName]) || sources.STATE || sources.state).stream;
2845
- if (!state$ instanceof Stream$1) throw new Error(`Could not find the state source: ${ stateSourceName }`)
2846
- const _name$ = state$
2847
- .map(mapFunction)
2848
- .filter(name => typeof name === 'string')
2849
- .compose(_default$3())
2850
- .startWith(initial)
2851
- .remember();
2852
- return _switchable(factories, sources, _name$, switched, stateSourceName)
2853
- }
2854
- }
2855
- }
2856
-
2857
-
2858
-
2859
- /**
2860
- * create a group of components which can be switched between based on a stream of component names
2861
- *
2862
- * @param {Object} factories maps names to component creation functions
2863
- * @param {Object} sources standard cycle sources object provided to each component
2864
- * @param {Observable} name$ stream of names corresponding to the component names
2865
- * @param {Array} switched which cycle sinks from the components should be `switched` when a new `name$` is emitted
2866
- * @return {Object} cycle sinks object where the selected sinks are switched to the last component name emitted to `name$`
2867
- *
2868
- * any component sinks not dsignated in `switched` will be merged across all components
2869
- */
2870
- function _switchable (factories, sources, name$, switched=['DOM'], stateSourceName='STATE') {
2871
- if (typeof switched === 'string') switched = [switched];
2872
-
2873
- const sinks = Object.entries(factories)
2874
- .map(([name, factory]) => {
2875
- if (sources[stateSourceName]) {
2876
- const state$ = sources[stateSourceName].stream;
2877
- const switched = xs$1.combine(name$, state$)
2878
- .filter(([newComponentName, _]) => newComponentName == name)
2879
- .map(([_, state]) => state)
2880
- .remember();
2881
-
2882
- const state = new sources[stateSourceName].constructor(switched, sources[stateSourceName]._name);
2883
- return [name, factory({ ...sources, state })]
2884
- }
2885
- return [name, factory(sources)]
2886
- });
2887
-
2888
- const switchedSinks = Object.keys(sources)
2889
- .reduce((obj, sinkName) => {
2890
- if (switched.includes(sinkName)) {
2891
- obj[sinkName] = name$
2892
- .map( newComponentName => {
2893
- const sink = sinks.find(([componentName, _]) => componentName === newComponentName);
2894
- return (sink && sink[1][sinkName]) || xs$1.never()
2895
- })
2896
- .flatten()
2897
- .remember()
2898
- .startWith(undefined);
2899
- } else {
2900
- const definedSinks = sinks.filter(([_,sink]) => sink[sinkName] !== undefined)
2901
- .map(([_,sink]) => sink[sinkName]);
2902
- obj[sinkName] = xs$1.merge(...definedSinks);
2903
- }
2904
- return obj
2905
- }, {});
2906
-
2907
- return switchedSinks
2908
- }
2909
-
2910
- var delay$1 = {};
2911
-
2912
- Object.defineProperty(delay$1, "__esModule", { value: true });
2913
- var index_1$2 = xstream;
2914
- var DelayOperator = /** @class */ (function () {
2915
- function DelayOperator(dt, ins) {
2916
- this.dt = dt;
2917
- this.ins = ins;
2918
- this.type = 'delay';
2919
- this.out = null;
2920
- }
2921
- DelayOperator.prototype._start = function (out) {
2922
- this.out = out;
2923
- this.ins._add(this);
2924
- };
2925
- DelayOperator.prototype._stop = function () {
2926
- this.ins._remove(this);
2927
- this.out = null;
2928
- };
2929
- DelayOperator.prototype._n = function (t) {
2930
- var u = this.out;
2931
- if (!u)
2932
- return;
2933
- var id = setInterval(function () {
2934
- u._n(t);
2935
- clearInterval(id);
2936
- }, this.dt);
2937
- };
2938
- DelayOperator.prototype._e = function (err) {
2939
- var u = this.out;
2940
- if (!u)
2941
- return;
2942
- var id = setInterval(function () {
2943
- u._e(err);
2944
- clearInterval(id);
2945
- }, this.dt);
2946
- };
2947
- DelayOperator.prototype._c = function () {
2948
- var u = this.out;
2949
- if (!u)
2950
- return;
2951
- var id = setInterval(function () {
2952
- u._c();
2953
- clearInterval(id);
2954
- }, this.dt);
2955
- };
2956
- return DelayOperator;
2957
- }());
2958
- /**
2959
- * Delays periodic events by a given time period.
2960
- *
2961
- * Marble diagram:
2962
- *
2963
- * ```text
2964
- * 1----2--3--4----5|
2965
- * delay(60)
2966
- * ---1----2--3--4----5|
2967
- * ```
2968
- *
2969
- * Example:
2970
- *
2971
- * ```js
2972
- * import fromDiagram from 'xstream/extra/fromDiagram'
2973
- * import delay from 'xstream/extra/delay'
2974
- *
2975
- * const stream = fromDiagram('1----2--3--4----5|')
2976
- * .compose(delay(60))
2977
- *
2978
- * stream.addListener({
2979
- * next: i => console.log(i),
2980
- * error: err => console.error(err),
2981
- * complete: () => console.log('completed')
2982
- * })
2983
- * ```
2984
- *
2985
- * ```text
2986
- * > 1 (after 60 ms)
2987
- * > 2 (after 160 ms)
2988
- * > 3 (after 220 ms)
2989
- * > 4 (after 280 ms)
2990
- * > 5 (after 380 ms)
2991
- * > completed
2992
- * ```
2993
- *
2994
- * @param {number} period The amount of silence required in milliseconds.
2995
- * @return {Stream}
2996
- */
2997
- function delay(period) {
2998
- return function delayOperator(ins) {
2999
- return new index_1$2.Stream(new DelayOperator(period, ins));
3000
- };
3001
- }
3002
- var _default$2 = delay$1.default = delay;
3003
-
3004
- var concat$1 = {};
3005
-
3006
- Object.defineProperty(concat$1, "__esModule", { value: true });
3007
- var index_1$1 = xstream;
3008
- var ConcatProducer = /** @class */ (function () {
3009
- function ConcatProducer(streams) {
3010
- this.streams = streams;
3011
- this.type = 'concat';
3012
- this.out = null;
3013
- this.i = 0;
3014
- }
3015
- ConcatProducer.prototype._start = function (out) {
3016
- this.out = out;
3017
- this.streams[this.i]._add(this);
3018
- };
3019
- ConcatProducer.prototype._stop = function () {
3020
- var streams = this.streams;
3021
- if (this.i < streams.length) {
3022
- streams[this.i]._remove(this);
3023
- }
3024
- this.i = 0;
3025
- this.out = null;
3026
- };
3027
- ConcatProducer.prototype._n = function (t) {
3028
- var u = this.out;
3029
- if (!u)
3030
- return;
3031
- u._n(t);
3032
- };
3033
- ConcatProducer.prototype._e = function (err) {
3034
- var u = this.out;
3035
- if (!u)
3036
- return;
3037
- u._e(err);
3038
- };
3039
- ConcatProducer.prototype._c = function () {
3040
- var u = this.out;
3041
- if (!u)
3042
- return;
3043
- var streams = this.streams;
3044
- streams[this.i]._remove(this);
3045
- if (++this.i < streams.length) {
3046
- streams[this.i]._add(this);
3047
- }
3048
- else {
3049
- u._c();
3050
- }
3051
- };
3052
- return ConcatProducer;
3053
- }());
3054
- /**
3055
- * Puts one stream after the other. *concat* is a factory that takes multiple
3056
- * streams as arguments, and starts the `n+1`-th stream only when the `n`-th
3057
- * stream has completed. It concatenates those streams together.
3058
- *
3059
- * Marble diagram:
3060
- *
3061
- * ```text
3062
- * --1--2---3---4-|
3063
- * ...............--a-b-c--d-|
3064
- * concat
3065
- * --1--2---3---4---a-b-c--d-|
3066
- * ```
3067
- *
3068
- * Example:
3069
- *
3070
- * ```js
3071
- * import concat from 'xstream/extra/concat'
3072
- *
3073
- * const streamA = xs.of('a', 'b', 'c')
3074
- * const streamB = xs.of(10, 20, 30)
3075
- * const streamC = xs.of('X', 'Y', 'Z')
3076
- *
3077
- * const outputStream = concat(streamA, streamB, streamC)
3078
- *
3079
- * outputStream.addListener({
3080
- * next: (x) => console.log(x),
3081
- * error: (err) => console.error(err),
3082
- * complete: () => console.log('concat completed'),
3083
- * })
3084
- * ```
3085
- *
3086
- * @factory true
3087
- * @param {Stream} stream1 A stream to concatenate together with other streams.
3088
- * @param {Stream} stream2 A stream to concatenate together with other streams. Two
3089
- * or more streams may be given as arguments.
3090
- * @return {Stream}
3091
- */
3092
- function concat() {
3093
- var streams = [];
3094
- for (var _i = 0; _i < arguments.length; _i++) {
3095
- streams[_i] = arguments[_i];
3096
- }
3097
- return new index_1$1.Stream(new ConcatProducer(streams));
3098
- }
3099
- var _default$1 = concat$1.default = concat;
3100
-
3101
- var debounce$1 = {};
3102
-
3103
- Object.defineProperty(debounce$1, "__esModule", { value: true });
3104
- var index_1 = xstream;
3105
- var DebounceOperator = /** @class */ (function () {
3106
- function DebounceOperator(dt, ins) {
3107
- this.dt = dt;
3108
- this.ins = ins;
3109
- this.type = 'debounce';
3110
- this.out = null;
3111
- this.id = null;
3112
- this.t = index_1.NO;
3113
- }
3114
- DebounceOperator.prototype._start = function (out) {
3115
- this.out = out;
3116
- this.ins._add(this);
3117
- };
3118
- DebounceOperator.prototype._stop = function () {
3119
- this.ins._remove(this);
3120
- this.out = null;
3121
- this.clearInterval();
3122
- };
3123
- DebounceOperator.prototype.clearInterval = function () {
3124
- var id = this.id;
3125
- if (id !== null) {
3126
- clearInterval(id);
3127
- }
3128
- this.id = null;
3129
- };
3130
- DebounceOperator.prototype._n = function (t) {
3131
- var _this = this;
3132
- var u = this.out;
3133
- if (!u)
3134
- return;
3135
- this.clearInterval();
3136
- this.t = t;
3137
- this.id = setInterval(function () {
3138
- _this.clearInterval();
3139
- u._n(t);
3140
- _this.t = index_1.NO;
3141
- }, this.dt);
3142
- };
3143
- DebounceOperator.prototype._e = function (err) {
3144
- var u = this.out;
3145
- if (!u)
3146
- return;
3147
- this.clearInterval();
3148
- u._e(err);
3149
- };
3150
- DebounceOperator.prototype._c = function () {
3151
- var u = this.out;
3152
- if (!u)
3153
- return;
3154
- this.clearInterval();
3155
- if (this.t != index_1.NO)
3156
- u._n(this.t);
3157
- this.t = index_1.NO;
3158
- u._c();
3159
- };
3160
- return DebounceOperator;
3161
- }());
3162
- /**
3163
- * Delays events until a certain amount of silence has passed. If that timespan
3164
- * of silence is not met the event is dropped.
3165
- *
3166
- * Marble diagram:
3167
- *
3168
- * ```text
3169
- * --1----2--3--4----5|
3170
- * debounce(60)
3171
- * -----1----------4--|
3172
- * ```
3173
- *
3174
- * Example:
3175
- *
3176
- * ```js
3177
- * import fromDiagram from 'xstream/extra/fromDiagram'
3178
- * import debounce from 'xstream/extra/debounce'
3179
- *
3180
- * const stream = fromDiagram('--1----2--3--4----5|')
3181
- * .compose(debounce(60))
3182
- *
3183
- * stream.addListener({
3184
- * next: i => console.log(i),
3185
- * error: err => console.error(err),
3186
- * complete: () => console.log('completed')
3187
- * })
3188
- * ```
3189
- *
3190
- * ```text
3191
- * > 1
3192
- * > 4
3193
- * > completed
3194
- * ```
3195
- *
3196
- * @param {number} period The amount of silence required in milliseconds.
3197
- * @return {Stream}
3198
- */
3199
- function debounce(period) {
3200
- return function debounceOperator(ins) {
3201
- return new index_1.Stream(new DebounceOperator(period, ins));
3202
- };
3203
- }
3204
- var _default = debounce$1.default = debounce;
3205
-
3206
- const ENVIRONMENT = ((typeof window != 'undefined' && window) || (process && process.env)) || {};
3207
-
3208
-
3209
- const BOOTSTRAP_ACTION = 'BOOTSTRAP';
3210
- const INITIALIZE_ACTION = 'INITIALIZE';
3211
- const HYDRATE_ACTION = 'HYDRATE';
3212
- const PARENT_SINK_NAME = 'PARENT';
3213
- const CHILD_SOURCE_NAME = 'CHILD';
3214
-
3215
-
3216
- let COMPONENT_COUNT = 0;
3217
-
3218
-
3219
- const ABORT$1 = '~#~#~ABORT~#~#~';
3220
-
3221
- function component (opts) {
3222
- const { name, sources, isolateOpts, stateSourceName='STATE' } = opts;
3223
-
3224
- if (sources && !isObj(sources)) {
3225
- throw new Error('Sources must be a Cycle.js sources object:', name)
3226
- }
3227
-
3228
- let fixedIsolateOpts;
3229
- if (typeof isolateOpts == 'string') {
3230
- fixedIsolateOpts = { [stateSourceName]: isolateOpts };
3231
- } else {
3232
- if (isolateOpts === true) {
3233
- fixedIsolateOpts = {};
3234
- } else {
3235
- fixedIsolateOpts = isolateOpts;
3236
- }
3237
- }
3238
-
3239
- const currySources = typeof sources === 'undefined';
3240
- let returnFunction;
3241
-
3242
- if (isObj(fixedIsolateOpts)) {
3243
- const wrapped = (sources) => {
3244
- const fixedOpts = { ...opts, sources };
3245
- return (new Component(fixedOpts)).sinks
3246
- };
3247
- returnFunction = currySources ? isolate(wrapped, fixedIsolateOpts) : isolate(wrapped, fixedIsolateOpts)(sources);
3248
- } else {
3249
- returnFunction = currySources ? (sources) => (new Component({ ...opts, sources })).sinks : (new Component(opts)).sinks;
3250
- }
3251
-
3252
- returnFunction.componentName = name;
3253
- returnFunction.isSygnalComponent = true;
3254
-
3255
- return returnFunction
3256
- }
3257
-
3258
-
3259
-
3260
-
3261
-
3262
- class Component {
3263
- // [ PASSED PARAMETERS ]
3264
- // name
3265
- // sources
3266
- // intent
3267
- // model
3268
- // context
3269
- // view
3270
- // peers
3271
- // components
3272
- // initialState
3273
- // calculated
3274
- // storeCalculatedInState
3275
- // DOMSourceName
3276
- // stateSourceName
3277
- // requestSourceName
3278
- // debug
3279
-
3280
- // [ PRIVATE / CALCULATED VALUES ]
3281
- // sourceNames
3282
- // intent$
3283
- // action$
3284
- // model$
3285
- // context$
3286
- // peers$
3287
- // childSources
3288
- // vdom$
3289
- // currentState
3290
- // currentProps
3291
- // currentChildren
3292
- // currentContext
3293
- // subComponentSink$
3294
- // unmountRequest$ <- TODO
3295
- // unmount() <- TODO
3296
- // _debug
3297
-
3298
- // [ INSTANTIATED STREAM OPERATOR ]
3299
- // log
3300
-
3301
- // [ OUTPUT ]
3302
- // sinks
3303
-
3304
- constructor({ name='NO NAME', sources, intent, model, hmrActions, context, response, view, peers={}, components={}, initialState, calculated, storeCalculatedInState=true, DOMSourceName='DOM', stateSourceName='STATE', requestSourceName='HTTP', debug=false }) {
3305
- if (!sources || !isObj(sources)) throw new Error('Missing or invalid sources')
3306
-
3307
- this.name = name;
3308
- this.sources = sources;
3309
- this.intent = intent;
3310
- this.model = model;
3311
- this.hmrActions = hmrActions;
3312
- this.context = context;
3313
- this.response = response;
3314
- this.view = view;
3315
- this.peers = peers;
3316
- this.components = components;
3317
- this.initialState = initialState;
3318
- this.calculated = calculated;
3319
- this.storeCalculatedInState = storeCalculatedInState;
3320
- this.DOMSourceName = DOMSourceName;
3321
- this.stateSourceName = stateSourceName;
3322
- this.requestSourceName = requestSourceName;
3323
- this.sourceNames = Object.keys(sources);
3324
- this._debug = debug;
3325
-
3326
- this.isSubComponent = this.sourceNames.includes('props$');
3327
-
3328
- const state$ = sources[stateSourceName] && sources[stateSourceName].stream;
3329
-
3330
- if (state$) {
3331
- this.currentState = initialState || {};
3332
- this.sources[stateSourceName] = new StateSource(state$.map(val => {
3333
- this.currentState = val;
3334
- return val
3335
- }));
3336
- }
3337
-
3338
- const props$ = sources.props$;
3339
- if (props$) {
3340
- this.sources.props$ = props$.map(val => {
3341
- const { sygnalFactory, sygnalOptions, ...sanitizedProps } = val;
3342
- this.currentProps = sanitizedProps;
3343
- return val
3344
- });
3345
- }
3346
-
3347
- const children$ = sources.children$;
3348
- if (children$) {
3349
- this.sources.children$ = children$.map(val => {
3350
- this.currentChildren = val;
3351
- return val
3352
- });
3353
- }
3354
-
3355
-
3356
- // Ensure that the root component has an intent and model
3357
- // This is necessary to ensure that the component tree's state sink is subscribed to
3358
- if (!this.isSubComponent && typeof this.intent === 'undefined' && typeof this.model === 'undefined') {
3359
- this.initialState = initialState || true;
3360
- this.intent = _ => ({__NOOP_ACTION__:xs$1.never()});
3361
- this.model = {
3362
- __NOOP_ACTION__: state => state
3363
- };
3364
- }
3365
-
3366
- const componentNumber = COMPONENT_COUNT++;
3367
-
3368
- this.addCalculated = this.createMemoizedAddCalculated();
3369
- this.log = makeLog(`${componentNumber} | ${name}`);
3370
-
3371
- this.initChildSources$();
3372
- this.initIntent$();
3373
- this.initHmrActions();
3374
- this.initAction$();
3375
- this.initState();
3376
- this.initContext();
3377
- this.initModel$();
3378
- this.initPeers$();
3379
- this.initSubComponentSink$();
3380
- this.initSubComponentsRendered$();
3381
- this.initVdom$();
3382
- this.initSinks();
3383
-
3384
- this.sinks.__index = componentNumber;
3385
-
3386
- this.log(`Instantiated`, true);
3387
- }
3388
-
3389
- get debug() {
3390
- return this._debug || (ENVIRONMENT.SYGNAL_DEBUG === 'true' || ENVIRONMENT.SYGNAL_DEBUG === true)
3391
- }
3392
-
3393
- initIntent$() {
3394
- if (!this.intent) {
3395
- return
3396
- }
3397
- if (typeof this.intent != 'function') {
3398
- throw new Error('Intent must be a function')
3399
- }
3400
-
3401
- this.intent$ = this.intent(this.sources);
3402
-
3403
- if (!(this.intent$ instanceof Stream$1) && (!isObj(this.intent$))) {
3404
- throw new Error('Intent must return either an action$ stream or map of event streams')
3405
- }
3406
- }
3407
-
3408
- initHmrActions() {
3409
- if (typeof this.hmrActions === 'undefined') {
3410
- this.hmrAction$ = xs$1.of().filter(_ => false);
3411
- return
3412
- }
3413
- if (typeof this.hmrActions === 'string') {
3414
- this.hmrActions = [this.hmrActions];
3415
- }
3416
- if (!Array.isArray(this.hmrActions)) {
3417
- throw new Error(`[${ this.name }] hmrActions must be the name of an action or an array of names of actions to run when a component is hot-reloaded`)
3418
- }
3419
- if (this.hmrActions.some(action => typeof action !== 'string')) {
3420
- throw new Error(`[${ this.name }] hmrActions must be the name of an action or an array of names of actions to run when a component is hot-reloaded`)
3421
- }
3422
- this.hmrAction$ = xs$1.fromArray(this.hmrActions.map(action => ({ type: action })));
3423
- }
3424
-
3425
- initAction$() {
3426
- const requestSource = (this.sources && this.sources[this.requestSourceName]) || null;
3427
-
3428
- if (!this.intent$) {
3429
- this.action$ = xs$1.never();
3430
- return
3431
- }
3432
-
3433
- let runner;
3434
- if (this.intent$ instanceof Stream$1) {
3435
- runner = this.intent$;
3436
- } else {
3437
- const mapped = Object.entries(this.intent$)
3438
- .map(([type, data$]) => data$.map(data => ({type, data})));
3439
- runner = xs$1.merge(xs$1.never(), ...mapped);
3440
- }
3441
-
3442
- const action$ = ((runner instanceof Stream$1) ? runner : (runner.apply && runner(this.sources) || xs$1.never()));
3443
- const bootstrap$ = xs$1.of({ type: BOOTSTRAP_ACTION }).compose(_default$2(10));
3444
- const hmrAction$ = window?.__SYGNAL_HMR_UPDATING === true ? this.hmrAction$ : xs$1.of().filter(_ => false);
3445
- const wrapped$ = (this.model[BOOTSTRAP_ACTION] && window?.__SYGNAL_HMR_UPDATING !== true) ? _default$1(bootstrap$, action$) : _default$1(xs$1.of().compose(_default$2(1)).filter(_ => false), hmrAction$, action$);
3446
-
3447
-
3448
- let initialApiData;
3449
- if (window?.__SYGNAL_HMR_UPDATING !== true && requestSource && typeof requestSource.select == 'function') {
3450
- initialApiData = requestSource.select('initial')
3451
- .flatten();
3452
- } else {
3453
- initialApiData = xs$1.never();
3454
- }
3455
-
3456
- const hydrate$ = initialApiData.map(data => ({ type: HYDRATE_ACTION, data }));
3457
-
3458
- this.action$ = xs$1.merge(wrapped$, hydrate$)
3459
- .compose(this.log(({ type }) => `<${ type }> Action triggered`));
3460
- }
3461
-
3462
- initState() {
3463
- if (this.model !== undefined) {
3464
- if (this.model[INITIALIZE_ACTION] === undefined) {
3465
- this.model[INITIALIZE_ACTION] = {
3466
- [this.stateSourceName]: (_, data) => ({ ...this.addCalculated(data) })
3467
- };
3468
- } else if (isObj(this.model[INITIALIZE_ACTION])) {
3469
- Object.keys(this.model[INITIALIZE_ACTION]).forEach(name => {
3470
- if (name !== this.stateSourceName) {
3471
- console.warn(`${ INITIALIZE_ACTION } can only be used with the ${ this.stateSourceName } source... disregarding ${ name }`);
3472
- delete this.model[INITIALIZE_ACTION][name];
3473
- }
3474
- });
3475
- }
3476
- }
3477
- }
3478
-
3479
- initContext() {
3480
- if (!this.context && !this.sources.__parentContext$) {
3481
- this.context$ = xs$1.of({});
3482
- return
3483
- }
3484
-
3485
- const state$ = this.sources[this.stateSourceName]?.stream.startWith({}).compose(_default$3(objIsEqual)) || xs$1.never();
3486
- const parentContext$ = this.sources.__parentContext$?.startWith({}).compose(_default$3(objIsEqual)) || xs$1.of({});
3487
- if (this.context && !isObj(this.context)) {
3488
- console.error(`[${this.name}] Context must be an object mapping names to values of functions: ignoring provided ${ typeof this.context }`);
3489
- }
3490
- this.context$ = xs$1.combine(state$, parentContext$)
3491
- .map(([_, parent]) => {
3492
- const _parent = isObj(parent) ? parent : {};
3493
- const context = isObj(this.context) ? this.context : {};
3494
- const state = this.currentState;
3495
- const values = Object.entries(context).reduce((acc, current) => {
3496
- const [name, value] = current;
3497
- let _value;
3498
- const valueType = typeof value;
3499
- if (valueType === 'string') {
3500
- _value = state[value];
3501
- } else if (valueType === 'boolean') {
3502
- _value = state[name];
3503
- } else if (valueType === 'function') {
3504
- _value = value(state);
3505
- } else {
3506
- console.error(`[${ this.name }] Invalid context entry '${ name }': must be the name of a state property or a function returning a value to use`);
3507
- return acc
3508
- }
3509
- acc[name] = _value;
3510
- return acc
3511
- }, {});
3512
- const newContext = { ..._parent, ...values };
3513
- this.currentContext = newContext;
3514
- return newContext
3515
- })
3516
- .compose(_default$3(objIsEqual))
3517
- .startWith({});
3518
- this.context$.subscribe({ next: _ => _ });
3519
- }
3520
-
3521
- initModel$() {
3522
- if (typeof this.model == 'undefined') {
3523
- this.model$ = this.sourceNames.reduce((a,s) => {
3524
- a[s] = xs$1.never();
3525
- return a
3526
- }, {});
3527
- return
3528
- }
3529
-
3530
- const initial = { type: INITIALIZE_ACTION, data: this.initialState };
3531
- if (this.isSubComponent && this.initialState) {
3532
- console.warn(`[${ this.name }] Initial state provided to sub-component. This will overwrite any state provided by the parent component.`);
3533
- }
3534
- const shimmed$ = (this.initialState && window?.__SYGNAL_HMR_UPDATING !== true) ? _default$1(xs$1.of(initial), this.action$).compose(_default$2(0)) : this.action$;
3535
- const onState = () => this.makeOnAction(shimmed$, true, this.action$);
3536
- const onNormal = () => this.makeOnAction(this.action$, false, this.action$);
3537
-
3538
-
3539
- const modelEntries = Object.entries(this.model);
3540
-
3541
- const reducers = {};
3542
-
3543
- modelEntries.forEach((entry) => {
3544
- let [action, sinks] = entry;
3545
-
3546
- if (typeof sinks === 'function') {
3547
- sinks = { [this.stateSourceName]: sinks };
3548
- }
3549
-
3550
- if (!isObj(sinks)) {
3551
- throw new Error(`Entry for each action must be an object: ${ this.name } ${ action }`)
3552
- }
3553
-
3554
- const sinkEntries = Object.entries(sinks);
3555
-
3556
- sinkEntries.forEach((entry) => {
3557
- const [sink, reducer] = entry;
3558
-
3559
- const isStateSink = (sink === this.stateSourceName);
3560
- const isParentSink = (sink === PARENT_SINK_NAME);
3561
-
3562
- const on = isStateSink ? onState() : onNormal();
3563
- const on$ = isParentSink ? on(action, reducer).map(value => ({ name: this.name, value })) : on(action, reducer);
3564
-
3565
- const wrapped$ = on$
3566
- .compose(this.log(data => {
3567
- if (isStateSink) {
3568
- return `<${ action }> State reducer added`
3569
- } else if (isParentSink) {
3570
- return `<${ action }> Data sent to parent component: ${ JSON.stringify(data.value).replaceAll('"', '') }`
3571
- } else {
3572
- const extra = data && (data.type || data.command || data.name || data.key || (Array.isArray(data) && 'Array') || data);
3573
- return `<${ action }> Data sent to [${ sink }]: ${ JSON.stringify(extra).replaceAll('"', '') }`
3574
- }
3575
- }));
3576
-
3577
- if (Array.isArray(reducers[sink])) {
3578
- reducers[sink].push(wrapped$);
3579
- } else {
3580
- reducers[sink] = [wrapped$];
3581
- }
3582
- });
3583
- });
3584
-
3585
- const model$ = Object.entries(reducers).reduce((acc, entry) => {
3586
- const [sink, streams] = entry;
3587
- acc[sink] = xs$1.merge(xs$1.never(), ...streams);
3588
- return acc
3589
- }, {});
3590
-
3591
- this.model$ = model$;
3592
- }
3593
-
3594
- initPeers$() {
3595
- const initial = this.sourceNames.reduce((acc, name) => {
3596
- if (name == this.DOMSourceName) {
3597
- acc[name] = {};
3598
- } else {
3599
- acc[name] = [];
3600
- }
3601
- return acc
3602
- }, {});
3603
-
3604
- this.peers$ = Object.entries(this.peers).reduce((acc, [peerName, peerFactory]) => {
3605
- const peer$ = peerFactory(this.sources);
3606
- this.sourceNames.forEach(source => {
3607
- if (source == this.DOMSourceName) {
3608
- acc[source][peerName] = peer$[source];
3609
- } else {
3610
- acc[source].push(peer$[source]);
3611
- }
3612
- });
3613
- return acc
3614
- }, initial);
3615
- }
3616
-
3617
- initChildSources$() {
3618
- let newSourcesNext;
3619
- const childSources$ = xs$1.create({
3620
- start: listener => {
3621
- newSourcesNext = listener.next.bind(listener);
3622
- },
3623
- stop: _ => {
3624
-
3625
- }
3626
- }).map(sources => xs$1.merge(...sources)).flatten();
3627
-
3628
- this.sources[CHILD_SOURCE_NAME] = {
3629
- select: (name) => {
3630
- const all$ = childSources$;
3631
- const filtered$ = name ? all$.filter(entry => entry.name === name) : all$;
3632
- const unwrapped$ = filtered$.map(entry => entry.value);
3633
- return unwrapped$
3634
- }
3635
- };
3636
-
3637
- this.newChildSources = (sources) => {
3638
- if (typeof newSourcesNext === 'function') newSourcesNext(sources);
3639
- };
3640
- }
3641
-
3642
- initSubComponentSink$() {
3643
- const subComponentSink$ = xs$1.create({
3644
- start: listener => {
3645
- this.newSubComponentSinks = listener.next.bind(listener);
3646
- },
3647
- stop: _ => {
3648
-
3649
- }
3650
- });
3651
- subComponentSink$.subscribe({ next: _ => _ });
3652
- this.subComponentSink$ = subComponentSink$.filter(sinks => Object.keys(sinks).length > 0);
3653
- }
3654
-
3655
- initSubComponentsRendered$() {
3656
- const stream = xs$1.create({
3657
- start: (listener) => {
3658
- this.triggerSubComponentsRendered = listener.next.bind(listener);
3659
- },
3660
- stop: _ => {
3661
-
3662
- }
3663
- });
3664
- this.subComponentsRendered$ = stream.startWith(null);
3665
- }
3666
-
3667
- initVdom$() {
3668
- if (typeof this.view != 'function') {
3669
- this.vdom$ = xs$1.of(null);
3670
- return
3671
- }
3672
-
3673
- const renderParameters$ = this.collectRenderParameters();
3674
-
3675
- this.vdom$ = renderParameters$
3676
- .map(params => {
3677
- const { props, state, children, context, ...peers } = params;
3678
- const { sygnalFactory, sygnalOptions, ...sanitizedProps} = props || {};
3679
- return this.view({ ...sanitizedProps, state, children, context, peers }, state, context, peers)
3680
- })
3681
- .compose(this.log('View rendered'))
3682
- .map(vDom => vDom || { sel: 'div', data: {}, children: [] })
3683
- .compose(this.instantiateSubComponents.bind(this))
3684
- .filter(val => val !== undefined)
3685
- .compose(this.renderVdom.bind(this));
3686
-
3687
- }
3688
-
3689
- initSinks() {
3690
- this.sinks = this.sourceNames.reduce((acc, name) => {
3691
- if (name == this.DOMSourceName) return acc
3692
- const subComponentSink$ = (this.subComponentSink$ && name !== PARENT_SINK_NAME) ? this.subComponentSink$.map(sinks => sinks[name]).filter(sink => !!sink).flatten() : xs$1.never();
3693
- if (name === this.stateSourceName) {
3694
- acc[name] = xs$1.merge((this.model$[name] || xs$1.never()), subComponentSink$, this.sources[this.stateSourceName].stream.filter(_ => false), ...(this.peers$[name] || []));
3695
- } else {
3696
- acc[name] = xs$1.merge((this.model$[name] || xs$1.never()), subComponentSink$, ...(this.peers$[name] || []));
3697
- }
3698
- return acc
3699
- }, {});
3700
-
3701
- this.sinks[this.DOMSourceName] = this.vdom$;
3702
- this.sinks[PARENT_SINK_NAME] = this.model$[PARENT_SINK_NAME] || xs$1.never();
3703
- }
3704
-
3705
- makeOnAction(action$, isStateSink=true, rootAction$) {
3706
- rootAction$ = rootAction$ || action$;
3707
- return (name, reducer) => {
3708
- const filtered$ = action$.filter(({type}) => type == name);
3709
-
3710
- let returnStream$;
3711
- if (typeof reducer === 'function') {
3712
- returnStream$ = filtered$.map(action => {
3713
- const next = (type, data, delay=10) => {
3714
- if (typeof delay !== 'number') throw new Error(`[${ this.name } ] Invalid delay value provided to next() function in model action '${ name }'. Must be a number in ms.`)
3715
- // put the "next" action request at the end of the event loop so the "current" action completes first
3716
- setTimeout(() => {
3717
- // push the "next" action request into the action$ stream
3718
- rootAction$.shamefullySendNext({ type, data });
3719
- }, delay);
3720
- this.log(`<${ name }> Triggered a next() action: <${ type }> ${ delay }ms delay`, true);
3721
- };
3722
-
3723
- const props = { ...this.currentProps, children: this.currentChildren, context: this.currentContext };
3724
-
3725
- let data = action.data;
3726
- if (isStateSink) {
3727
- return (state) => {
3728
- const _state = this.isSubComponent ? this.currentState : state;
3729
- const enhancedState = this.addCalculated(_state);
3730
- props.state = enhancedState;
3731
- const newState = reducer(enhancedState, data, next, props);
3732
- if (newState == ABORT$1) return _state
3733
- return this.cleanupCalculated(newState)
3734
- }
3735
- } else {
3736
- const enhancedState = this.addCalculated(this.currentState);
3737
- props.state = enhancedState;
3738
- const reduced = reducer(enhancedState, data, next, props);
3739
- const type = typeof reduced;
3740
- if (isObj(reduced) || ['string', 'number', 'boolean', 'function'].includes(type)) return reduced
3741
- if (type == 'undefined') {
3742
- console.warn(`'undefined' value sent to ${ name }`);
3743
- return reduced
3744
- }
3745
- throw new Error(`Invalid reducer type for ${ name } ${ type }`)
3746
- }
3747
- }).filter(result => result != ABORT$1);
3748
- } else if (reducer === undefined || reducer === true) {
3749
- returnStream$ = filtered$.map(({data}) => data);
3750
- } else {
3751
- const value = reducer;
3752
- returnStream$ = filtered$.mapTo(value);
3753
- }
3754
-
3755
- return returnStream$
3756
- }
3757
- }
3758
-
3759
- createMemoizedAddCalculated() {
3760
- let lastState;
3761
- let lastResult;
3762
-
3763
- return function(state) {
3764
- if (!this.calculated || !isObj(state) || Array.isArray(state)) return state
3765
- if (state === lastState) {
3766
- return lastResult
3767
- }
3768
- if (!isObj(this.calculated)) throw new Error(`'calculated' parameter must be an object mapping calculated state field named to functions`)
3769
-
3770
- const calculated = this.getCalculatedValues(state);
3771
- if (!calculated) {
3772
- lastState = state;
3773
- lastResult = state;
3774
- return state
3775
- }
3776
-
3777
- const newState = { ...state, ...calculated };
3778
-
3779
- lastState = state;
3780
- lastResult = newState;
3781
-
3782
- return newState
3783
- }
3784
- }
3785
-
3786
- getCalculatedValues(state) {
3787
- const entries = Object.entries(this.calculated || {});
3788
- if (entries.length === 0) {
3789
- return
3790
- }
3791
- return entries.reduce((acc, [field, fn]) => {
3792
- if (typeof fn !== 'function') throw new Error(`Missing or invalid calculator function for calculated field '${ field }`)
3793
- try {
3794
- acc[field] = fn(state);
3795
- } catch(e) {
3796
- console.warn(`Calculated field '${ field }' threw an error during calculation: ${ e.message }`);
3797
- }
3798
- return acc
3799
- }, {})
3800
- }
3801
-
3802
- cleanupCalculated(incomingState) {
3803
- if (!incomingState || !isObj(incomingState) || Array.isArray(incomingState)) return incomingState
3804
- const state = this.storeCalculatedInState ? this.addCalculated(incomingState) : incomingState;
3805
- const copy = { ...state };
3806
- if (!this.calculated || this.storeCalculatedInState) return copy
3807
- const keys = Object.keys(this.calculated);
3808
- keys.forEach(key => {
3809
- if (this.initialState && typeof this.initialState[key] !== 'undefined') {
3810
- copy[key] = this.initialState[key];
3811
- } else {
3812
- delete copy[key];
3813
- }
3814
- });
3815
- return copy
3816
- }
3817
-
3818
- collectRenderParameters() {
3819
- const state = this.sources[this.stateSourceName];
3820
- const renderParams = { ...this.peers$[this.DOMSourceName] };
3821
-
3822
- const enhancedState = state && state.isolateSource(state, { get: state => this.addCalculated(state) });
3823
- const stateStream = (enhancedState && enhancedState.stream) || xs$1.never();
3824
-
3825
-
3826
- renderParams.state = stateStream.compose(_default$3(objIsEqual));
3827
-
3828
- if (this.sources.props$) {
3829
- renderParams.props = this.sources.props$.compose(_default$3(propsIsEqual));
3830
- }
3831
-
3832
- if (this.sources.children$) {
3833
- renderParams.children = this.sources.children$.compose(_default$3(objIsEqual));
3834
- }
3835
-
3836
- if (this.context$) {
3837
- renderParams.context = this.context$.compose(_default$3(objIsEqual));
3838
- }
3839
-
3840
- const names = [];
3841
- const streams = [];
3842
-
3843
- Object.entries(renderParams).forEach(([name, stream]) => {
3844
- names.push(name);
3845
- streams.push(stream);
3846
- });
3847
-
3848
- const combined = xs$1.combine(...streams)
3849
- .compose(_default(1))
3850
- // map the streams from an array back to an object with the render parameter names as the keys
3851
- .map(arr => {
3852
- const params = names.reduce((acc, name, index) => {
3853
- acc[name] = arr[index];
3854
- if (name === 'state') {
3855
- acc[this.stateSourceName] = arr[index];
3856
- acc.calculated = (arr[index] && this.getCalculatedValues(arr[index])) || {};
3857
- }
3858
- return acc
3859
- }, {});
3860
- return params
3861
- });
3862
-
3863
- return combined
3864
- }
3865
-
3866
- instantiateSubComponents(vDom$) {
3867
- return vDom$.fold((previousComponents, vDom) => {
3868
- const componentNames = Object.keys(this.components);
3869
- const foundComponents = getComponents(vDom, componentNames);
3870
- const entries = Object.entries(foundComponents);
3871
-
3872
- const rootEntry = { '::ROOT::': vDom };
3873
-
3874
- if (entries.length === 0) {
3875
- return rootEntry
3876
- }
3877
-
3878
- const sinkArrsByType = {};
3879
- const childSources = [];
3880
- let newInstanceCount = 0;
3881
-
3882
- const newComponents = entries.reduce((acc, [id, el]) => {
3883
- const data = el.data;
3884
- const props = data.props || {};
3885
- const children = el.children || [];
3886
-
3887
- const isCollection = data.isCollection || false;
3888
- const isSwitchable = data.isSwitchable || false;
3889
-
3890
- const addSinks = (sinks) => {
3891
- Object.entries(sinks).forEach(([name, stream]) => {
3892
- sinkArrsByType[name] ||= [];
3893
- if (name === PARENT_SINK_NAME) {
3894
- childSources.push(stream);
3895
- } else if (name !== this.DOMSourceName) {
3896
- sinkArrsByType[name].push(stream);
3897
- }
3898
- });
3899
- };
3900
-
3901
-
3902
- if (previousComponents[id]) {
3903
- const entry = previousComponents[id];
3904
- acc[id] = entry;
3905
- entry.props$.shamefullySendNext(props);
3906
- entry.children$.shamefullySendNext(children);
3907
- addSinks(entry.sink$);
3908
- return acc
3909
- }
3910
-
3911
- const props$ = xs$1.create().startWith(props);
3912
- const children$ = xs$1.create().startWith(children);
3913
-
3914
- let instantiator;
3915
-
3916
- if (isCollection) {
3917
- instantiator = this.instantiateCollection.bind(this);
3918
- } else if (isSwitchable) {
3919
- instantiator = this.instantiateSwitchable.bind(this);
3920
- } else {
3921
- instantiator = this.instantiateCustomComponent.bind(this);
3922
- }
3923
-
3924
- newInstanceCount++;
3925
-
3926
- const sink$ = instantiator(el, props$, children$);
3927
-
3928
- sink$[this.DOMSourceName] = sink$[this.DOMSourceName] ? this.makeCoordinatedSubComponentDomSink(sink$[this.DOMSourceName]) : xs$1.never();
3929
-
3930
- acc[id] = { sink$, props$, children$ };
3931
-
3932
- addSinks(sink$);
3933
-
3934
- return acc
3935
- }, rootEntry);
3936
-
3937
- const mergedSinksByType = Object.entries(sinkArrsByType).reduce((acc, [name, streamArr]) => {
3938
- if (streamArr.length === 0) return acc
3939
- acc[name] = streamArr.length === 1 ? streamArr[0] : xs$1.merge(...streamArr);
3940
- return acc
3941
- }, {});
3942
-
3943
- this.newSubComponentSinks(mergedSinksByType);
3944
- this.newChildSources(childSources);
3945
-
3946
-
3947
- if (newInstanceCount > 0) this.log(`New sub components instantiated: ${ newInstanceCount }`, true);
3948
-
3949
- return newComponents
3950
- }, {})
3951
- }
3952
-
3953
- makeCoordinatedSubComponentDomSink(domSink$) {
3954
- const remembered$ = domSink$.remember();
3955
-
3956
- const coordinated = this.sources[this.stateSourceName].stream
3957
- .compose(_default$3(objIsEqual))
3958
- .map(state => remembered$)
3959
- .flatten()
3960
- .debug(_ => this.triggerSubComponentsRendered())
3961
- .remember();
3962
-
3963
- return coordinated
3964
- }
3965
-
3966
- instantiateCollection(el, props$, children$) {
3967
- const data = el.data;
3968
- const props = data.props || {};
3969
- let filter = typeof props.filter === 'function' ? props.filter : undefined;
3970
- let sort = sortFunctionFromProp(props.sort);
3971
-
3972
- const arrayOperators = {
3973
- filter,
3974
- sort
3975
- };
3976
-
3977
- const state$ = xs$1.combine(this.sources[this.stateSourceName].stream.startWith(this.currentState), props$.startWith(props))
3978
- // this debounce is important. it forces state and prop updates to happen at the same time
3979
- // without this, changes to sort or filter won't happen properly
3980
- .compose(_default(1))
3981
- .map(([state, props]) => {
3982
- if (props.filter !== arrayOperators.filter) {
3983
- arrayOperators.filter = typeof props.filter === 'function' ? props.filter : undefined;
3984
- }
3985
- if (props.sort !== arrayOperators.sort) {
3986
- arrayOperators.sort = sortFunctionFromProp(props.sort);
3987
- }
3988
-
3989
- return isObj(state) ? this.addCalculated(state) : state
3990
- });
3991
-
3992
- const stateSource = new StateSource(state$);
3993
- const stateField = props.from;
3994
- const collectionOf = props.of;
3995
- const idField = props.idfield || 'id';
3996
-
3997
- let lense;
3998
- let factory;
3999
-
4000
- if (typeof collectionOf === 'function') {
4001
- if (collectionOf.isSygnalComponent) {
4002
- factory = collectionOf;
4003
- } else {
4004
- const name = collectionOf.componentName || collectionOf.label || collectionOf.name || 'FUNCTION_COMPONENT';
4005
- const view = collectionOf;
4006
- const { model, intent, hmrActions, context, peers, components, initialState, calculated, storeCalculatedInState, DOMSourceName, stateSourceName, debug } = collectionOf;
4007
- const options = { name, view, model, intent, hmrActions, context, peers, components, initialState, calculated, storeCalculatedInState, DOMSourceName, stateSourceName, debug };
4008
- factory = component(options);
4009
- }
4010
- } else if (this.components[collectionOf]) {
4011
- factory = this.components[collectionOf];
4012
- } else {
4013
- throw new Error(`[${this.name}] Invalid 'of' propery in collection: ${ collectionOf }`)
4014
- }
4015
-
4016
- const fieldLense = {
4017
- get: state => {
4018
- if (!Array.isArray(state[stateField])) return []
4019
- const items = state[stateField];
4020
- const filtered = typeof arrayOperators.filter === 'function' ? items.filter(arrayOperators.filter) : items;
4021
- const sorted = typeof arrayOperators.sort ? filtered.sort(arrayOperators.sort) : filtered;
4022
- const mapped = sorted.map((item, index) => {
4023
- return (isObj(item)) ? { ...item, [idField]: item[idField] || index } : { value: item, [idField]: index }
4024
- });
4025
-
4026
- return mapped
4027
- },
4028
- set: (oldState, newState) => {
4029
- if (this.calculated && stateField in this.calculated) {
4030
- console.warn(`Collection sub-component of ${ this.name } attempted to update state on a calculated field '${ stateField }': Update ignored`);
4031
- return oldState
4032
- }
4033
- const updated = [];
4034
- for (const oldItem of oldState[stateField].map((item, index) => (isObj(item) ? { ...item, [idField]: item[idField] || index } : { __primitive: true, value: item, [idField]: index }))) {
4035
- if (typeof arrayOperators.filter === 'function' && !arrayOperators.filter(oldItem)) {
4036
- updated.push(oldItem.__primitive ? oldItem.value : oldItem);
4037
- } else {
4038
- const newItem = newState.find(item => item[idField] === oldItem[idField]);
4039
- if (typeof newItem !== 'undefined') updated.push(oldItem.__primitive ? newItem.value : newItem);
4040
- }
4041
- }
4042
- return { ...oldState, [stateField]: updated }
4043
- }
4044
- };
4045
-
4046
- if (stateField === undefined) {
4047
- lense = {
4048
- get: state => {
4049
- if (!(state instanceof Array) && state.value && state.value instanceof Array) return state.value
4050
- return state
4051
- },
4052
- set: (oldState, newState) => {
4053
- return newState
4054
- }
4055
- };
4056
- } else if (typeof stateField === 'string') {
4057
- if (isObj(this.currentState)) {
4058
- if(!(this.currentState && stateField in this.currentState) && !(this.calculated && stateField in this.calculated)) {
4059
- console.error(`Collection component in ${ this.name } is attempting to use non-existent state property '${ stateField }': To fix this error, specify a valid array property on the state. Attempting to use parent component state.`);
4060
- lense = undefined;
4061
- } else if (!Array.isArray(this.currentState[stateField])) {
4062
- console.warn(`State property '${ stateField }' in collection comopnent of ${ this.name } is not an array: No components will be instantiated in the collection.`);
4063
- lense = fieldLense;
4064
- } else {
4065
- lense = fieldLense;
4066
- }
4067
- } else {
4068
- if (!Array.isArray(this.currentState[stateField])) {
4069
- console.warn(`State property '${ stateField }' in collection component of ${ this.name } is not an array: No components will be instantiated in the collection.`);
4070
- lense = fieldLense;
4071
- } else {
4072
- lense = fieldLense;
4073
- }
4074
- }
4075
- } else if (isObj(stateField)) {
4076
- if (typeof stateField.get !== 'function') {
4077
- console.error(`Collection component in ${ this.name } has an invalid 'from' field: Expecting 'undefined', a string indicating an array property in the state, or an object with 'get' and 'set' functions for retrieving and setting child state from the current state. Attempting to use parent component state.`);
4078
- lense = undefined;
4079
- } else {
4080
- lense = {
4081
- get: (state) => {
4082
- const newState = stateField.get(state);
4083
- if (!Array.isArray(newState)) {
4084
- console.warn(`State getter function in collection component of ${ this.name } did not return an array: No components will be instantiated in the collection. Returned value:`, newState);
4085
- return []
4086
- }
4087
- return newState
4088
- },
4089
- set: stateField.set
4090
- };
4091
- }
4092
- } else {
4093
- console.error(`Collection component in ${ this.name } has an invalid 'from' field: Expecting 'undefined', a string indicating an array property in the state, or an object with 'get' and 'set' functions for retrieving and setting child state from the current state. Attempting to use parent component state.`);
4094
- lense = undefined;
4095
- }
4096
-
4097
- const sources = { ...this.sources, [this.stateSourceName]: stateSource, props$, children$, __parentContext$: this.context$, PARENT: null };
4098
- const sink$ = collection(factory, lense, { container: null })(sources);
4099
- if (!isObj(sink$)) {
4100
- throw new Error('Invalid sinks returned from component factory of collection element')
4101
- }
4102
- return sink$
4103
- }
4104
-
4105
- instantiateSwitchable(el, props$, children$) {
4106
- const data = el.data;
4107
- const props = data.props || {};
4108
-
4109
- const state$ = this.sources[this.stateSourceName].stream.startWith(this.currentState)
4110
- .map((state) => {
4111
- return isObj(state) ? this.addCalculated(state) : state
4112
- });
4113
-
4114
- const stateSource = new StateSource(state$);
4115
- const stateField = props.state;
4116
- let lense;
4117
-
4118
- const fieldLense = {
4119
- get: state => state[stateField],
4120
- set: (oldState, newState) => {
4121
- if (this.calculated && stateField in this.calculated) {
4122
- console.warn(`Switchable sub-component of ${ this.name } attempted to update state on a calculated field '${ stateField }': Update ignored`);
4123
- return oldState
4124
- }
4125
- if (!isObj(newState) || Array.isArray(newState)) return { ...oldState, [stateField]: newState }
4126
- return { ...oldState, [stateField]: newState }
4127
- }
4128
- };
4129
-
4130
- const baseLense = {
4131
- get: state => state,
4132
- set: (oldState, newState) => newState
4133
- };
4134
-
4135
- if (typeof stateField === 'undefined') {
4136
- lense = baseLense;
4137
- } else if (typeof stateField === 'string') {
4138
- lense = fieldLense;
4139
- } else if (isObj(stateField)) {
4140
- if (typeof stateField.get !== 'function') {
4141
- console.error(`Switchable component in ${ this.name } has an invalid 'state' field: Expecting 'undefined', a string indicating an array property in the state, or an object with 'get' and 'set' functions for retrieving and setting sub-component state from the current state. Attempting to use parent component state.`);
4142
- lense = baseLense;
4143
- } else {
4144
- lense = { get: stateField.get, set: stateField.set };
4145
- }
4146
- } else {
4147
- console.error(`Invalid state provided to switchable sub-component of ${ this.name }: Expecting string, object, or undefined, but found ${ typeof stateField }. Attempting to use parent component state.`);
4148
- lense = baseLense;
4149
- }
4150
-
4151
- const switchableComponents = props.of;
4152
- const keys = Object.keys(switchableComponents);
4153
- keys.forEach(key => {
4154
- const current = switchableComponents[key];
4155
- if (!current.isSygnalComponent) {
4156
- const name = current.componentName || current.label || current.name || 'FUNCTION_COMPONENT';
4157
- const view = current;
4158
- const { model, intent, hmrActions, context, peers, components, initialState, calculated, storeCalculatedInState, DOMSourceName, stateSourceName, debug } = current;
4159
- const options = { name, view, model, intent, hmrActions, context, peers, components, initialState, calculated, storeCalculatedInState, DOMSourceName, stateSourceName, debug };
4160
- switchableComponents[key] = component(options);
4161
- }
4162
- });
4163
- const sources = { ...this.sources, [this.stateSourceName]: stateSource, props$, children$, __parentContext$: this.context$ };
4164
-
4165
- const sink$ = isolate(switchable(switchableComponents, props$.map(props => props.current)), { [this.stateSourceName]: lense })(sources);
4166
-
4167
- if (!isObj(sink$)) {
4168
- throw new Error('Invalid sinks returned from component factory of switchable element')
4169
- }
4170
-
4171
- return sink$
4172
- }
4173
-
4174
- instantiateCustomComponent(el, props$, children$) {
4175
- const componentName = el.sel;
4176
- const data = el.data;
4177
- const props = data.props || {};
4178
-
4179
- const state$ = this.sources[this.stateSourceName].stream.startWith(this.currentState)
4180
- .map((state) => {
4181
- return isObj(state) ? this.addCalculated(state) : state
4182
- });
4183
-
4184
- const stateSource = new StateSource(state$);
4185
- const stateField = props.state;
4186
-
4187
- if (typeof props.sygnalFactory !== 'function' && isObj(props.sygnalOptions)) {
4188
- props.sygnalFactory = component(props.sygnalOptions);
4189
- }
4190
-
4191
- const factory = componentName === 'sygnal-factory' ? props.sygnalFactory : (this.components[componentName] || props.sygnalFactory);
4192
- if (!factory) {
4193
- if (componentName === 'sygnal-factory') throw new Error(`Component not found on element with Capitalized selector and nameless function: JSX transpilation replaces selectors starting with upper case letters with functions in-scope with the same name, Sygnal cannot see the name of the resulting component.`)
4194
- throw new Error(`Component not found: ${ componentName }`)
4195
- }
4196
-
4197
- let lense;
4198
-
4199
- const fieldLense = {
4200
- get: state => state[stateField],
4201
- set: (oldState, newState) => {
4202
- if (this.calculated && stateField in this.calculated) {
4203
- console.warn(`Sub-component of ${ this.name } attempted to update state on a calculated field '${ stateField }': Update ignored`);
4204
- return oldState
4205
- }
4206
- return { ...oldState, [stateField]: newState }
4207
- }
4208
- };
4209
-
4210
- const baseLense = {
4211
- get: state => state,
4212
- set: (oldState, newState) => newState
4213
- };
4214
-
4215
- if (typeof stateField === 'undefined') {
4216
- lense = baseLense;
4217
- } else if (typeof stateField === 'string') {
4218
- lense = fieldLense;
4219
- } else if (isObj(stateField)) {
4220
- if (typeof stateField.get !== 'function') {
4221
- console.error(`Sub-component in ${ this.name } has an invalid 'state' field: Expecting 'undefined', a string indicating an array property in the state, or an object with 'get' and 'set' functions for retrieving and setting sub-component state from the current state. Attempting to use parent component state.`);
4222
- lense = baseLense;
4223
- } else {
4224
- lense = { get: stateField.get, set: stateField.set };
4225
- }
4226
- } else {
4227
- console.error(`Invalid state provided to sub-component of ${ this.name }: Expecting string, object, or undefined, but found ${ typeof stateField }. Attempting to use parent component state.`);
4228
- lense = baseLense;
4229
- }
4230
-
4231
- const sources = { ...this.sources, [this.stateSourceName]: stateSource, props$, children$, __parentContext$: this.context$ };
4232
- const sink$ = isolate(factory, { [this.stateSourceName]: lense })(sources);
4233
-
4234
- if (!isObj(sink$)) {
4235
- const name = componentName === 'sygnal-factory' ? 'custom element' : componentName;
4236
- throw new Error('Invalid sinks returned from component factory:', name)
4237
- }
4238
-
4239
- return sink$
4240
- }
4241
-
4242
- renderVdom(componentInstances$) {
4243
- return xs$1.combine(this.subComponentsRendered$, componentInstances$)
4244
- .compose(_default(1))
4245
- .map(([_, components]) => {
4246
- const componentNames = Object.keys(this.components);
4247
-
4248
- const root = components['::ROOT::'];
4249
- const entries = Object.entries(components).filter(([id]) => id !== '::ROOT::');
4250
-
4251
- if (entries.length === 0) {
4252
- return xs$1.of(root)
4253
- }
4254
-
4255
- const ids = [];
4256
- const vdom$ = entries
4257
- .map(([id, val]) => {
4258
- ids.push(id);
4259
- return val.sink$[this.DOMSourceName].startWith(undefined)
4260
- });
4261
-
4262
- if (vdom$.length === 0) return xs$1.of(root)
4263
-
4264
- return xs$1.combine(...vdom$)
4265
- .compose(_default(1))
4266
- .map(vdoms => {
4267
- const withIds = vdoms.reduce((acc, vdom, index) => {
4268
- acc[ids[index]] = vdom;
4269
- return acc
4270
- }, {});
4271
- const rootCopy = deepCopyVdom(root);
4272
- const injected = injectComponents(rootCopy, withIds, componentNames);
4273
- return injected
4274
- })
4275
- })
4276
- .flatten()
4277
- .filter(val => !!val)
4278
- .remember()
4279
- }
4280
-
4281
- }
4282
-
4283
-
4284
-
4285
-
4286
-
4287
-
4288
-
4289
- /**
4290
- * factory to create a logging function meant to be used inside of an xstream .compose()
4291
- *
4292
- * @param {String} context name of the component or file to be prepended to any messages
4293
- * @return {Function}
4294
- *
4295
- * returned function accepts either a `String` of `Function`
4296
- * `String` values will be logged to `console` as is
4297
- * `Function` values will be called with the current `stream` value and the result will be logged to `console`
4298
- * all output will be prepended with the `context` (ex. "[CONTEXT] My output")
4299
- * ONLY outputs if the global `DEBUG` variable is set to `true`
4300
- */
4301
- function makeLog (context) {
4302
- return function (msg, immediate=false) {
4303
- const fixedMsg = (typeof msg === 'function') ? msg : _ => msg;
4304
- if (immediate) {
4305
- if (this.debug) {
4306
- console.log(`[${context}] ${fixedMsg(msg)}`);
4307
- }
4308
- return
4309
- } else {
4310
- return stream => {
4311
- return stream.debug(msg => {
4312
- if (this.debug) {
4313
- console.log(`[${context}] ${fixedMsg(msg)}`);
4314
- }
4315
- })
4316
- }
4317
- }
4318
- }
4319
- }
4320
-
4321
-
4322
-
4323
- function getComponents(currentElement, componentNames, depth=0, index=0, parentId) {
4324
- if (!currentElement) return {}
4325
-
4326
- if (currentElement.data?.componentsProcessed) return {}
4327
- if (depth === 0) currentElement.data.componentsProcessed = true;
4328
-
4329
- const sel = currentElement.sel;
4330
- const isCollection = sel && sel.toLowerCase() === 'collection';
4331
- const isSwitchable = sel && sel.toLowerCase() === 'switchable';
4332
- const isComponent = sel && (['collection', 'switchable', 'sygnal-factory', ...componentNames].includes(sel)) || typeof currentElement.data?.props?.sygnalFactory === 'function' || isObj(currentElement.data?.props?.sygnalOptions);
4333
- const props = (currentElement.data && currentElement.data.props) || {};
4334
- (currentElement.data && currentElement.data.attrs) || {};
4335
- const children = currentElement.children || [];
4336
-
4337
- let found = {};
4338
-
4339
- let id = parentId;
4340
- if (isComponent) {
4341
- id = getComponentIdFromElement(currentElement, depth, index, parentId);
4342
- if (isCollection) {
4343
- if (!props.of) throw new Error(`Collection element missing required 'component' property`)
4344
- if (typeof props.of !== 'string' && typeof props.of !== 'function') throw new Error(`Invalid 'component' property of collection element: found ${ typeof props.of } requires string or component factory function`)
4345
- if (typeof props.of !== 'function' && !componentNames.includes(props.of)) throw new Error(`Specified component for collection not found: ${ props.of }`)
4346
- if (typeof props.from !== 'undefined' && !(typeof props.from === 'string' || Array.isArray(props.from) || typeof props.from.get === 'function')) console.warn(`No valid array found for collection ${ typeof props.of === 'string' ? props.of : 'function component' }: no collection components will be created`, props.from);
4347
- currentElement.data.isCollection = true;
4348
- currentElement.data.props ||= {};
4349
- } else if (isSwitchable) {
4350
- if (!props.of) throw new Error(`Switchable element missing required 'of' property`)
4351
- if (!isObj(props.of)) throw new Error(`Invalid 'of' property of switchable element: found ${ typeof props.of } requires object mapping names to component factories`)
4352
- const switchableComponents = Object.values(props.of);
4353
- if (!switchableComponents.every(comp => typeof comp === 'function')) throw new Error(`One or more components provided to switchable element is not a valid component factory`)
4354
- if (!props.current || (typeof props.current !== 'string' && typeof props.current !== 'function')) throw new Error(`Missing or invalid 'current' property for switchable element: found '${ typeof props.current }' requires string or function`)
4355
- const switchableComponentNames = Object.keys(props.of);
4356
- if (!switchableComponentNames.includes(props.current)) throw new Error(`Component '${ props.current }' not found in switchable element`)
4357
- currentElement.data.isSwitchable = true;
4358
- } else ;
4359
- if (typeof props.key === 'undefined') currentElement.data.props.key = id;
4360
- found[id] = currentElement;
4361
- }
4362
-
4363
- if (children.length > 0) {
4364
- children.map((child, i) => getComponents(child, componentNames, depth + 1, index + i, id))
4365
- .forEach((child) => {
4366
- Object.entries(child).forEach(([id, el]) => found[id] = el);
4367
- });
4368
- }
4369
-
4370
- return found
4371
- }
4372
-
4373
- function injectComponents(currentElement, components, componentNames, depth=0, index=0, parentId) {
4374
- if (!currentElement) return
4375
- if (currentElement.data?.componentsInjected) return currentElement
4376
- if (depth === 0 && currentElement.data) currentElement.data.componentsInjected = true;
4377
-
4378
-
4379
- const sel = currentElement.sel || 'NO SELECTOR';
4380
- const isComponent = ['collection', 'switchable', 'sygnal-factory', ...componentNames].includes(sel) || typeof currentElement.data?.props?.sygnalFactory === 'function' || isObj(currentElement.data?.props?.sygnalOptions);
4381
- const isCollection = currentElement?.data?.isCollection;
4382
- const isSwitchable = currentElement?.data?.isSwitchable;
4383
- (currentElement.data && currentElement.data.props) || {};
4384
- const children = currentElement.children || [];
4385
-
4386
- let id = parentId;
4387
- if (isComponent) {
4388
- id = getComponentIdFromElement(currentElement, depth, index, parentId);
4389
- const component = components[id];
4390
- if (isCollection) {
4391
- currentElement.sel = 'div';
4392
- currentElement.children = Array.isArray(component) ? component : [component];
4393
- return currentElement
4394
- } else if (isSwitchable) {
4395
- return component
4396
- } else {
4397
- return component
4398
- }
4399
- } else if (children.length > 0) {
4400
- currentElement.children = children.map((child, i) => injectComponents(child, components, componentNames, depth + 1, index + i, id)).flat();
4401
- return currentElement
4402
- } else {
4403
- return currentElement
4404
- }
4405
- }
4406
-
4407
- function getComponentIdFromElement(el, depth, index, parentId) {
4408
- const sel = el.sel;
4409
- const name = typeof sel === 'string' ? sel : 'functionComponent';
4410
- const uid = `${depth}:${index}`;
4411
- const props = el.data?.props || {};
4412
- const id = (props.id && JSON.stringify(props.id).replaceAll('"', '')) || uid;
4413
- const parentString = parentId ? `${ parentId }|` : '';
4414
- const fullId = `${ parentString }${ name }::${ id }`;
4415
- return fullId
4416
- }
4417
-
4418
-
4419
- function deepCopyVdom(obj) {
4420
- if (typeof obj === 'undefined') return obj
4421
- return { ...obj, children: Array.isArray(obj.children) ? obj.children.map(deepCopyVdom) : undefined, data: obj.data && { ...obj.data, componentsInjected: false } }
4422
- }
4423
-
4424
- function propsIsEqual(obj1, obj2) {
4425
- return objIsEqual(sanitizeObject(obj1))
4426
- }
4427
-
4428
- function objIsEqual(obj1, obj2, maxDepth = 5, depth = 0) {
4429
- // Base case: if the current depth exceeds maxDepth, return true
4430
- if (depth > maxDepth) {
4431
- return false;
4432
- }
4433
-
4434
- // If both are the same object or are both exactly null or undefined
4435
- if (obj1 === obj2) {
4436
- return true;
4437
- }
4438
-
4439
- // If either is not an object (null, undefined, or primitive), directly compare
4440
- if (typeof obj1 !== 'object' || obj1 === null || typeof obj2 !== 'object' || obj2 === null) {
4441
- return false;
4442
- }
4443
-
4444
- // Special handling for arrays
4445
- if (Array.isArray(obj1) && Array.isArray(obj2)) {
4446
- if (obj1.length !== obj2.length) {
4447
- return false;
4448
- }
4449
- for (let i = 0; i < obj1.length; i++) {
4450
- if (!objIsEqual(obj1[i], obj2[i], maxDepth, depth + 1)) {
4451
- return false;
4452
- }
4453
- }
4454
- return true;
4455
- }
4456
-
4457
- // Get keys of both objects
4458
- const keys1 = Object.keys(obj1);
4459
- const keys2 = Object.keys(obj2);
4460
-
4461
- // Check if the number of properties is different
4462
- if (keys1.length !== keys2.length) {
4463
- return false;
4464
- }
4465
-
4466
- // Recursively check each property
4467
- for (const key of keys1) {
4468
- if (!keys2.includes(key)) {
4469
- return false;
4470
- }
4471
- if (!objIsEqual(obj1[key], obj2[key], maxDepth, depth + 1)) {
4472
- return false;
4473
- }
4474
- }
4475
-
4476
- return true;
4477
- }
4478
-
4479
- function sanitizeObject(obj) {
4480
- if (!isObj(obj)) return obj
4481
- const {state, of, from, filter, ...sanitized} = obj;
4482
- return sanitized
4483
- }
4484
-
4485
- function isObj(obj) {
4486
- return typeof obj === 'object' && obj !== null && !Array.isArray(obj)
4487
- }
4488
-
4489
- function __baseSort(a, b, ascending=true) {
4490
- const direction = ascending ? 1 : -1;
4491
- switch(true) {
4492
- case a > b: return 1 * direction
4493
- case a < b: return -1 * direction
4494
- default: return 0
4495
- }
4496
- }
4497
-
4498
- function __sortFunctionFromObj(item) {
4499
- const entries = Object.entries(item);
4500
- if (entries.length > 1) {
4501
- console.error('Sort objects can only have one key:', item);
4502
- return undefined
4503
- }
4504
- const entry = entries[0];
4505
- const [field, directionRaw] = entry;
4506
- if (!['string', 'number'].includes(typeof directionRaw)) {
4507
- console.error('Sort object properties must be a string or number:', item);
4508
- return undefined
4509
- }
4510
- let ascending = true;
4511
- if (typeof directionRaw === 'string') {
4512
- if (!['asc', 'dec'].includes(directionRaw.toLowerCase())) {
4513
- console.error('Sort object string values must be asc or dec:', item);
4514
- return undefined
4515
- }
4516
- ascending = directionRaw.toLowerCase() === 'asc';
4517
- }
4518
- if (typeof directionRaw === 'number') {
4519
- if (directionRaw !== 1 && directionRaw !== -1) {
4520
- console.error('Sort object number values must be 1 or -1:', item);
4521
- return undefined
4522
- }
4523
- ascending = directionRaw === 1;
4524
- }
4525
- return (a, b) => __baseSort(a[field], b[field], ascending)
4526
- }
4527
-
4528
- function sortFunctionFromProp(sortProp) {
4529
- if (!sortProp) return undefined
4530
- const propType = typeof sortProp;
4531
- // if function do nothing
4532
- if (propType === 'function') return sortProp
4533
- if (propType === 'string') {
4534
- // if passed either 'asc' or 'dec' sort on the entire item
4535
- if (sortProp.toLowerCase() === 'asc' || sortProp.toLowerCase() === 'dec') {
4536
- const ascending = sortProp.toLowerCase() === 'asc';
4537
- return (a, b) => __baseSort(a, b, ascending)
4538
- }
4539
- // assume it's a field/property name, and sort it ascending
4540
- const field = sortProp;
4541
- return (a, b) => __baseSort(a[field], b[field], true)
4542
- } else if (Array.isArray(sortProp)) {
4543
- const sorters = sortProp.map(item => {
4544
- if (typeof item === 'function') return item
4545
- if (typeof item === 'string' && !['asc', 'dec'].includes(item.toLowerCase())) return (a, b) => __baseSort(a[item], b[item], true)
4546
- if (isObj(item)) {
4547
- return __sortFunctionFromObj(item)
4548
- }
4549
- });
4550
-
4551
- return (a, b) => sorters.filter(sorter => typeof sorter === 'function').reduce((comparisonSoFar, currentSorter) => {
4552
- if (comparisonSoFar !== 0) return comparisonSoFar
4553
- return currentSorter(a, b)
4554
- }, 0)
4555
- } else if (isObj(sortProp)) {
4556
- return __sortFunctionFromObj(sortProp)
4557
- } else {
4558
- console.error('Invalid sort option (ignoring):', item);
4559
- return undefined
4560
- }
4561
- }
4562
-
4563
- function run(app, drivers={}, options={}) {
4564
- const { mountPoint='#root', fragments=true, useDefaultDrivers=true } = options;
4565
- if (!app.isSygnalComponent) {
4566
- const name = app.name || app.componentName || app.label || "FUNCTIONAL_COMPONENT";
4567
- const view = app;
4568
- const { model, intent, hmrActions, context, peers, components, initialState, calculated, storeCalculatedInState, DOMSourceName, stateSourceName, debug } = app;
4569
- const options = { name, view, model, intent, hmrActions, context, peers, components, initialState, calculated, storeCalculatedInState, DOMSourceName, stateSourceName, debug };
4570
-
4571
- app = component(options);
4572
- }
4573
-
4574
- const wrapped = withState(app, 'STATE');
4575
-
4576
- const baseDrivers = useDefaultDrivers ? {
4577
- EVENTS: eventBusDriver,
4578
- DOM: makeDOMDriver(mountPoint, { snabbdomOptions: { experimental: { fragments } } }),
4579
- LOG: logDriver
4580
- } : {};
4581
-
4582
- const combinedDrivers = { ...baseDrivers, ...drivers };
4583
-
4584
- const { sources, sinks, run: _run } = setup(wrapped, combinedDrivers);
4585
- const dispose = _run();
4586
-
4587
- const exposed = { sources, sinks, dispose };
4588
-
4589
- const hmr = (newComponent) => {
4590
- exposed.sinks.STATE.shamefullySendNext((state) => {
4591
- window.__SYGNAL_HMR_UPDATING = true;
4592
- exposed.dispose();
4593
- const App = newComponent.default;
4594
- App.initialState = state;
4595
- const updated = run(App, drivers);
4596
- exposed.sources = updated.sources;
4597
- exposed.sinks = updated.sinks;
4598
- exposed.dispose = updated.dispose;
4599
- updated.sinks.STATE.shamefullySendNext(() => {
4600
- return { ...state }
4601
- });
4602
- updated.sources.STATE.stream.setDebugListener({
4603
- next: () => {
4604
- exposed.sources.STATE.stream.setDebugListener(null);
4605
- setTimeout(() => {
4606
- window.__SYGNAL_HMR_UPDATING = false;
4607
- }, 100);
4608
- }
4609
- });
4610
- return ABORT
4611
- });
4612
- };
4613
-
4614
- exposed.hmr = hmr;
4615
-
4616
- return exposed
4617
- }
4618
-
4619
- function looksLikeSygnalComponent(Component) {
4620
- if (typeof Component !== 'function') return false
4621
- return Boolean(
4622
- Component.isSygnalComponent ||
4623
- Component.model ||
4624
- Component.intent ||
4625
- Component.initialState ||
4626
- Component.componentName
4627
- )
4628
- }
4629
-
4630
- var client = (element) => {
4631
- return async (Component, props, _slotted, metadata) => {
4632
- if (!looksLikeSygnalComponent(Component)) return
4633
-
4634
- const mountPoint = element;
4635
- const { client } = metadata || {};
4636
- const canHydrate = element.hasAttribute('ssr');
4637
-
4638
- if (client !== 'only' && !canHydrate) return
4639
-
4640
- const previous = element.__sygnal;
4641
- if (previous && typeof previous.dispose === 'function') {
4642
- previous.dispose();
4643
- }
4644
-
4645
- const Wrapped = (args) => Component({ ...args, props: { ...(props || {}) } });
4646
- Wrapped.model = Component.model;
4647
- Wrapped.intent = Component.intent;
4648
- Wrapped.hmrActions = Component.hmrActions;
4649
- Wrapped.context = Component.context;
4650
- Wrapped.peers = Component.peers;
4651
- Wrapped.components = Component.components;
4652
- Wrapped.initialState = Component.initialState;
4653
- Wrapped.calculated = Component.calculated;
4654
- Wrapped.storeCalculatedInState = Component.storeCalculatedInState;
4655
- Wrapped.DOMSourceName = Component.DOMSourceName;
4656
- Wrapped.stateSourceName = Component.stateSourceName;
4657
- Wrapped.debug = Component.debug;
4658
- Wrapped.componentName = Component.componentName || Component.name;
4659
-
4660
- const app = run(Wrapped, {}, { mountPoint });
4661
- element.__sygnal = app;
4662
- }
4663
- };
4664
-
4665
- export { client as default };