ctx-core 5.0.1 → 5.2.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 (227) hide show
  1. package/all/CACHE_VERSION/index.d.ts +10 -0
  2. package/all/CACHE_VERSION/index.js +14 -0
  3. package/all/NODE_ENV/index.d.ts +10 -0
  4. package/all/NODE_ENV/index.js +14 -0
  5. package/all/Request/index.js +2 -1
  6. package/all/Response/index.js +1 -1
  7. package/all/VERSION/index.d.ts +7 -0
  8. package/all/VERSION/index.js +12 -0
  9. package/all/add/index.js +1 -1
  10. package/all/all_union_a/index.js +1 -1
  11. package/all/and/index.js +2 -1
  12. package/all/andand_or/index.js +2 -1
  13. package/all/andandfn/index.js +4 -3
  14. package/all/apply/index.js +4 -2
  15. package/all/arg_a__pick/index.d.ts +6 -0
  16. package/all/arg_a__pick/index.js +16 -0
  17. package/all/arg_i0_a/index.js +3 -2
  18. package/all/assign_fn_key_a/index.js +1 -1
  19. package/all/bad_gateway/index.js +2 -1
  20. package/all/bad_request/index.js +1 -1
  21. package/all/be/index.js +3 -2
  22. package/all/be_/index.d.ts +38 -3
  23. package/all/be_/index.js +52 -14
  24. package/all/be_/index.test.ts +192 -91
  25. package/all/be_lock_memosig_triple/index.test.ts +6 -6
  26. package/all/be_memo_pair/index.test.ts +4 -4
  27. package/all/be_memosig_triple/index.test.ts +6 -6
  28. package/all/be_sig_triple/index.test.ts +4 -4
  29. package/all/binary_sort_rank/index.d.ts +3 -2
  30. package/all/binary_sort_rank/index.js +2 -1
  31. package/all/bind_apply/index.js +4 -4
  32. package/all/bind_call/index.js +1 -1
  33. package/all/bind_map_apply/index.js +1 -1
  34. package/all/bind_map_call/index.js +4 -5
  35. package/all/btoa/index.js +2 -1
  36. package/all/btoa_Uint32Array/index.js +2 -1
  37. package/all/call/index.js +2 -1
  38. package/all/call_assign/index.js +2 -1
  39. package/all/chain/index.js +3 -2
  40. package/all/clone_assign_fn_key_a/index.js +2 -1
  41. package/all/color_hsv_phi_rgb_a/index.js +3 -2
  42. package/all/color_invert_rgb_a/index.js +3 -2
  43. package/all/compact_a_ctx/index.js +2 -1
  44. package/all/compare/index.js +2 -1
  45. package/all/compose/index.js +5 -5
  46. package/all/concat_truthy_a/index.js +4 -2
  47. package/all/console__error/index.js +2 -1
  48. package/all/crypto__sign/index.js +2 -1
  49. package/all/currency_str/index.js +2 -1
  50. package/all/currency_symbol/index.js +2 -1
  51. package/all/curry/index.js +2 -2
  52. package/all/date/index.js +1 -1
  53. package/all/deep_equal/index.d.ts +1 -0
  54. package/all/deep_equal/index.js +54 -0
  55. package/all/default_arg_a/index.d.ts +11 -0
  56. package/all/default_arg_a/index.js +41 -0
  57. package/all/dfn_flag_r/index.d.ts +8 -0
  58. package/all/dfn_flag_r/index.js +24 -0
  59. package/all/difference_a/index.js +4 -2
  60. package/all/each/index.js +2 -1
  61. package/all/ensure__refresh/index.js +3 -2
  62. package/all/eq/index.js +5 -3
  63. package/all/eql_fn_a/index.js +1 -1
  64. package/all/error__print/index.js +4 -2
  65. package/all/error_o/index.js +4 -2
  66. package/all/falsy__none/index.js +2 -1
  67. package/all/fetch/index.js +2 -1
  68. package/all/fetch__template_pair/index.js +2 -1
  69. package/all/fetch_method/index.js +2 -1
  70. package/all/fetch_response_pair/index.js +4 -2
  71. package/all/filter/index.js +2 -1
  72. package/all/filter_o/index.js +3 -2
  73. package/all/find/index.js +1 -1
  74. package/all/flag_a/index.d.ts +6 -0
  75. package/all/flag_a/index.js +13 -0
  76. package/all/flag_r/index.d.ts +8 -0
  77. package/all/flag_r/index.js +34 -0
  78. package/all/flag_r__pick/index.d.ts +11 -0
  79. package/all/flag_r__pick/index.js +31 -0
  80. package/all/flag_r_arg_a/index.d.ts +9 -0
  81. package/all/flag_r_arg_a/index.js +27 -0
  82. package/all/flag_r_param_name/index.d.ts +9 -0
  83. package/all/flag_r_param_name/index.js +24 -0
  84. package/all/flag_regex/index.d.ts +1 -0
  85. package/all/flag_regex/index.js +1 -0
  86. package/all/flatten/index.js +7 -7
  87. package/all/flip/index.js +3 -2
  88. package/all/head_arg_a/index.js +3 -2
  89. package/all/headers/index.js +1 -1
  90. package/all/hex__digest/index.js +2 -1
  91. package/all/hmac/index.js +2 -1
  92. package/all/hmac_key/index.js +2 -1
  93. package/all/html/index.d.ts +4 -0
  94. package/all/html/index.js +15 -0
  95. package/all/html/index.test.ts +9 -0
  96. package/all/html_attr/index.d.ts +6 -0
  97. package/all/html_attr/index.js +19 -0
  98. package/all/html_attr/index.test.ts +10 -0
  99. package/all/html_attrs/index.d.ts +5 -0
  100. package/all/html_attrs/index.js +28 -0
  101. package/all/html_attrs/index.test.ts +36 -0
  102. package/all/html_class/index.d.ts +10 -0
  103. package/all/html_class/index.js +32 -0
  104. package/all/html_class/index.test.ts +32 -0
  105. package/all/html_dataset__data_attrs/index.d.ts +1 -0
  106. package/all/html_dataset__data_attrs/index.js +11 -0
  107. package/all/html_dataset__data_attrs/index.test.ts +13 -0
  108. package/all/html_style/index.d.ts +10 -0
  109. package/all/html_style/index.js +47 -0
  110. package/all/html_style/index.test.ts +92 -0
  111. package/all/html_style__assign/index.d.ts +8 -0
  112. package/all/html_style__assign/index.js +15 -0
  113. package/all/html_styles_o/index.d.ts +6 -0
  114. package/all/html_styles_o/index.js +18 -0
  115. package/all/html_styles_o/index.test.ts +10 -0
  116. package/all/http_error/index.js +4 -2
  117. package/all/idx/index.js +2 -1
  118. package/all/idx_filter/index.js +2 -2
  119. package/all/idx_key_r/index.js +5 -4
  120. package/all/idx_reject/index.js +1 -1
  121. package/all/idx_sort_a__sort_idx_o/index.js +2 -1
  122. package/all/import_meta_env/index.d.ts +10 -0
  123. package/all/import_meta_env/index.js +18 -0
  124. package/all/index.d.ts +33 -0
  125. package/all/index.js +33 -0
  126. package/all/intersection_a/index.js +4 -2
  127. package/all/intersection_by/index.js +2 -1
  128. package/all/invalid_state/index.js +2 -2
  129. package/all/is_development/index.d.ts +6 -0
  130. package/all/is_development/index.js +9 -0
  131. package/all/is_production/index.d.ts +9 -0
  132. package/all/is_production/index.js +12 -0
  133. package/all/is_staging/index.d.ts +9 -0
  134. package/all/is_staging/index.js +12 -0
  135. package/all/item_r_idx/index.js +2 -1
  136. package/all/js_html/index.d.ts +10 -0
  137. package/all/js_html/index.js +17 -0
  138. package/all/left_and/index.js +2 -1
  139. package/all/left_or/index.js +2 -1
  140. package/all/line__parse/index.js +2 -3
  141. package/all/line__transform_stream/index.js +1 -1
  142. package/all/links_html/index.d.ts +9 -0
  143. package/all/links_html/index.js +16 -0
  144. package/all/many_andand/index.js +4 -2
  145. package/all/many_andand_or/index.js +6 -3
  146. package/all/map/index.js +1 -1
  147. package/all/map_andand/index.js +1 -1
  148. package/all/map_andand_or/index.js +3 -2
  149. package/all/map_andandfn/index.js +2 -1
  150. package/all/map_apply/index.js +2 -1
  151. package/all/map_call/index.js +3 -2
  152. package/all/map_find/index.js +1 -1
  153. package/all/map_obj/index.js +3 -2
  154. package/all/map_obj_andand/index.js +1 -1
  155. package/all/missing_argument/index.js +3 -2
  156. package/all/missing_env__throw/index.d.ts +8 -0
  157. package/all/missing_env__throw/index.js +19 -0
  158. package/all/money_str/index.js +2 -2
  159. package/all/neq/index.js +2 -1
  160. package/all/not/index.js +4 -3
  161. package/all/not_found/index.js +1 -1
  162. package/all/nullish__none/index.js +1 -1
  163. package/all/nullish__not_all/index.js +1 -1
  164. package/all/number__count/index.js +2 -2
  165. package/all/o_a_present/index.js +1 -1
  166. package/all/one_andand/index.js +2 -1
  167. package/all/one_andand_or/index.js +3 -2
  168. package/all/or/index.js +2 -3
  169. package/all/or_null/index.js +2 -1
  170. package/all/param_dfn/index.d.ts +1 -0
  171. package/all/param_dfn/index.js +1 -0
  172. package/all/param_dfn_a_reducer/index.d.ts +9 -0
  173. package/all/param_dfn_a_reducer/index.js +12 -0
  174. package/all/param_dfn_split_regex/index.d.ts +1 -0
  175. package/all/param_dfn_split_regex/index.js +1 -0
  176. package/all/param_name_r_param_val_a/index.d.ts +11 -0
  177. package/all/param_name_r_param_val_a/index.js +29 -0
  178. package/all/param_r/index.d.ts +16 -0
  179. package/all/param_r/index.js +33 -0
  180. package/all/param_r/index.test.ts +28 -0
  181. package/all/parseFloat_andor/index.d.ts +3 -2
  182. package/all/parseFloat_andor/index.test.ts +1 -1
  183. package/all/promise_o/index.js +2 -1
  184. package/all/rank/index.d.ts +1 -1
  185. package/all/rank/index.js +2 -1
  186. package/all/reduce/index.js +1 -1
  187. package/all/reject/index.js +1 -1
  188. package/all/response_o/index.js +2 -3
  189. package/all/right_and/index.js +2 -1
  190. package/all/right_or/index.js +2 -1
  191. package/all/selector_splice/index.d.ts +1 -1
  192. package/all/slice/index.d.ts +2 -2
  193. package/all/slice_arg_a/index.js +3 -2
  194. package/all/slice_arg_spread_a/index.js +3 -2
  195. package/all/sort/index.d.ts +1 -1
  196. package/all/sort/index.js +1 -1
  197. package/all/sort_a/index.js +1 -1
  198. package/all/sort_idx_a/index.js +1 -1
  199. package/all/sort_idx_o/index.js +5 -4
  200. package/all/sort_val_a/index.js +1 -1
  201. package/all/sort_val_a__transition_idx_a/index.js +1 -3
  202. package/all/splice/index.d.ts +2 -2
  203. package/all/spread/index.js +1 -1
  204. package/all/spread_slice/index.js +2 -1
  205. package/all/tap/index.js +1 -1
  206. package/all/tempfile_path/index.test.ts +1 -1
  207. package/all/unauthorized/index.js +1 -1
  208. package/all/unformat_currency_str/index.js +1 -2
  209. package/all/union_a/index.js +3 -2
  210. package/all/union_by/index.js +1 -1
  211. package/all/url__join/index.js +2 -1
  212. package/all/weak_r/index.js +1 -1
  213. package/all/wrap_a/index.js +8 -5
  214. package/all/wrap_aa/index.js +3 -2
  215. package/all/wrap_concat/index.js +4 -3
  216. package/all/zip_with/index.js +1 -1
  217. package/array/index.d.ts +1 -0
  218. package/array/index.js +1 -0
  219. package/cli-args/index.d.ts +14 -0
  220. package/cli-args/index.js +14 -0
  221. package/deep_equal/index.d.ts +1 -0
  222. package/deep_equal/index.js +1 -0
  223. package/env/index.d.ts +8 -0
  224. package/env/index.js +8 -0
  225. package/html/index.d.ts +41 -0
  226. package/html/index.js +41 -0
  227. package/package.json +18 -8
@@ -0,0 +1,10 @@
1
+ import type { be_sig_triple_T } from 'rmemo'
2
+ export declare const [
3
+ CACHE_VERSION$_,
4
+ CACHE_VERSION_,
5
+ CACHE_VERSION__set,
6
+ ]:be_sig_triple_T<false|string>
7
+ export {
8
+ CACHE_VERSION$_ as CACHE_VERSION__,
9
+ CACHE_VERSION$_ as b__CACHE_VERSION,
10
+ }
@@ -0,0 +1,14 @@
1
+ /// <reference types="ctx-core" />
2
+ import { be_sig_triple_ } from '../be_sig_triple/index.js'
3
+ import { import_meta_env_ } from '../import_meta_env/index.js'
4
+ export const [
5
+ CACHE_VERSION$_,
6
+ CACHE_VERSION_,
7
+ CACHE_VERSION__set,
8
+ ] = /** @type {be_sig_triple_T<false|string>} */ be_sig_triple_(()=>
9
+ typeof process === 'object' && import_meta_env_().CACHE_VERSION,
10
+ { id: 'CACHE_VERSION' })
11
+ export {
12
+ CACHE_VERSION$_ as CACHE_VERSION__,
13
+ CACHE_VERSION$_ as b__CACHE_VERSION,
14
+ }
@@ -0,0 +1,10 @@
1
+ import type { be_sig_triple_T } from 'rmemo'
2
+ export declare const [
3
+ NODE_ENV$_,
4
+ NODE_ENV_,
5
+ NODE_ENV__set,
6
+ ]:be_sig_triple_T<string>
7
+ export {
8
+ NODE_ENV$_ as NODE_ENV__,
9
+ NODE_ENV$_ as b__NODE_ENV,
10
+ }
@@ -0,0 +1,14 @@
1
+ /// <reference types="ctx-core" />
2
+ import { be_sig_triple_ } from '../be_sig_triple/index.js'
3
+ import { import_meta_env_ } from '../import_meta_env/index.js'
4
+ export const [
5
+ NODE_ENV$_,
6
+ NODE_ENV_,
7
+ NODE_ENV__set,
8
+ ] = be_sig_triple_(()=>
9
+ import_meta_env_().NODE_ENV,
10
+ { id: 'NODE_ENV' })
11
+ export {
12
+ NODE_ENV$_ as NODE_ENV__,
13
+ NODE_ENV$_ as b__NODE_ENV,
14
+ }
@@ -1,2 +1,3 @@
1
- /** @type {import('../Request/index.d.ts').Request} */
1
+ /// <reference types="../index.d.ts" />
2
+ /** @type {Request} */
2
3
  export const { Request, RequestInit } = globalThis
@@ -1,2 +1,2 @@
1
- /** @type {import('../Response/index.d.ts').Response} */
1
+ /** @type {import('../Response/index.d.ts').Response}Response */
2
2
  export const { Response } = globalThis
@@ -0,0 +1,7 @@
1
+ import type { be_sig_triple_T } from 'rmemo'
2
+ export declare const [
3
+ VERSION$_,
4
+ VERSION_,
5
+ VERSION__set,
6
+ ]:be_sig_triple_T<string>
7
+ export { VERSION$_ as VERSION__ }
@@ -0,0 +1,12 @@
1
+ import { be_sig_triple_ } from '../be_sig_triple/index.js'
2
+ import { import_meta_env_ } from '../import_meta_env/index.js'
3
+ export const [
4
+ VERSION$_,
5
+ VERSION_,
6
+ VERSION__set,
7
+ ] = be_sig_triple_(()=>
8
+ typeof process === 'object'
9
+ && (import_meta_env_().VERSION || import_meta_env_().HEROKU_SLUG_COMMIT)
10
+ || Math.random().toString(),
11
+ { id: 'VERSION' })
12
+ export { VERSION$_ as VERSION__ }
package/all/add/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @typedef {import('../nullish/index.d.ts').nullish} */
1
+ /// <reference types="../nullish/index.d.ts" />
2
2
  /**
3
3
  * Adds the arguments
4
4
  * @param {readonly (number|nullish)[]|nullish}numerator_a
@@ -1,4 +1,4 @@
1
- /** @typedef {import('../add/index.js').all_union_a_T} */
1
+ /// <reference types="../add/index.d.ts" />
2
2
  /**
3
3
  * @return {(a:all_union_a_T)=>all_union_a_T}
4
4
  * @see {@link https://stackoverflow.com/questions/60131681/make-sure-array-has-all-types-from-a-union/75418615#75418615}
package/all/and/index.js CHANGED
@@ -1,8 +1,9 @@
1
+ /// <reference types="../a_nowrap/index.d.ts" />
1
2
  import { wrap_a_ } from '../wrap_a/index.js'
2
3
  import { wrap_concat } from '../wrap_concat/index.js'
3
4
  /**
4
5
  * Returns the first falsy or last item in `a_nowrap`.
5
- * @param {import('../a_nowrap/index.js').a_nowrap_T}a_nowrap
6
+ * @param {a_nowrap_T}a_nowrap
6
7
  * @returns {unknown}
7
8
  */
8
9
  export function and(a_nowrap) {
@@ -1,5 +1,6 @@
1
+ /// <reference types="../andand/index.d.ts" />
1
2
  import { andand } from '../andand/index.js'
2
- /** @typedef {import('../andand/index.js').andand_key_T} */
3
+ /** @typedef {andand_key_T} */
3
4
  /**
4
5
  * Returns `andand(obj, name_a) || or_fn(obj, val)`
5
6
  * @param {unknown|null}obj
@@ -1,4 +1,5 @@
1
- /** @typedef {import('../andand/index.js').andand_key_T} */
1
+ /// <reference types="../andand/index.d.ts" />
2
+ /// <reference types="../andandfn/index.d.ts" />
2
3
  /**
3
4
  * Applies `&&` to a chain of property name or function with return value from `obj`.
4
5
  * @param {unknown}obj
@@ -24,11 +25,11 @@ export function andandfn(obj, ...name_a) {
24
25
  return out_value
25
26
  }
26
27
  export { andandfn as andand__fn, }
27
- /** @typedef {import('../andand/index.d.ts').andand_key_T} */
28
+ /** @typedef {andand_key_T} */
28
29
  /**
29
30
  * Returns a function that calls `andand_(obj, ...name_a)`
30
31
  * @param {andand_key_T}name_a
31
- * @returns {import('../andandfn').andandfn_T}
32
+ * @returns {andandfn_T}
32
33
  */
33
34
  export function andandfn_(...name_a) {
34
35
  return (obj)=>andandfn(obj, ...name_a)
@@ -1,9 +1,11 @@
1
- /** @typedef {import('../call/index.d.ts').call_fn_T} */
1
+ /// <reference types="../bind_call/index.d.ts" />
2
+ /// <reference types="../call/index.d.ts" />
3
+ /** @typedef {call_fn_T} */
2
4
  /**
3
5
  * Returns function that applies in_arg_a with ...fn_arg_a
4
6
  * @param {call_fn_T}fn
5
7
  * @param {unknown[]}[in_arg_a]
6
- * @returns {import('../bind_call').bind_call_T}
8
+ * @returns {bind_call_T}
7
9
  */
8
10
  export function apply_(fn, in_arg_a = []) {
9
11
  return (...fn_arg_a)=>fn(...[
@@ -0,0 +1,6 @@
1
+ import type { param_dfn_T } from '../param_dfn/index.js'
2
+ export declare function arg_a__pick(
3
+ arg_a:string[],
4
+ ...param_dfn_a:param_dfn_T[]
5
+ ):string[]
6
+ export { arg_a__pick as pick_arg_a1, }
@@ -0,0 +1,16 @@
1
+ /// <reference types="../_types/index.js" />
2
+ import { flag_r__pick } from '../flag_r__pick/index.js'
3
+ import { flag_r_arg_a_ } from '../flag_r_arg_a/index.js'
4
+ /**
5
+ * @param {string[]}arg_a
6
+ * @param {param_dfn_T}param_dfn_a
7
+ * @returns {string[]}
8
+ */
9
+ export function arg_a__pick(
10
+ arg_a,
11
+ ...param_dfn_a
12
+ ) {
13
+ const pick_flag_R = flag_r__pick(arg_a, ...param_dfn_a)
14
+ return flag_r_arg_a_(pick_flag_R, arg_a)
15
+ }
16
+ export { arg_a__pick as pick_arg_a1, }
@@ -1,9 +1,10 @@
1
+ /// <reference types="../slice_arg_spread_a/index.d.ts" />
1
2
  import { slice_arg_spread_a_ } from '../slice_arg_spread_a/index.js'
2
- /** @typedef {import('../slice_arg_spread_a_/index.js').slice_arg_spread_a__arg__T} */
3
+ /** @typedef {slice_arg_spread_a__arg__T} */
3
4
  /**
4
5
  * Returns a function that calls fn passing only the first argument.
5
6
  * @param {slice_arg_spread_a__arg__T}fn
6
- * @returns {import('../slice_arg_spread_a_').slice_arg_spread_a___ret_T}
7
+ * @returns {slice_arg_spread_a___ret_T}
7
8
  */
8
9
  export function arg_i0_a(fn) {
9
10
  return slice_arg_spread_a_(fn, 0, 1)
@@ -1,4 +1,4 @@
1
- /** @typedef {import('../assign_fn_key_a/index.js').fn_key_a_tuple_T} */
1
+ /// <reference types="../assign_fn_key_a/index.d.ts" />
2
2
  /**
3
3
  * Assigns to an obj array of keys the return value of function in key_a_fn_aa.
4
4
  * @param {object}obj
@@ -1,6 +1,7 @@
1
+ /// <reference types="../error_o/index.d.ts" />
1
2
  import { assign } from '../assign/index.js'
2
3
  import { HttpError } from '../http_error/index.js'
3
- /** @typedef {import('../error_o/index.d.ts').argument__error_o_T} */
4
+ /** @typedef {argument__error_o_T} */
4
5
  export const bad_gateway__default__message = 'Bad Gateway'
5
6
  /**
6
7
  * @param {string}[message]
@@ -1,6 +1,6 @@
1
+ /// <reference types="../error_o/index.d.ts" />
1
2
  import { assign } from '../assign/index.js'
2
3
  import { HttpError } from '../http_error/index.js'
3
- /** @typedef {import('../error_o/index.d.ts').argument__error_o_T} */
4
4
  export const bad_request__default__message = 'Bad Request'
5
5
  /**
6
6
  * @param {string}[message]
package/all/be/index.js CHANGED
@@ -1,7 +1,8 @@
1
+ /// <reference types="../be_/index.d.ts" />
1
2
  import { be_ } from '../be_/index.js'
2
3
  /**
3
- * @param {import('../be_/index.js').Ctx}ctx
4
- * @param {import('../be_/index.js').be__val__new_T}val_
4
+ * @param {Ctx}ctx
5
+ * @param {be__val__new_T}val_
5
6
  * @returns {NonNullable<unknown>}
6
7
  */
7
8
  export function be(ctx, val_) {
@@ -37,6 +37,12 @@ export declare function ctx__delete<
37
37
  be_OR_id:Be<unknown, ns_T, ctx_T>|string|symbol,
38
38
  ns?:string
39
39
  ):void
40
+ /**
41
+ * Clear all BeMap values by running ctx__delete on all stored Be functions.
42
+ * This behavior can be used in conjunction with ondelete_be_ to run the ondelete callbacks
43
+ * on all of the ondelete_be functions.
44
+ */
45
+ export declare function ctx__clear(ctx:Ctx):void
40
46
  export declare function be__has_<
41
47
  ns_T extends string = '',
42
48
  ctx_T extends Ctx = Ctx_wide_T<ns_T>,
@@ -50,11 +56,27 @@ export declare function be__val_<
50
56
  ns_T extends string = '',
51
57
  ctx_T extends Ctx = Ctx_wide_T<ns_T>,
52
58
  >(be_OR_id:Be<val_T, ns_T, ctx_T>|string, ctx:ctx_T, ns?:ns_T):val_T|unknown|null
53
- export declare type Be<
59
+ export declare function ondelete_be_<
60
+ val_T,
61
+ ns_T extends string = '',
62
+ ctx_T extends Ctx = Ctx_wide_T<ns_T>,
63
+ >(
64
+ val__new:ondelete_be__val__new_T<val_T, ns_T, ctx_T>,
65
+ config?:be_config_T<ns_T>
66
+ ):ondelete_Be<val_T, ns_T, ctx_T>
67
+ export type Be<
54
68
  val_T,
55
69
  ns_T extends string = '',
56
70
  ctx_T extends Ctx = Ctx_wide_T<ns_T>,
57
71
  > = ((ctx:ctx_T)=>val_T)&be_o_T<val_T, ns_T, ctx_T>
72
+ export type ondelete_Be<
73
+ val_T,
74
+ ns_T extends string = '',
75
+ ctx_T extends Ctx = Ctx_wide_T<ns_T>,
76
+ > = ((ctx:ctx_T)=>val_T)&be_o_T<val_T, ns_T, ctx_T>&{
77
+ ondelete(cb:(val:val_T, ctx:ctx_T, be:Be<val_T, ns_T, ctx_T>)=>void):void
78
+ d():void
79
+ }
58
80
  export type be_o_T<
59
81
  val_T,
60
82
  ns_T extends string = '',
@@ -70,14 +92,27 @@ export type be_config_T<ns_T extends string = string> = {
70
92
  }
71
93
  export type BeMap<
72
94
  ns_T extends string = ''
73
- > = Map<Be<unknown, ns_T, Ctx_wide_T<ns_T>>|string|symbol, unknown>
95
+ > =
96
+ Map<
97
+ Be<unknown, ns_T, Ctx_wide_T<ns_T>>|string|symbol,
98
+ [unknown, Be<unknown, ns_T, Ctx_wide_T<ns_T>>, Ctx_wide_T<ns_T>]
99
+ >
74
100
  export type BeMapO<ns_union_T extends string> =
75
101
  { [K in ns_union_T]:BeMap<K> }
76
- export declare type be__val__new_T<
102
+ export type be__val__new_T<
77
103
  val_T,
78
104
  ns_T extends string = '',
79
105
  ctx_T extends Ctx = Ctx_wide_T<ns_T>
80
106
  > = (ctx:ctx_T, be:Be<val_T, ns_T, ctx_T>)=>val_T
107
+ export type ondelete_be__val__new_T<
108
+ val_T,
109
+ ns_T extends string = '',
110
+ ctx_T extends Ctx = Ctx_wide_T<ns_T>
111
+ > =
112
+ (
113
+ ctx:ctx_T,
114
+ be:ondelete_Be<val_T, ns_T, ctx_T>
115
+ )=>val_T
81
116
  export type Ctx<ns_T extends string = string> = Readonly<{
82
117
  s:Ctx_s_T<ns_T>
83
118
  is_ctx:true
package/all/be_/index.js CHANGED
@@ -17,13 +17,23 @@ export function be_(val__new, config) {
17
17
  // ~ 30 B
18
18
  if (!be_map) throw Error('ctx_no_ns: \'' + be.ns + '\'')
19
19
  /* @endif */
20
- if (be_map.has(be.id)) return be_map.get(be.id)
21
- // circular dependency state
22
- // if val__new calls this be before returning, 'cir' will be the value of this be
23
- // 'cir' is used instead of 'circular' to reduce the payload by a few bytes
24
- be_map.set(be.id, 'cir')
25
- be_map.set(be.id, val__new(ctx, be))
26
- return be_map.get(be.id)
20
+ // config is not used anymore so reusing to reduce bundle size
21
+ config = be_map.get(be.id)
22
+ if (config) return config[0]
23
+ /* @if DEBUG **
24
+ // 5-11 B
25
+ // circular dependency state
26
+ // if val__new calls this be before returning, 'cir' will be the value of this be
27
+ // 'cir' is used instead of 'circular' to reduce the payload by a few bytes
28
+ config = ['cir', ctx, be]
29
+ be_map.set(be.id, config)
30
+ config[0] = val__new(ctx, be)
31
+ /* @endif */
32
+ /* @if !DEBUG */
33
+ config = [val__new(ctx, be), ctx, be]
34
+ be_map.set(be.id, config)
35
+ /* @endif */
36
+ return config[0]
27
37
  }
28
38
  be.id = config?.id ?? be
29
39
  be.ns = config?.ns ?? ''
@@ -57,7 +67,13 @@ export function ctx__set(
57
67
  val,
58
68
  ns = be_OR_id.ns ?? ''
59
69
  ) {
60
- ctx.s[ns].set(be_OR_id.id ?? be_OR_id, val)
70
+ let state =
71
+ ctx.s[ns].get(be_OR_id.id ?? be_OR_id)
72
+ ?? [val, be_OR_id.id ?? be_OR_id, ctx]
73
+ // ondelete
74
+ if (state[1] !== (be_OR_id.id ?? be_OR_id)) state[1].d?.(...state)
75
+ state[0] = val
76
+ ctx.s[ns].set(state[1], state)
61
77
  }
62
78
  /**
63
79
  * @param {Ctx}ctx
@@ -69,11 +85,22 @@ export function ctx__delete(
69
85
  be_OR_id,
70
86
  ns = be_OR_id.ns ?? ''
71
87
  ) {
72
- if (ns != null) {
73
- ctx.s[ns].delete(be_OR_id.id ?? be_OR_id)
74
- } else {
75
- for (let _source in ctx.s) {
76
- ctx.s[_source].delete(be_OR_id.id ?? be_OR_id)
88
+ let state = ctx.s[ns].get(be_OR_id.id ?? be_OR_id)
89
+ if (state) {
90
+ state[2].d?.(...state)
91
+ ctx.s[ns].delete(state[2].id)
92
+ }
93
+ }
94
+ /**
95
+ * Clear all BeMap values by running ctx__delete on all stored Be functions.
96
+ * This behavior can be used in conjunction with ondelete_be_ to run the ondelete callbacks
97
+ * on all of the ondelete_be functions.
98
+ * @param {Ctx}ctx
99
+ */
100
+ export function ctx__clear(ctx) {
101
+ for (let ns in ctx.s) {
102
+ for (let id of ctx.s[ns].keys()) {
103
+ ctx__delete(ctx, id)
77
104
  }
78
105
  }
79
106
  }
@@ -103,5 +130,16 @@ export function be_map__find(be_or_id, ctx, ns = be_or_id.ns ?? '') {
103
130
  * @private
104
131
  */
105
132
  export function be__val_(be_or_id, ctx, ns) {
106
- return be_map__find(be_or_id, ctx, ns)?.get?.(be_or_id.id ?? be_or_id)
133
+ return be_map__find(be_or_id, ctx, ns)?.get?.(be_or_id.id ?? be_or_id)?.[0]
134
+ }
135
+ export function ondelete_be_(val__new, config) {
136
+ let be = be_(val__new, config)
137
+ let ondelete_cb_a = []
138
+ be.ondelete = cb=>ondelete_cb_a.push(cb)
139
+ be.d = (...state)=>{
140
+ for (let ondelete_cb of ondelete_cb_a) {
141
+ ondelete_cb(...state)
142
+ }
143
+ }
144
+ return be
107
145
  }