@zajno/common 1.6.3 → 2.0.0-beta.2

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 (433) hide show
  1. package/.eslintrc.js +1 -1
  2. package/README.md +6 -1
  3. package/coverage/clover.xml +344 -1066
  4. package/coverage/coverage-final.json +31 -45
  5. package/coverage/lcov-report/__tests__/helpers/expect.ts.html +1 -1
  6. package/coverage/lcov-report/__tests__/helpers/index.html +1 -1
  7. package/coverage/lcov-report/__tests__/helpers/main.ts.html +1 -1
  8. package/coverage/lcov-report/async/arrays.ts.html +1 -1
  9. package/coverage/lcov-report/async/index.html +36 -21
  10. package/coverage/lcov-report/async/timeout.ts.html +59 -59
  11. package/coverage/lcov-report/dates/calc.ts.html +1 -1
  12. package/coverage/lcov-report/dates/convert.ts.html +1 -1
  13. package/coverage/lcov-report/dates/datex.ts.html +1 -1
  14. package/coverage/lcov-report/dates/format.ts.html +1 -1
  15. package/coverage/lcov-report/dates/index.html +1 -1
  16. package/coverage/lcov-report/dates/index.ts.html +1 -1
  17. package/coverage/lcov-report/dates/parse.ts.html +1 -1
  18. package/coverage/lcov-report/dates/period.ts.html +1 -1
  19. package/coverage/lcov-report/dates/shift.ts.html +1 -1
  20. package/coverage/lcov-report/dates/types.ts.html +1 -1
  21. package/coverage/lcov-report/dates/yearDate.ts.html +1 -1
  22. package/coverage/lcov-report/fields/index.html +1 -1
  23. package/coverage/lcov-report/fields/update.ts.html +1 -1
  24. package/coverage/lcov-report/functions/index.html +17 -17
  25. package/coverage/lcov-report/functions/safeCall.ts.html +13 -13
  26. package/coverage/lcov-report/index.html +119 -74
  27. package/coverage/lcov-report/lazy/index.html +1 -1
  28. package/coverage/lcov-report/lazy/promise.ts.html +1 -1
  29. package/coverage/lcov-report/lazy/singleton.ts.html +1 -1
  30. package/coverage/lcov-report/logger/batch.ts.html +1 -1
  31. package/coverage/lcov-report/logger/console.ts.html +1 -1
  32. package/coverage/lcov-report/logger/index.html +1 -1
  33. package/coverage/lcov-report/logger/index.ts.html +1 -1
  34. package/coverage/lcov-report/logger/named.ts.html +1 -1
  35. package/coverage/lcov-report/logger/proxy.ts.html +1 -1
  36. package/coverage/lcov-report/math/arrays.ts.html +1 -1
  37. package/coverage/lcov-report/math/calc.ts.html +1 -1
  38. package/coverage/lcov-report/math/distribution.ts.html +1 -1
  39. package/coverage/lcov-report/math/index.html +1 -1
  40. package/coverage/lcov-report/math/index.ts.html +1 -1
  41. package/coverage/lcov-report/observing/event.ts.html +1 -1
  42. package/coverage/lcov-report/observing/index.html +1 -1
  43. package/coverage/lcov-report/structures/helpers/enum.ts.html +1 -1
  44. package/coverage/lcov-report/structures/helpers/index.html +1 -1
  45. package/coverage/lcov-report/structures/index.html +1 -1
  46. package/coverage/lcov-report/structures/queue/index.html +24 -9
  47. package/coverage/lcov-report/structures/queue/parallel.ts.html +1 -1
  48. package/coverage/lcov-report/structures/queue/tasks.ts.html +358 -0
  49. package/coverage/lcov-report/structures/tempoCache.ts.html +1 -1
  50. package/coverage/lcov-report/types/comparator.ts.html +1 -1
  51. package/coverage/lcov-report/types/getter.ts.html +1 -1
  52. package/coverage/lcov-report/types/index.html +1 -1
  53. package/coverage/lcov-report/types/index.ts.html +1 -1
  54. package/coverage/lcov-report/validation/ValidationErrors.ts.html +1 -1
  55. package/coverage/lcov-report/validation/creditCard.ts.html +1 -1
  56. package/coverage/lcov-report/validation/helpers.ts.html +1 -1
  57. package/coverage/lcov-report/validation/index.html +1 -1
  58. package/coverage/lcov-report/validation/index.ts.html +1 -1
  59. package/coverage/lcov-report/validation/types.ts.html +1 -1
  60. package/coverage/lcov-report/validation/validators.ts.html +1 -1
  61. package/coverage/lcov-report/validation/wrappers.ts.html +1 -1
  62. package/coverage/lcov.info +863 -2381
  63. package/lib/fields/update.js +3 -3
  64. package/lib/fields/update.js.map +1 -1
  65. package/lib/{assert.d.ts → functions/assert.d.ts} +1 -1
  66. package/lib/functions/assert.d.ts.map +1 -0
  67. package/lib/{assert.js → functions/assert.js} +2 -2
  68. package/lib/functions/assert.js.map +1 -0
  69. package/lib/{disposer.d.ts → functions/disposer.d.ts} +0 -0
  70. package/lib/functions/disposer.d.ts.map +1 -0
  71. package/lib/{disposer.js → functions/disposer.js} +1 -1
  72. package/lib/functions/disposer.js.map +1 -0
  73. package/lib/functions/safeCall.d.ts +2 -0
  74. package/lib/functions/safeCall.d.ts.map +1 -0
  75. package/lib/{functions.js → functions/safeCall.js} +1 -1
  76. package/lib/functions/safeCall.js.map +1 -0
  77. package/lib/{throttle.d.ts → functions/throttle.d.ts} +0 -0
  78. package/lib/functions/throttle.d.ts.map +1 -0
  79. package/lib/{throttle.js → functions/throttle.js} +1 -1
  80. package/lib/functions/throttle.js.map +1 -0
  81. package/lib/lazy/light.d.ts +1 -1
  82. package/lib/lazy/light.d.ts.map +1 -1
  83. package/lib/lazy/promise.d.ts +1 -1
  84. package/lib/lazy/promise.d.ts.map +1 -1
  85. package/lib/lazy/singleton.d.ts +1 -1
  86. package/lib/lazy/singleton.d.ts.map +1 -1
  87. package/lib/math/arrays.d.ts +1 -0
  88. package/lib/math/arrays.d.ts.map +1 -1
  89. package/lib/math/arrays.js +13 -1
  90. package/lib/math/arrays.js.map +1 -1
  91. package/lib/{event.d.ts → observing/event.d.ts} +2 -3
  92. package/lib/observing/event.d.ts.map +1 -0
  93. package/lib/{event.js → observing/event.js} +2 -3
  94. package/lib/{event.js.map → observing/event.js.map} +1 -1
  95. package/lib/{throttledEvent.d.ts → observing/throttledEvent.d.ts} +0 -0
  96. package/lib/observing/throttledEvent.d.ts.map +1 -0
  97. package/lib/{throttledEvent.js → observing/throttledEvent.js} +1 -1
  98. package/lib/observing/throttledEvent.js.map +1 -0
  99. package/lib/{timer.d.ts → observing/timer.d.ts} +1 -1
  100. package/lib/observing/timer.d.ts.map +1 -0
  101. package/lib/{timer.js → observing/timer.js} +0 -0
  102. package/lib/observing/timer.js.map +1 -0
  103. package/lib/{abstractions/services/storage.d.ts → storage/abstractions.d.ts} +3 -2
  104. package/lib/storage/abstractions.d.ts.map +1 -0
  105. package/lib/{services/localization → storage}/abstractions.js +0 -0
  106. package/lib/storage/abstractions.js.map +1 -0
  107. package/lib/storage/asyncWrapper.d.ts +10 -0
  108. package/lib/storage/asyncWrapper.d.ts.map +1 -0
  109. package/lib/storage/asyncWrapper.js +24 -0
  110. package/lib/storage/asyncWrapper.js.map +1 -0
  111. package/lib/storage/index.d.ts +2 -0
  112. package/lib/storage/index.d.ts.map +1 -0
  113. package/lib/storage/index.js +5 -0
  114. package/lib/storage/index.js.map +1 -0
  115. package/lib/{services/storage/index.d.ts → storage/keyStorage.d.ts} +2 -10
  116. package/lib/storage/keyStorage.d.ts.map +1 -0
  117. package/lib/{services/storage/index.js → storage/keyStorage.js} +2 -22
  118. package/lib/storage/keyStorage.js.map +1 -0
  119. package/lib/{enumHelper.d.ts → structures/helpers/enum.d.ts} +1 -1
  120. package/lib/structures/helpers/enum.d.ts.map +1 -0
  121. package/lib/{enumHelper.js → structures/helpers/enum.js} +1 -1
  122. package/lib/structures/helpers/enum.js.map +1 -0
  123. package/lib/{nameHelper.d.ts → structures/helpers/name.d.ts} +5 -5
  124. package/lib/structures/helpers/name.d.ts.map +1 -0
  125. package/lib/{nameHelper.js → structures/helpers/name.js} +7 -6
  126. package/lib/structures/helpers/name.js.map +1 -0
  127. package/lib/structures/linkedList.d.ts +39 -0
  128. package/lib/structures/linkedList.d.ts.map +1 -0
  129. package/lib/structures/linkedList.js +82 -0
  130. package/lib/structures/linkedList.js.map +1 -0
  131. package/lib/{pool.d.ts → structures/pool.d.ts} +1 -1
  132. package/lib/structures/pool.d.ts.map +1 -0
  133. package/lib/{pool.js → structures/pool.js} +2 -2
  134. package/lib/structures/pool.js.map +1 -0
  135. package/lib/{queue → structures/queue}/parallel.d.ts +3 -3
  136. package/lib/structures/queue/parallel.d.ts.map +1 -0
  137. package/lib/{queue → structures/queue}/parallel.js +2 -2
  138. package/lib/structures/queue/parallel.js.map +1 -0
  139. package/lib/{queue → structures/queue}/tasks.d.ts +1 -1
  140. package/lib/structures/queue/tasks.d.ts.map +1 -0
  141. package/lib/{queue → structures/queue}/tasks.js +0 -0
  142. package/lib/structures/queue/tasks.js.map +1 -0
  143. package/lib/{tempoCache.d.ts → structures/tempoCache.d.ts} +0 -0
  144. package/lib/structures/tempoCache.d.ts.map +1 -0
  145. package/lib/{tempoCache.js → structures/tempoCache.js} +0 -0
  146. package/lib/structures/tempoCache.js.map +1 -0
  147. package/lib/types/comparator.d.ts +5 -0
  148. package/lib/types/comparator.d.ts.map +1 -0
  149. package/lib/types/comparator.js +8 -0
  150. package/lib/types/comparator.js.map +1 -0
  151. package/lib/types/deep.d.ts +9 -0
  152. package/lib/types/deep.d.ts.map +1 -0
  153. package/lib/{viewModels/types.js → types/deep.js} +1 -1
  154. package/lib/types/deep.js.map +1 -0
  155. package/lib/types/functions.d.ts +7 -0
  156. package/lib/types/functions.d.ts.map +1 -0
  157. package/lib/{abstractions/services/storage.js → types/functions.js} +1 -1
  158. package/lib/types/functions.js.map +1 -0
  159. package/lib/types/getter.d.ts +5 -0
  160. package/lib/types/getter.d.ts.map +1 -0
  161. package/lib/{types.js → types/getter.js} +2 -6
  162. package/lib/types/getter.js.map +1 -0
  163. package/lib/{ident.d.ts → types/ident.d.ts} +0 -0
  164. package/lib/types/ident.d.ts.map +1 -0
  165. package/lib/{ident.js → types/ident.js} +0 -0
  166. package/lib/types/ident.js.map +1 -0
  167. package/lib/types/index.d.ts +8 -0
  168. package/lib/types/index.d.ts.map +1 -0
  169. package/lib/types/index.js +7 -0
  170. package/lib/types/index.js.map +1 -0
  171. package/lib/validation/ValidationErrors.d.ts +1 -1
  172. package/lib/validation/ValidationErrors.d.ts.map +1 -1
  173. package/lib/validation/ValidationErrors.js +2 -2
  174. package/lib/validation/ValidationErrors.js.map +1 -1
  175. package/lib/{emails.d.ts → validation/emails.d.ts} +0 -0
  176. package/lib/validation/emails.d.ts.map +1 -0
  177. package/lib/{emails.js → validation/emails.js} +0 -0
  178. package/lib/validation/emails.js.map +1 -0
  179. package/package.json +16 -16
  180. package/src/async/__tests__/timeout.test.ts +1 -1
  181. package/src/fields/update.ts +1 -1
  182. package/src/{assert.ts → functions/assert.ts} +2 -2
  183. package/src/{disposer.ts → functions/disposer.ts} +1 -1
  184. package/src/functions/safeCall.ts +6 -0
  185. package/src/{throttle.ts → functions/throttle.ts} +1 -1
  186. package/src/lazy/__tests__/lazy.test.ts +1 -48
  187. package/src/lazy/light.ts +1 -1
  188. package/src/lazy/promise.ts +1 -1
  189. package/src/lazy/singleton.ts +1 -1
  190. package/src/math/arrays.ts +13 -0
  191. package/src/{event.ts → observing/event.ts} +3 -4
  192. package/src/{throttledEvent.ts → observing/throttledEvent.ts} +1 -1
  193. package/src/{timer.ts → observing/timer.ts} +1 -1
  194. package/src/{abstractions/services/storage.ts → storage/abstractions.ts} +3 -1
  195. package/src/storage/asyncWrapper.ts +24 -0
  196. package/src/storage/index.ts +2 -0
  197. package/src/{services/storage/index.ts → storage/keyStorage.ts} +1 -24
  198. package/src/{__tests__ → structures/__tests__}/enumHelper.test.ts +1 -1
  199. package/src/{__tests__ → structures/__tests__}/tempoCache.test.ts +1 -1
  200. package/src/{enumHelper.ts → structures/helpers/enum.ts} +0 -0
  201. package/src/{nameHelper.ts → structures/helpers/name.ts} +4 -4
  202. package/src/structures/linkedList.ts +129 -0
  203. package/src/{pool.ts → structures/pool.ts} +2 -2
  204. package/src/{queue → structures/queue}/__tests__/parallel.test.ts +2 -2
  205. package/src/{queue → structures/queue}/__tests__/tasks.test.ts +2 -2
  206. package/src/{queue → structures/queue}/parallel.ts +2 -2
  207. package/src/{queue → structures/queue}/tasks.ts +1 -1
  208. package/src/{tempoCache.ts → structures/tempoCache.ts} +0 -0
  209. package/src/types/comparator.ts +6 -0
  210. package/src/types/deep.ts +18 -0
  211. package/src/types/functions.ts +8 -0
  212. package/src/types/getter.ts +14 -0
  213. package/src/{ident.ts → types/ident.ts} +0 -0
  214. package/src/types/index.ts +9 -0
  215. package/src/validation/ValidationErrors.ts +1 -1
  216. package/src/{emails.ts → validation/emails.ts} +0 -0
  217. package/tsconfig.build.json +10 -0
  218. package/tsconfig.json +0 -1
  219. package/yarn.lock +467 -370
  220. package/lib/abstractions/services/storage.d.ts.map +0 -1
  221. package/lib/abstractions/services/storage.js.map +0 -1
  222. package/lib/assert.d.ts.map +0 -1
  223. package/lib/assert.js.map +0 -1
  224. package/lib/cache.d.ts +0 -36
  225. package/lib/cache.d.ts.map +0 -1
  226. package/lib/cache.js +0 -165
  227. package/lib/cache.js.map +0 -1
  228. package/lib/deepPartial.d.ts +0 -4
  229. package/lib/deepPartial.d.ts.map +0 -1
  230. package/lib/deepPartial.js +0 -3
  231. package/lib/deepPartial.js.map +0 -1
  232. package/lib/disposer.d.ts.map +0 -1
  233. package/lib/disposer.js.map +0 -1
  234. package/lib/emails.d.ts.map +0 -1
  235. package/lib/emails.js.map +0 -1
  236. package/lib/enumHelper.d.ts.map +0 -1
  237. package/lib/enumHelper.js.map +0 -1
  238. package/lib/event.d.ts.map +0 -1
  239. package/lib/functions.d.ts +0 -9
  240. package/lib/functions.d.ts.map +0 -1
  241. package/lib/functions.js.map +0 -1
  242. package/lib/ident.d.ts.map +0 -1
  243. package/lib/ident.js.map +0 -1
  244. package/lib/lazy/index.d.ts +0 -10
  245. package/lib/lazy/index.d.ts.map +0 -1
  246. package/lib/lazy/index.js +0 -23
  247. package/lib/lazy/index.js.map +0 -1
  248. package/lib/lazy/observable.d.ts +0 -9
  249. package/lib/lazy/observable.d.ts.map +0 -1
  250. package/lib/lazy/observable.js +0 -31
  251. package/lib/lazy/observable.js.map +0 -1
  252. package/lib/lazy.light.d.ts +0 -2
  253. package/lib/lazy.light.d.ts.map +0 -1
  254. package/lib/lazy.light.js +0 -8
  255. package/lib/lazy.light.js.map +0 -1
  256. package/lib/nameHelper.d.ts.map +0 -1
  257. package/lib/nameHelper.js.map +0 -1
  258. package/lib/observersMap.d.ts +0 -22
  259. package/lib/observersMap.d.ts.map +0 -1
  260. package/lib/observersMap.js +0 -93
  261. package/lib/observersMap.js.map +0 -1
  262. package/lib/observingCache.d.ts +0 -32
  263. package/lib/observingCache.d.ts.map +0 -1
  264. package/lib/observingCache.js +0 -128
  265. package/lib/observingCache.js.map +0 -1
  266. package/lib/pool.d.ts.map +0 -1
  267. package/lib/pool.js.map +0 -1
  268. package/lib/queue/parallel.d.ts.map +0 -1
  269. package/lib/queue/parallel.js.map +0 -1
  270. package/lib/queue/tasks.d.ts.map +0 -1
  271. package/lib/queue/tasks.js.map +0 -1
  272. package/lib/services/localization/LocalaziedValidationErrors.d.ts +0 -9
  273. package/lib/services/localization/LocalaziedValidationErrors.d.ts.map +0 -1
  274. package/lib/services/localization/LocalaziedValidationErrors.js +0 -27
  275. package/lib/services/localization/LocalaziedValidationErrors.js.map +0 -1
  276. package/lib/services/localization/LocalizationManager.d.ts +0 -18
  277. package/lib/services/localization/LocalizationManager.d.ts.map +0 -1
  278. package/lib/services/localization/LocalizationManager.js +0 -58
  279. package/lib/services/localization/LocalizationManager.js.map +0 -1
  280. package/lib/services/localization/abstractions.d.ts +0 -12
  281. package/lib/services/localization/abstractions.d.ts.map +0 -1
  282. package/lib/services/localization/abstractions.js.map +0 -1
  283. package/lib/services/localization/defaultShape.d.ts +0 -26
  284. package/lib/services/localization/defaultShape.d.ts.map +0 -1
  285. package/lib/services/localization/defaultShape.js +0 -28
  286. package/lib/services/localization/defaultShape.js.map +0 -1
  287. package/lib/services/localization/index.d.ts +0 -5
  288. package/lib/services/localization/index.d.ts.map +0 -1
  289. package/lib/services/localization/index.js +0 -10
  290. package/lib/services/localization/index.js.map +0 -1
  291. package/lib/services/storage/index.d.ts.map +0 -1
  292. package/lib/services/storage/index.js.map +0 -1
  293. package/lib/services/storage/web/localStorage.d.ts +0 -13
  294. package/lib/services/storage/web/localStorage.d.ts.map +0 -1
  295. package/lib/services/storage/web/localStorage.js +0 -29
  296. package/lib/services/storage/web/localStorage.js.map +0 -1
  297. package/lib/services/storage/web/sessionStorage.d.ts +0 -13
  298. package/lib/services/storage/web/sessionStorage.d.ts.map +0 -1
  299. package/lib/services/storage/web/sessionStorage.js +0 -29
  300. package/lib/services/storage/web/sessionStorage.js.map +0 -1
  301. package/lib/services/storage/web/webStorage.d.ts +0 -9
  302. package/lib/services/storage/web/webStorage.d.ts.map +0 -1
  303. package/lib/services/storage/web/webStorage.js +0 -24
  304. package/lib/services/storage/web/webStorage.js.map +0 -1
  305. package/lib/tempoCache.d.ts.map +0 -1
  306. package/lib/tempoCache.js.map +0 -1
  307. package/lib/throttle.d.ts.map +0 -1
  308. package/lib/throttle.js.map +0 -1
  309. package/lib/throttledEvent.d.ts.map +0 -1
  310. package/lib/throttledEvent.js.map +0 -1
  311. package/lib/timeHelper.d.ts +0 -7
  312. package/lib/timeHelper.d.ts.map +0 -1
  313. package/lib/timeHelper.js +0 -37
  314. package/lib/timeHelper.js.map +0 -1
  315. package/lib/timer.d.ts.map +0 -1
  316. package/lib/timer.js.map +0 -1
  317. package/lib/transitionObserver.d.ts +0 -36
  318. package/lib/transitionObserver.d.ts.map +0 -1
  319. package/lib/transitionObserver.js +0 -153
  320. package/lib/transitionObserver.js.map +0 -1
  321. package/lib/types.d.ts +0 -17
  322. package/lib/types.d.ts.map +0 -1
  323. package/lib/types.js.map +0 -1
  324. package/lib/unsubscriber.d.ts +0 -2
  325. package/lib/unsubscriber.d.ts.map +0 -1
  326. package/lib/unsubscriber.js +0 -12
  327. package/lib/unsubscriber.js.map +0 -1
  328. package/lib/validation/ValidationErrorsLocalization.d.ts +0 -27
  329. package/lib/validation/ValidationErrorsLocalization.d.ts.map +0 -1
  330. package/lib/validation/ValidationErrorsLocalization.js +0 -26
  331. package/lib/validation/ValidationErrorsLocalization.js.map +0 -1
  332. package/lib/viewModels/CommonModel.d.ts +0 -13
  333. package/lib/viewModels/CommonModel.d.ts.map +0 -1
  334. package/lib/viewModels/CommonModel.js +0 -38
  335. package/lib/viewModels/CommonModel.js.map +0 -1
  336. package/lib/viewModels/FlagModel.d.ts +0 -22
  337. package/lib/viewModels/FlagModel.d.ts.map +0 -1
  338. package/lib/viewModels/FlagModel.js +0 -52
  339. package/lib/viewModels/FlagModel.js.map +0 -1
  340. package/lib/viewModels/InitializableModel.d.ts +0 -6
  341. package/lib/viewModels/InitializableModel.d.ts.map +0 -1
  342. package/lib/viewModels/InitializableModel.js +0 -23
  343. package/lib/viewModels/InitializableModel.js.map +0 -1
  344. package/lib/viewModels/LoadingModel.d.ts +0 -17
  345. package/lib/viewModels/LoadingModel.d.ts.map +0 -1
  346. package/lib/viewModels/LoadingModel.js +0 -42
  347. package/lib/viewModels/LoadingModel.js.map +0 -1
  348. package/lib/viewModels/MultiSelectModel.d.ts +0 -47
  349. package/lib/viewModels/MultiSelectModel.d.ts.map +0 -1
  350. package/lib/viewModels/MultiSelectModel.js +0 -144
  351. package/lib/viewModels/MultiSelectModel.js.map +0 -1
  352. package/lib/viewModels/NumberModel.d.ts +0 -19
  353. package/lib/viewModels/NumberModel.d.ts.map +0 -1
  354. package/lib/viewModels/NumberModel.js +0 -38
  355. package/lib/viewModels/NumberModel.js.map +0 -1
  356. package/lib/viewModels/PromptModal.d.ts +0 -31
  357. package/lib/viewModels/PromptModal.d.ts.map +0 -1
  358. package/lib/viewModels/PromptModal.js +0 -57
  359. package/lib/viewModels/PromptModal.js.map +0 -1
  360. package/lib/viewModels/SelectModel.d.ts +0 -35
  361. package/lib/viewModels/SelectModel.d.ts.map +0 -1
  362. package/lib/viewModels/SelectModel.js +0 -118
  363. package/lib/viewModels/SelectModel.js.map +0 -1
  364. package/lib/viewModels/TextModel.d.ts +0 -41
  365. package/lib/viewModels/TextModel.d.ts.map +0 -1
  366. package/lib/viewModels/TextModel.js +0 -98
  367. package/lib/viewModels/TextModel.js.map +0 -1
  368. package/lib/viewModels/Validatable.d.ts +0 -26
  369. package/lib/viewModels/Validatable.d.ts.map +0 -1
  370. package/lib/viewModels/Validatable.js +0 -81
  371. package/lib/viewModels/Validatable.js.map +0 -1
  372. package/lib/viewModels/ValueModel.d.ts +0 -12
  373. package/lib/viewModels/ValueModel.d.ts.map +0 -1
  374. package/lib/viewModels/ValueModel.js +0 -29
  375. package/lib/viewModels/ValueModel.js.map +0 -1
  376. package/lib/viewModels/ValuesCollector.d.ts +0 -26
  377. package/lib/viewModels/ValuesCollector.d.ts.map +0 -1
  378. package/lib/viewModels/ValuesCollector.js +0 -51
  379. package/lib/viewModels/ValuesCollector.js.map +0 -1
  380. package/lib/viewModels/index.d.ts +0 -12
  381. package/lib/viewModels/index.d.ts.map +0 -1
  382. package/lib/viewModels/index.js +0 -15
  383. package/lib/viewModels/index.js.map +0 -1
  384. package/lib/viewModels/types.d.ts +0 -19
  385. package/lib/viewModels/types.d.ts.map +0 -1
  386. package/lib/viewModels/types.js.map +0 -1
  387. package/lib/viewModels/wrappers.d.ts +0 -12
  388. package/lib/viewModels/wrappers.d.ts.map +0 -1
  389. package/lib/viewModels/wrappers.js +0 -43
  390. package/lib/viewModels/wrappers.js.map +0 -1
  391. package/src/__tests__/observingCache.test.ts +0 -127
  392. package/src/__tests__/transitionObserver.test.ts +0 -219
  393. package/src/cache.ts +0 -181
  394. package/src/deepPartial.ts +0 -4
  395. package/src/functions.ts +0 -14
  396. package/src/lazy/index.ts +0 -33
  397. package/src/lazy/observable.ts +0 -37
  398. package/src/lazy.light.ts +0 -8
  399. package/src/observersMap.ts +0 -105
  400. package/src/observingCache.ts +0 -160
  401. package/src/services/localization/LocalaziedValidationErrors.ts +0 -18
  402. package/src/services/localization/LocalizationManager.ts +0 -53
  403. package/src/services/localization/abstractions.ts +0 -16
  404. package/src/services/localization/defaultShape.ts +0 -26
  405. package/src/services/localization/index.ts +0 -6
  406. package/src/services/storage/web/localStorage.ts +0 -35
  407. package/src/services/storage/web/sessionStorage.ts +0 -35
  408. package/src/services/storage/web/webStorage.ts +0 -29
  409. package/src/timeHelper.ts +0 -39
  410. package/src/transitionObserver.ts +0 -183
  411. package/src/types.ts +0 -30
  412. package/src/unsubscriber.ts +0 -14
  413. package/src/validation/ValidationErrorsLocalization.ts +0 -27
  414. package/src/viewModels/CommonModel.ts +0 -45
  415. package/src/viewModels/FlagModel.ts +0 -70
  416. package/src/viewModels/InitializableModel.ts +0 -17
  417. package/src/viewModels/LoadingModel.ts +0 -52
  418. package/src/viewModels/MultiSelectModel.ts +0 -178
  419. package/src/viewModels/NumberModel.ts +0 -50
  420. package/src/viewModels/PromptModal.ts +0 -65
  421. package/src/viewModels/SelectModel.ts +0 -152
  422. package/src/viewModels/TextModel.ts +0 -127
  423. package/src/viewModels/Validatable.ts +0 -102
  424. package/src/viewModels/ValueModel.ts +0 -34
  425. package/src/viewModels/ValuesCollector.ts +0 -81
  426. package/src/viewModels/__tests__/common.test.ts +0 -107
  427. package/src/viewModels/__tests__/multiSelect.test.ts +0 -138
  428. package/src/viewModels/__tests__/select.test.ts +0 -71
  429. package/src/viewModels/__tests__/wrappers.test.ts +0 -79
  430. package/src/viewModels/index.ts +0 -15
  431. package/src/viewModels/types.ts +0 -23
  432. package/src/viewModels/wrappers.ts +0 -49
  433. package/tsconfig.eslint.json +0 -9
@@ -1,127 +0,0 @@
1
- import { observable, makeObservable, reaction, action } from 'mobx';
2
- import { Getter } from '../types';
3
- import { IValueModel } from './types';
4
- import logger from '../logger';
5
- import { ValidatableModel } from './Validatable';
6
- import { IResetableModel } from 'viewModels';
7
-
8
- export type TextInputConfig = {
9
- name?: Getter<string>;
10
- title?: Getter<string>;
11
- value?: Getter<string>;
12
- async?: boolean;
13
-
14
- noSubscribe?: boolean;
15
- };
16
-
17
- function FromGetter(getter: Getter<string>, setter: (val: string) => void, autorunDelay: number = null, noAutorun: boolean = null) {
18
- if (noAutorun || typeof getter !== 'function') {
19
- setter(Getter.getValue(getter));
20
- return null;
21
- }
22
-
23
- return reaction(
24
- () => Getter.getValue(getter),
25
- setter,
26
- { delay: autorunDelay, fireImmediately: true },
27
- );
28
- }
29
-
30
- export class Text {
31
- @observable
32
- private _value: string = null;
33
-
34
- constructor(config: { value: Getter<string>, async?: boolean, noSubscribe?: boolean }) {
35
- makeObservable(this);
36
- FromGetter(config.value, val => this._value = val, config.async ? 100 : null, config.noSubscribe);
37
- }
38
-
39
- get value() { return this._value; }
40
- }
41
-
42
- export class TextInputVM extends ValidatableModel<string> implements IValueModel<string>, IResetableModel {
43
- // @observable
44
- private _value = '';
45
-
46
- // @observable
47
- private _focused = false;
48
-
49
- private _name: string = null;
50
- private _title: string = null;
51
-
52
- private readonly _valueObserving: () => void = null;
53
-
54
- constructor(config?: TextInputConfig) {
55
- super();
56
- makeObservable<TextInputVM, '_value' | '_focused'>(this, {
57
- _value: observable,
58
- _focused: observable,
59
- setValue: action,
60
- setFocused: action,
61
- });
62
- config = config || {};
63
-
64
- const delay = config.async ? 100 : null;
65
-
66
- FromGetter(config.name, val => this._name = val, delay);
67
- FromGetter(config.title, val => this._title = val, delay);
68
- this._valueObserving = FromGetter(config.value, val => this._value = val, delay);
69
- }
70
-
71
- get value() { return this._value; }
72
- get name() { return this._name; }
73
- get title() { return this._title; }
74
-
75
- set value(val) {
76
- this.setValue(val);
77
- }
78
-
79
- // @action
80
- public readonly setValue = (value: string) => {
81
- if (!this._valueObserving) {
82
- this._value = value;
83
-
84
- if (this._validateOnChange) {
85
- this.validate();
86
- }
87
- } else {
88
- logger.warn('[TextInputViewModel] Setting value is not allowed when value is observing');
89
- }
90
- };
91
-
92
- get isEmpty() {
93
- return !this._value;
94
- }
95
-
96
- get focused() {
97
- return this._focused;
98
- }
99
-
100
- set focused(val: boolean) {
101
- this.setFocused(val);
102
- }
103
-
104
- // @action
105
- public readonly setFocused = (value = true) => {
106
- this._focused = value;
107
- if (!value) {
108
- this.onBlur();
109
- return;
110
- }
111
-
112
- super.reset();
113
- };
114
-
115
- protected get valueToValidate() { return (this.value ?? '').trim(); }
116
-
117
- private onBlur() {
118
- this.validate();
119
- }
120
-
121
- reset = () => {
122
- this._value = '';
123
- this._focused = false;
124
- super.reset();
125
- };
126
-
127
- }
@@ -1,102 +0,0 @@
1
- import { observable, makeObservable, action, runInAction } from 'mobx';
2
- import { ValidatorFunction, ValidatorFunctionAsync, ValidationErrors, ValidationError } from '../validation';
3
- import { someAsync } from '../async/arrays';
4
-
5
- export type ValueValidator<T, TErrors = ValidationErrors> = ValidatorFunction<T, TErrors> | ValidatorFunctionAsync<T, TErrors>;
6
- export type ValidationErrorsStrings<TErrors extends string | number = number> = Partial<Omit<Record<TErrors, string>, 0 | null>>;
7
-
8
- export type ValidationConfig<T, TErrors extends string | number = ValidationErrors> = {
9
- validator: ValueValidator<Readonly<T>, TErrors>,
10
- errors: ValidationErrorsStrings<TErrors>,
11
- };
12
-
13
- const EmptyValidator = () => 0;
14
-
15
- export abstract class ValidatableModel<T = string> {
16
-
17
- private _validator: ValueValidator<T | Readonly<T>, any> = null;
18
- private _strings: ValidationErrorsStrings<any> = null;
19
-
20
- // @observable
21
- private _error: string = null;
22
-
23
- private _validationError: ValidationError = null;
24
- protected _validateOnChange = false;
25
-
26
- constructor() {
27
- makeObservable<ValidatableModel<T>, '_error'>(this, {
28
- '_error': observable,
29
- reset: action,
30
- });
31
- }
32
-
33
- protected abstract get valueToValidate(): T | Readonly<T>;
34
-
35
- get isValid() { return !this._error; }
36
-
37
- get error() { return this._error; }
38
-
39
- public setValidationConfig<TErrors extends string | number = ValidationErrors>(config?: ValidationConfig<T, TErrors>) {
40
- this._validator = config?.validator || EmptyValidator;
41
- this._strings = config?.errors;
42
- return this;
43
- }
44
-
45
- public validateOnChange(enable = true) {
46
- this._validateOnChange = enable;
47
- return this;
48
- }
49
-
50
- public async testValidate(value: T) {
51
- if (this._validator) {
52
- const res = await this._validator(value);
53
- return res;
54
- }
55
- return null;
56
- }
57
-
58
- async validate() {
59
- if (!this._validator) {
60
- return true;
61
- }
62
-
63
- try {
64
- const validationResult = await this._validator(this.valueToValidate);
65
- this._validationError = !validationResult
66
- ? null
67
- : new ValidationError('Unknown error', validationResult);
68
- } catch (err) {
69
- this._validationError = err as ValidationError;
70
- }
71
-
72
- runInAction(() => {
73
- if (!this._validationError) {
74
- this._error = null;
75
- } else {
76
- const code = this._validationError.code;
77
- this._error = this._strings && this._strings[code];
78
- }
79
- });
80
- return this._validationError == null;
81
- }
82
-
83
- async getIsInvalid() {
84
- const valid = await this.validate();
85
- return !valid;
86
- }
87
-
88
- // @action
89
- reset() {
90
- this._validationError = null;
91
- this._error = null;
92
- }
93
-
94
- static async IsSomeInvalid(validatables: ReadonlyArray<ValidatableModel<any>>, stopOnFail = true) {
95
- if (stopOnFail) {
96
- return someAsync(validatables, async v => !(await v.validate()));
97
- }
98
-
99
- const results = await Promise.all(validatables.map(v => v.validate()));
100
- return results.some(r => !r);
101
- }
102
- }
@@ -1,34 +0,0 @@
1
- import { action, makeObservable, observable } from 'mobx';
2
- import { Getter } from '../types';
3
- import { IValueModel } from './types';
4
-
5
- export class ValueModel<T> implements IValueModel<T> {
6
- // observable[.ref]
7
- private _value: T;
8
-
9
- private _defaultValue: Getter<T> = null;
10
-
11
- constructor(v: Getter<T> = null, useRefObservable = true) {
12
- this._value = Getter.getValue(v) || null;
13
- this._defaultValue = v;
14
-
15
- makeObservable<ValueModel<T>, '_value'>(this, {
16
- _value: useRefObservable ? observable.ref : observable,
17
- setValue: action,
18
- });
19
- }
20
-
21
- public get value() { return this._value; }
22
- public set value(v: T) {
23
- this.setValue(v);
24
- }
25
-
26
- // action
27
- public readonly setValue = (value: T) => {
28
- this._value = value;
29
- };
30
-
31
- reset = () => {
32
- this._value = Getter.getValue(this._defaultValue);
33
- };
34
- }
@@ -1,81 +0,0 @@
1
- import { IValueModel } from './types';
2
-
3
- export interface IValueCollector<TSource, TValue> {
4
- getValue(source: TSource): TValue;
5
- setValue(source: TSource, value: TValue): void;
6
- }
7
-
8
- type SimpleCollector<T> = {
9
- get: () => T,
10
- set: (t: T) => void,
11
- };
12
-
13
- type SimpleCollectorsMap<T> = {
14
- [P in keyof T]?: SimpleCollector<T[P]>;
15
- };
16
-
17
- export type ModelCollectorsMap<T> = {
18
- [P in keyof T]?: IValueModel<T[P]>;
19
- };
20
-
21
- export type CollectorsMap<T> = {
22
- [P in keyof T]?: SimpleCollector<T[P]>;
23
- };
24
-
25
- export class ModelCollector<T extends Object> {
26
-
27
- private readonly _collectors: SimpleCollectorsMap<T> = { };
28
-
29
- public addModels(models: ModelCollectorsMap<T>) {
30
- Object.entries(models).forEach(pair => this.addModel(pair[0] as keyof T, pair[1]));
31
- return this;
32
- }
33
-
34
- public addModel<TKey extends keyof T, TSource extends IValueModel<T[TKey]>>(key: TKey, source: TSource) {
35
- this._collectors[key] = {
36
- get: () => source.value,
37
- set: v => { source.value = v; },
38
- };
39
-
40
- return this;
41
- }
42
-
43
- public addCollector<TKey extends keyof T, TModel, TCollector extends IValueCollector<TModel, T[TKey]>>(key: TKey, model: TModel, collector: TCollector) {
44
- this._collectors[key] = {
45
- get: () => collector.getValue(model),
46
- set: v => collector.setValue(model, v),
47
- };
48
-
49
- return this;
50
- }
51
-
52
- public remove(key: keyof T) {
53
- delete this._collectors[key];
54
-
55
- return this;
56
- }
57
-
58
- public collect(): T {
59
- const res = { } as T;
60
-
61
- Object.entries(this._collectors).forEach(pair => {
62
- const key = pair[0] as keyof T;
63
- const collector = pair[1] as SimpleCollector<T[keyof T]>;
64
- res[key] = collector.get();
65
- });
66
-
67
- return res;
68
- }
69
-
70
- public populate(data: T) {
71
- Object.entries(data).forEach(pair => {
72
- const key = pair[0] as keyof T;
73
- const value = pair[1] as T[keyof T];
74
-
75
- const collector = this._collectors[key];
76
- if (collector) {
77
- collector.set(value);
78
- }
79
- });
80
- }
81
- }
@@ -1,107 +0,0 @@
1
- import { ValidationErrors } from '../../validation';
2
- import { CommonModel } from '../CommonModel';
3
- import { LoadingModel } from '../LoadingModel';
4
- import { setTimeoutAsync } from '../../async/timeout';
5
- import { SelectString } from '../SelectModel';
6
- import { TextInputVM } from '../TextModel';
7
-
8
- describe('CommonModel', () => {
9
- const NotEmptyError = 'should be not empty';
10
-
11
- it('works', async () => {
12
-
13
- let m: CommonModel<string[]>;
14
-
15
- const fn = async () => {
16
- m = new CommonModel<string[]>(() => [], true)
17
- .setValidationConfig({
18
- validator: (v: readonly any[]) => v.length > 0 ? ValidationErrors.None : ValidationErrors.ShouldBeNonEmpty,
19
- errors: {
20
- [ValidationErrors.ShouldBeNonEmpty]: NotEmptyError,
21
- },
22
- });
23
- };
24
-
25
- await expect(fn()).resolves.not.toThrow();
26
- expect(m).toBeDefined();
27
-
28
- m.value = ['1'];
29
-
30
- expect(m.value).toStrictEqual(['1']);
31
- const valid1 = await m.validate();
32
- expect(valid1).toBeTruthy();
33
-
34
- m.reset();
35
-
36
- expect(m.value).toStrictEqual([]);
37
-
38
- const valid2 = await m.validate();
39
- expect(valid2).toBeFalsy();
40
-
41
- m.reset();
42
- expect(m.error).toBeFalsy();
43
-
44
- m.validateOnChange(true);
45
- m.value = [];
46
-
47
- // skip one frame
48
- await Promise.resolve();
49
-
50
- expect(m.error).toEqual(NotEmptyError);
51
- });
52
- });
53
-
54
- describe('LoadingModel works', () => {
55
- const worker = async () => {
56
- await setTimeoutAsync(100);
57
- return 100;
58
- };
59
-
60
- it('basic', async () => {
61
-
62
- const m = new LoadingModel();
63
- expect(m.value).toBe(false);
64
- expect(m.isLoading).toBeFalsy();
65
-
66
- const promise = m.useLoading(worker);
67
- expect(m.isLoading).toBeTruthy();
68
-
69
- await promise;
70
-
71
- expect(m.isLoading).toBeFalsy();
72
- });
73
-
74
- it('with exclusive', async () => {
75
- const m = new LoadingModel();
76
-
77
- const first = m.useLoading(worker, true);
78
- expect(m.isLoading).toBeTruthy();
79
-
80
- const second = m.useLoading(worker, true);
81
- expect(m.isLoading).toBeTruthy();
82
-
83
- await expect(() => m.useLoading(worker, 'throw')).rejects.toThrow();
84
-
85
- expect(m.isLoading).toBeTruthy();
86
-
87
- await expect(second).resolves.toBe(false);
88
- await expect(first).resolves.toBe(100);
89
-
90
- expect(m.value).toBe(false);
91
- expect(m.isLoading).toBeFalsy();
92
- });
93
- });
94
-
95
- describe('Others', () => {
96
- it('has no mobx errors', async () => {
97
-
98
- await expect((async () => {
99
- return new SelectString([]);
100
- })()).resolves.not.toThrow();
101
-
102
- await expect((async () => {
103
- return new TextInputVM();
104
- })()).resolves.not.toThrow();
105
-
106
- });
107
- });
@@ -1,138 +0,0 @@
1
- import { reaction, toJS } from 'mobx';
2
- import { arrayRepeat } from '../../math';
3
- import { MultiSelect, MultiSelectString } from '../MultiSelectModel';
4
-
5
- type SetType<T> = { items: T[], selected: number[], accessor: (item: T) => string };
6
-
7
- describe('MultiSelectModel', () => {
8
- it('creates', () => {
9
- expect(() => new MultiSelect(null, null).values).toThrow();
10
- expect(() => new MultiSelect([1], null).values).toThrow();
11
- });
12
-
13
- const sets: SetType<any>[] = [
14
- { items: [1, 2, 3], selected: [1], accessor: i => `_${i}_` },
15
- { items: [1, 2, 3], selected: [], accessor: i => `_${i}_` },
16
- { items: ['a', 'b', 'c'], selected: [2], accessor: i => i },
17
- ];
18
-
19
- describe('consistent', () => {
20
- sets.forEach((set, setIndex) => {
21
- it(`variant ${setIndex + 1}`, () => {
22
- const items = set.items; // [1, 2, 3];
23
- const accessor = set.accessor; // (i: number) => `_${i}_`;
24
- const initialSelected = set.selected; // [1];
25
- const values = items.map(accessor);
26
- const selectedValues = initialSelected.map(i => accessor(items[i]));
27
-
28
- const vm = new MultiSelect(items, accessor, ...initialSelected);
29
-
30
- expect(vm.items).toStrictEqual(items);
31
- expect(vm.values).toStrictEqual(values);
32
- expect(vm.count).toBe(items.length);
33
- expect(vm.selectedCount).toBe(initialSelected.length);
34
- expect(vm.selectedIndexes).toStrictEqual(initialSelected);
35
- expect(vm.selectedValues).toStrictEqual(selectedValues);
36
-
37
- initialSelected.forEach(index => {
38
- expect(vm.isIndexSelected(index)).toBe(initialSelected.includes(index));
39
- });
40
-
41
- values.forEach((value) => {
42
- expect(vm.isValueSelected(value)).toBe(selectedValues.includes(value));
43
- });
44
- });
45
- });
46
-
47
- });
48
-
49
- it('reacts', () => {
50
- const vm = new MultiSelectString(['a', 'b', 'c']);
51
-
52
- expect(vm.count).toBe(3);
53
- expect(vm.selectedCount).toBe(0);
54
- expect(vm.selectedIndexes).toHaveLength(0);
55
-
56
- const mocks = arrayRepeat(() => jest.fn().mockImplementation(null), 5);
57
- const [
58
- onSelectedIndexes,
59
- onSelectedItems,
60
- onSelectedValues,
61
- onIsIndexSelected,
62
- onIsValueSelected,
63
- ] = mocks;
64
-
65
- const wrapMock = mock => ((a: any) => mock(toJS(a)));
66
-
67
- const expectEmptyCalls = () => {
68
- expect(onSelectedIndexes).toHaveBeenCalledWith([]);
69
- expect(onSelectedItems).toHaveBeenCalledWith([]);
70
- expect(onSelectedValues).toHaveBeenCalledWith([]);
71
- mocks.forEach(m => m.mockClear());
72
- };
73
-
74
- reaction(() => vm.selectedIndexes, wrapMock(onSelectedIndexes));
75
- reaction(() => vm.selectedItems, wrapMock(onSelectedItems));
76
- reaction(() => vm.selectedValues, wrapMock(onSelectedValues));
77
-
78
- // initially – 'false', so expect only when 'true' should be passed
79
- reaction(() => vm.isIndexSelected(0), wrapMock(onIsIndexSelected));
80
- reaction(() => vm.isValueSelected('a'), wrapMock(onIsValueSelected));
81
-
82
- vm.selectIndex(1);
83
-
84
- expect(onSelectedIndexes).toHaveBeenCalledWith([1]);
85
- expect(onSelectedItems).toHaveBeenCalledWith(['b']);
86
- expect(onSelectedValues).toHaveBeenCalledWith(['b']);
87
- expect(onIsIndexSelected).not.toHaveBeenCalled();
88
- expect(onIsValueSelected).not.toHaveBeenCalled();
89
- mocks.forEach(m => m.mockClear());
90
-
91
- vm.deSelectIndex(1);
92
- expect(onIsIndexSelected).not.toHaveBeenCalled();
93
- expect(onIsValueSelected).not.toHaveBeenCalled();
94
- expectEmptyCalls();
95
-
96
- vm.selectItem('c');
97
-
98
- expect(onSelectedIndexes).toHaveBeenCalledWith([2]);
99
- expect(onSelectedItems).toHaveBeenCalledWith(['c']);
100
- expect(onSelectedValues).toHaveBeenCalledWith(['c']);
101
- expect(onIsIndexSelected).not.toHaveBeenCalled();
102
- expect(onIsValueSelected).not.toHaveBeenCalled();
103
- mocks.forEach(m => m.mockClear());
104
-
105
- vm.deSelectItem('c');
106
- expect(onIsIndexSelected).not.toHaveBeenCalled();
107
- expect(onIsValueSelected).not.toHaveBeenCalled();
108
- expectEmptyCalls();
109
-
110
- vm.selectValue('a');
111
-
112
- expect(onSelectedIndexes).toHaveBeenCalledWith([0]);
113
- expect(onSelectedItems).toHaveBeenCalledWith(['a']);
114
- expect(onSelectedValues).toHaveBeenCalledWith(['a']);
115
- expect(onIsIndexSelected).toHaveBeenCalledWith(true);
116
- expect(onIsValueSelected).toHaveBeenCalledWith(true);
117
- mocks.forEach(m => m.mockClear());
118
-
119
- vm.deSelectValue('a');
120
- expect(onIsIndexSelected).toHaveBeenCalledWith(false);
121
- expect(onIsValueSelected).toHaveBeenCalledWith(false);
122
- expectEmptyCalls();
123
-
124
- vm.selectItems(['a', 'b']);
125
-
126
- expect(onSelectedIndexes).toHaveBeenCalledWith([0, 1]);
127
- expect(onSelectedItems).toHaveBeenCalledWith(['a', 'b']);
128
- expect(onSelectedValues).toHaveBeenCalledWith(['a', 'b']);
129
- expect(onIsIndexSelected).toHaveBeenCalledWith(true);
130
- expect(onIsValueSelected).toHaveBeenCalledWith(true);
131
- mocks.forEach(m => m.mockClear());
132
-
133
- vm.reset();
134
- expect(onIsIndexSelected).toHaveBeenCalledWith(false);
135
- expect(onIsValueSelected).toHaveBeenCalledWith(false);
136
- expectEmptyCalls();
137
- });
138
- });
@@ -1,71 +0,0 @@
1
- import { configure } from 'mobx';
2
- import { Select, SelectString } from '../SelectModel';
3
-
4
- configure({ enforceActions: 'never' });
5
-
6
- describe('SelectViewModel', () => {
7
- it('consistent', async () => {
8
- expect(() => new Select(null, null).values).toThrow();
9
- expect(() => new Select([1], null).values).toThrow();
10
-
11
- const emptyVm = new Select([], null);
12
- expect(emptyVm.selectedValue).toBeNull();
13
-
14
- const items = [0, 1, 2];
15
- const values = ['0!', '1!', '2!'];
16
- const initialIndex = -1;
17
- const vm = new Select(items, i => `${i}!`, initialIndex);
18
-
19
- expect(vm.index).toEqual(initialIndex);
20
- expect(vm.values).toStrictEqual(values);
21
- expect(vm.items).toStrictEqual(items);
22
-
23
- expect(vm.selectedItem).toBeUndefined();
24
- expect(vm.selectedValue).toBeUndefined();
25
-
26
- vm.selectedItem = 7;
27
- expect(vm.index).toBe(initialIndex);
28
-
29
- vm.selectedValue = '123';
30
- expect(vm.index).toBe(initialIndex);
31
-
32
- vm.opened.value = true;
33
- expect(vm.opened.value).toBe(true);
34
-
35
- vm.index = 1;
36
- expect(vm.index).toBe(1);
37
-
38
- expect(vm.flags).toHaveLength(items.length);
39
- values.forEach((_currentValue, itemIndex) => {
40
- vm.selectedValue = _currentValue;
41
- expect(vm.selectedItem).toBe(items[itemIndex]);
42
- vm.selectedItem = items[itemIndex];
43
- expect(vm.selectedValue).toBe(_currentValue);
44
- vm.flags.forEach((f, i) => {
45
- expect(f.value).toBe(i === itemIndex);
46
- expect(f.label).toBe(values[i]);
47
- });
48
- });
49
-
50
- vm.flags.forEach((f, i) => {
51
- f.value = true;
52
- vm.flags.forEach((ff, ii) => {
53
- expect(ff.value).toBe(i === ii);
54
- });
55
- expect(vm.index).toBe(i);
56
- });
57
-
58
- vm.selectedItem = items[1];
59
- expect(vm.selectedValue).toBe(values[1]);
60
-
61
- vm.reset();
62
- expect(vm.index).toBe(initialIndex);
63
-
64
- expect(vm.error).toBeNull();
65
-
66
- await expect(vm.validate()).resolves.toBeTruthy();
67
-
68
- const vmS = new SelectString(values);
69
- expect(vmS.values).toStrictEqual(values);
70
- });
71
- });