ctx-core 5.1.0 → 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.
- package/all/CACHE_VERSION/index.d.ts +10 -0
- package/all/CACHE_VERSION/index.js +14 -0
- package/all/NODE_ENV/index.d.ts +10 -0
- package/all/NODE_ENV/index.js +14 -0
- package/all/Request/index.js +2 -1
- package/all/Response/index.js +1 -1
- package/all/VERSION/index.d.ts +7 -0
- package/all/VERSION/index.js +12 -0
- package/all/add/index.js +1 -1
- package/all/all_union_a/index.js +1 -1
- package/all/and/index.js +2 -1
- package/all/andand_or/index.js +2 -1
- package/all/andandfn/index.js +4 -3
- package/all/apply/index.js +4 -2
- package/all/arg_a__pick/index.d.ts +6 -0
- package/all/arg_a__pick/index.js +16 -0
- package/all/arg_i0_a/index.js +3 -2
- package/all/assign_fn_key_a/index.js +1 -1
- package/all/bad_gateway/index.js +2 -1
- package/all/bad_request/index.js +1 -1
- package/all/be/index.js +3 -2
- package/all/be_/index.d.ts +38 -3
- package/all/be_/index.js +52 -14
- package/all/be_/index.test.ts +191 -90
- package/all/be_lock_memosig_triple/index.test.ts +6 -6
- package/all/be_memo_pair/index.test.ts +4 -4
- package/all/be_memosig_triple/index.test.ts +6 -6
- package/all/be_sig_triple/index.test.ts +4 -4
- package/all/binary_sort_rank/index.js +2 -1
- package/all/bind_apply/index.js +4 -4
- package/all/bind_call/index.js +1 -1
- package/all/bind_map_apply/index.js +1 -1
- package/all/bind_map_call/index.js +4 -5
- package/all/btoa/index.js +2 -1
- package/all/btoa_Uint32Array/index.js +2 -1
- package/all/call/index.js +2 -1
- package/all/call_assign/index.js +2 -1
- package/all/chain/index.js +3 -2
- package/all/clone_assign_fn_key_a/index.js +2 -1
- package/all/color_hsv_phi_rgb_a/index.js +3 -2
- package/all/color_invert_rgb_a/index.js +3 -2
- package/all/compact_a_ctx/index.js +2 -1
- package/all/compare/index.js +2 -1
- package/all/compose/index.js +5 -5
- package/all/concat_truthy_a/index.js +4 -2
- package/all/console__error/index.js +2 -1
- package/all/crypto__sign/index.js +2 -1
- package/all/currency_str/index.js +2 -1
- package/all/currency_symbol/index.js +2 -1
- package/all/curry/index.js +2 -2
- package/all/date/index.js +1 -1
- package/all/default_arg_a/index.d.ts +11 -0
- package/all/default_arg_a/index.js +41 -0
- package/all/dfn_flag_r/index.d.ts +8 -0
- package/all/dfn_flag_r/index.js +24 -0
- package/all/difference_a/index.js +4 -2
- package/all/each/index.js +2 -1
- package/all/ensure__refresh/index.js +3 -2
- package/all/eq/index.js +5 -3
- package/all/eql_fn_a/index.js +1 -1
- package/all/error__print/index.js +4 -2
- package/all/error_o/index.js +4 -2
- package/all/falsy__none/index.js +2 -1
- package/all/fetch/index.js +2 -1
- package/all/fetch__template_pair/index.js +2 -1
- package/all/fetch_method/index.js +2 -1
- package/all/fetch_response_pair/index.js +4 -2
- package/all/filter/index.js +2 -1
- package/all/filter_o/index.js +3 -2
- package/all/find/index.js +1 -1
- package/all/flag_a/index.d.ts +6 -0
- package/all/flag_a/index.js +13 -0
- package/all/flag_r/index.d.ts +8 -0
- package/all/flag_r/index.js +34 -0
- package/all/flag_r__pick/index.d.ts +11 -0
- package/all/flag_r__pick/index.js +31 -0
- package/all/flag_r_arg_a/index.d.ts +9 -0
- package/all/flag_r_arg_a/index.js +27 -0
- package/all/flag_r_param_name/index.d.ts +9 -0
- package/all/flag_r_param_name/index.js +24 -0
- package/all/flag_regex/index.d.ts +1 -0
- package/all/flag_regex/index.js +1 -0
- package/all/flatten/index.js +7 -7
- package/all/flip/index.js +3 -2
- package/all/head_arg_a/index.js +3 -2
- package/all/headers/index.js +1 -1
- package/all/hex__digest/index.js +2 -1
- package/all/hmac/index.js +2 -1
- package/all/hmac_key/index.js +2 -1
- package/all/html/index.d.ts +0 -1
- package/all/html/index.js +0 -4
- package/all/html_attr/index.d.ts +0 -2
- package/all/html_attr/index.js +0 -2
- package/all/html_attrs/index.d.ts +0 -1
- package/all/html_attrs/index.js +0 -1
- package/all/html_class/index.d.ts +0 -2
- package/all/html_class/index.js +0 -2
- package/all/html_dataset__data_attrs/index.d.ts +0 -1
- package/all/html_dataset__data_attrs/index.js +0 -1
- package/all/html_style/index.d.ts +0 -2
- package/all/html_style/index.js +0 -2
- package/all/html_style__assign/index.d.ts +2 -6
- package/all/html_style__assign/index.js +0 -5
- package/all/html_styles_o/index.d.ts +0 -5
- package/all/html_styles_o/index.js +0 -5
- package/all/http_error/index.js +4 -2
- package/all/idx/index.js +2 -1
- package/all/idx_filter/index.js +2 -2
- package/all/idx_key_r/index.js +5 -4
- package/all/idx_reject/index.js +1 -1
- package/all/idx_sort_a__sort_idx_o/index.js +2 -1
- package/all/import_meta_env/index.d.ts +10 -0
- package/all/import_meta_env/index.js +18 -0
- package/all/index.d.ts +22 -0
- package/all/index.js +22 -0
- package/all/intersection_a/index.js +4 -2
- package/all/intersection_by/index.js +2 -1
- package/all/invalid_state/index.js +2 -2
- package/all/is_development/index.d.ts +6 -0
- package/all/is_development/index.js +9 -0
- package/all/is_production/index.d.ts +9 -0
- package/all/is_production/index.js +12 -0
- package/all/is_staging/index.d.ts +9 -0
- package/all/is_staging/index.js +12 -0
- package/all/item_r_idx/index.js +2 -1
- package/all/js_html/index.d.ts +0 -4
- package/all/js_html/index.js +0 -4
- package/all/left_and/index.js +2 -1
- package/all/left_or/index.js +2 -1
- package/all/line__parse/index.js +2 -3
- package/all/line__transform_stream/index.js +1 -1
- package/all/links_html/index.d.ts +0 -5
- package/all/links_html/index.js +0 -4
- package/all/many_andand/index.js +4 -2
- package/all/many_andand_or/index.js +6 -3
- package/all/map/index.js +1 -1
- package/all/map_andand/index.js +1 -1
- package/all/map_andand_or/index.js +3 -2
- package/all/map_andandfn/index.js +2 -1
- package/all/map_apply/index.js +2 -1
- package/all/map_call/index.js +3 -2
- package/all/map_find/index.js +1 -1
- package/all/map_obj/index.js +3 -2
- package/all/map_obj_andand/index.js +1 -1
- package/all/missing_argument/index.js +3 -2
- package/all/missing_env__throw/index.d.ts +8 -0
- package/all/missing_env__throw/index.js +19 -0
- package/all/money_str/index.js +2 -2
- package/all/neq/index.js +2 -1
- package/all/not/index.js +4 -3
- package/all/not_found/index.js +1 -1
- package/all/nullish__none/index.js +1 -1
- package/all/nullish__not_all/index.js +1 -1
- package/all/number__count/index.js +2 -2
- package/all/o_a_present/index.js +1 -1
- package/all/one_andand/index.js +2 -1
- package/all/one_andand_or/index.js +3 -2
- package/all/or/index.js +2 -3
- package/all/or_null/index.js +2 -1
- package/all/param_dfn/index.d.ts +1 -0
- package/all/param_dfn/index.js +1 -0
- package/all/param_dfn_a_reducer/index.d.ts +9 -0
- package/all/param_dfn_a_reducer/index.js +12 -0
- package/all/param_dfn_split_regex/index.d.ts +1 -0
- package/all/param_dfn_split_regex/index.js +1 -0
- package/all/param_name_r_param_val_a/index.d.ts +11 -0
- package/all/param_name_r_param_val_a/index.js +29 -0
- package/all/param_r/index.d.ts +16 -0
- package/all/param_r/index.js +33 -0
- package/all/param_r/index.test.ts +28 -0
- package/all/parseFloat_andor/index.d.ts +3 -2
- package/all/parseFloat_andor/index.test.ts +1 -1
- package/all/promise_o/index.js +2 -1
- package/all/rank/index.js +2 -1
- package/all/reduce/index.js +1 -1
- package/all/reject/index.js +1 -1
- package/all/response_o/index.js +2 -3
- package/all/right_and/index.js +2 -1
- package/all/right_or/index.js +2 -1
- package/all/slice_arg_a/index.js +3 -2
- package/all/slice_arg_spread_a/index.js +3 -2
- package/all/sort/index.js +1 -1
- package/all/sort_a/index.js +1 -1
- package/all/sort_idx_a/index.js +1 -1
- package/all/sort_idx_o/index.js +5 -4
- package/all/sort_val_a/index.js +1 -1
- package/all/sort_val_a__transition_idx_a/index.js +1 -3
- package/all/spread/index.js +1 -1
- package/all/spread_slice/index.js +2 -1
- package/all/tap/index.js +1 -1
- package/all/tempfile_path/index.test.ts +1 -1
- package/all/unauthorized/index.js +1 -1
- package/all/unformat_currency_str/index.js +1 -2
- package/all/union_a/index.js +3 -2
- package/all/union_by/index.js +1 -1
- package/all/url__join/index.js +2 -1
- package/all/weak_r/index.js +1 -1
- package/all/wrap_a/index.js +8 -5
- package/all/wrap_aa/index.js +3 -2
- package/all/wrap_concat/index.js +4 -3
- package/all/zip_with/index.js +1 -1
- package/cli-args/index.d.ts +14 -0
- package/cli-args/index.js +14 -0
- package/env/index.d.ts +8 -0
- package/env/index.js +8 -0
- package/html/index.d.ts +31 -0
- package/html/index.js +31 -0
- package/package.json +13 -7
|
@@ -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,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
|
+
}
|
package/all/Request/index.js
CHANGED
package/all/Response/index.js
CHANGED
|
@@ -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,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
package/all/all_union_a/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
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 {
|
|
6
|
+
* @param {a_nowrap_T}a_nowrap
|
|
6
7
|
* @returns {unknown}
|
|
7
8
|
*/
|
|
8
9
|
export function and(a_nowrap) {
|
package/all/andand_or/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
/// <reference types="../andand/index.d.ts" />
|
|
1
2
|
import { andand } from '../andand/index.js'
|
|
2
|
-
/** @typedef {
|
|
3
|
+
/** @typedef {andand_key_T} */
|
|
3
4
|
/**
|
|
4
5
|
* Returns `andand(obj, name_a) || or_fn(obj, val)`
|
|
5
6
|
* @param {unknown|null}obj
|
package/all/andandfn/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
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 {
|
|
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 {
|
|
32
|
+
* @returns {andandfn_T}
|
|
32
33
|
*/
|
|
33
34
|
export function andandfn_(...name_a) {
|
|
34
35
|
return (obj)=>andandfn(obj, ...name_a)
|
package/all/apply/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
|
|
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 {
|
|
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,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, }
|
package/all/arg_i0_a/index.js
CHANGED
|
@@ -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 {
|
|
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 {
|
|
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)
|
package/all/bad_gateway/index.js
CHANGED
|
@@ -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 {
|
|
4
|
+
/** @typedef {argument__error_o_T} */
|
|
4
5
|
export const bad_gateway__default__message = 'Bad Gateway'
|
|
5
6
|
/**
|
|
6
7
|
* @param {string}[message]
|
package/all/bad_request/index.js
CHANGED
|
@@ -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 {
|
|
4
|
-
* @param {
|
|
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_) {
|
package/all/be_/index.d.ts
CHANGED
|
@@ -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
|
|
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
|
-
> =
|
|
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
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
}
|