ctx-core 5.33.0 → 5.35.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/be_/index.d.ts +9 -0
- package/all/be_/index.js +31 -17
- package/all/import_meta_env/index.d.ts +5 -5
- package/all/index.browser.js +1 -0
- package/all/index.d.ts +1 -0
- package/all/index.js +1 -0
- package/all/window__ctx__set/index.browser.d.ts +1 -0
- package/all/window__ctx__set/index.browser.js +24 -0
- package/all/window__ctx__set/index.d.ts +8 -0
- package/all/window__ctx__set/index.js +7 -0
- package/all/window__ctx__set/index.test.ts +43 -0
- package/package.json +7 -1
package/all/be_/index.d.ts
CHANGED
|
@@ -47,6 +47,15 @@ export declare function ns_id_be_<
|
|
|
47
47
|
id:string,
|
|
48
48
|
val__new:be__val__new_T<val_T, ns_T, ctx_T>
|
|
49
49
|
):Be<val_T, ns_T, ctx_T>
|
|
50
|
+
export declare function ctx__get<
|
|
51
|
+
val_T,
|
|
52
|
+
ns_T extends string = '',
|
|
53
|
+
ctx_T extends Ctx_wide_T<ns_T> = Ctx_wide_T<ns_T>,
|
|
54
|
+
>(
|
|
55
|
+
ctx:ctx_T,
|
|
56
|
+
be_OR_id:Be<val_T>|string|symbol,
|
|
57
|
+
ns?:ns_T
|
|
58
|
+
):val_T
|
|
50
59
|
export declare function ctx__set<
|
|
51
60
|
val_T,
|
|
52
61
|
ns_T extends string = '',
|
package/all/be_/index.js
CHANGED
|
@@ -14,21 +14,21 @@ export function be_(val__new, config) {
|
|
|
14
14
|
let be = ctx=>{
|
|
15
15
|
let be_map = ctx.s[be.ns]
|
|
16
16
|
/* @if DEBUG **
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
// ~ 30 B
|
|
18
|
+
if (!be_map) throw Error('ctx_no_ns: \'' + be.ns + '\'')
|
|
19
|
+
/* @endif */
|
|
20
20
|
// config is not used anymore so reusing to reduce bundle size
|
|
21
21
|
config = be_map.get(be.id)
|
|
22
22
|
if (config) return config[0]
|
|
23
23
|
/* @if DEBUG **
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
32
|
/* @if !DEBUG */
|
|
33
33
|
config = [val__new(ctx, be), ctx, be]
|
|
34
34
|
be_map.set(be.id, config)
|
|
@@ -81,6 +81,20 @@ export function ns_id_be_(ns, id, val__new) {
|
|
|
81
81
|
* @private
|
|
82
82
|
*/
|
|
83
83
|
export { be_ as globalThis__be_ }
|
|
84
|
+
/**
|
|
85
|
+
* @param {Ctx}ctx
|
|
86
|
+
* @param {Be|string|symbol}be_OR_id
|
|
87
|
+
* @param {string}[ns]
|
|
88
|
+
* @returns {unknown}
|
|
89
|
+
* @private
|
|
90
|
+
*/
|
|
91
|
+
export function ctx__get(
|
|
92
|
+
ctx,
|
|
93
|
+
be_OR_id,
|
|
94
|
+
ns = be_OR_id.ns ?? ''
|
|
95
|
+
) {
|
|
96
|
+
return ctx.s[ns].get(be_OR_id.id ?? be_OR_id)?.[0]
|
|
97
|
+
}
|
|
84
98
|
/**
|
|
85
99
|
* @param {Ctx}ctx
|
|
86
100
|
* @param {Be|string|symbol}be_OR_id
|
|
@@ -141,24 +155,24 @@ export function be__has_(...arg_a) {
|
|
|
141
155
|
return Boolean(be_map__find(...arg_a))
|
|
142
156
|
}
|
|
143
157
|
/**
|
|
144
|
-
* @param {Be}
|
|
158
|
+
* @param {Be}be_OR_id
|
|
145
159
|
* @param {Ctx}ctx
|
|
146
160
|
* @param {string}[ns]
|
|
147
161
|
* @returns {Ctx}
|
|
148
162
|
* @private
|
|
149
163
|
*/
|
|
150
|
-
export function be_map__find(
|
|
151
|
-
return ctx.s[ns].has(
|
|
164
|
+
export function be_map__find(be_OR_id, ctx, ns = be_OR_id.ns ?? '') {
|
|
165
|
+
return ctx.s[ns].has(be_OR_id.id ?? be_OR_id) ? ctx.s[ns] : _undefined
|
|
152
166
|
}
|
|
153
167
|
/**
|
|
154
|
-
* @param {Be|string}
|
|
168
|
+
* @param {Be|string}be_OR_id
|
|
155
169
|
* @param {Ctx}ctx
|
|
156
170
|
* @param {string}[ns]
|
|
157
171
|
* @returns {unknown}
|
|
158
172
|
* @private
|
|
159
173
|
*/
|
|
160
|
-
export function be__val_(
|
|
161
|
-
return be_map__find(
|
|
174
|
+
export function be__val_(be_OR_id, ctx, ns) {
|
|
175
|
+
return be_map__find(be_OR_id, ctx, ns)?.get?.(be_OR_id.id ?? be_OR_id)?.[0]
|
|
162
176
|
}
|
|
163
177
|
/**
|
|
164
178
|
* @param {be__val__new_T}val__new
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export function import_meta_env_<R extends
|
|
2
|
-
export function import_meta_env__ensure<R extends
|
|
1
|
+
export function import_meta_env_<R extends import_meta_env_T>():R
|
|
2
|
+
export function import_meta_env__ensure<R extends import_meta_env_T>():R
|
|
3
3
|
declare global {
|
|
4
|
-
interface
|
|
5
|
-
readonly env:
|
|
4
|
+
interface import_meta_T {
|
|
5
|
+
readonly env:import_meta_env_T
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
|
-
interface
|
|
8
|
+
interface import_meta_env_T {
|
|
9
9
|
[key:string]:string
|
|
10
10
|
}
|
package/all/index.browser.js
CHANGED
|
@@ -448,6 +448,7 @@ export * from './waitfor/index.browser.js'
|
|
|
448
448
|
export * from './waitfor_fibonacci_backoff/index.browser.js'
|
|
449
449
|
export * from './weak_r/index.browser.js'
|
|
450
450
|
export * from './week/index.browser.js'
|
|
451
|
+
export * from './window__ctx__set/index.browser.js'
|
|
451
452
|
export * from './wrap_a/index.browser.js'
|
|
452
453
|
export * from './wrap_a_item/index.browser.js'
|
|
453
454
|
export * from './wrap_aa/index.browser.js'
|
package/all/index.d.ts
CHANGED
|
@@ -448,6 +448,7 @@ export * from './waitfor/index.js'
|
|
|
448
448
|
export * from './waitfor_fibonacci_backoff/index.js'
|
|
449
449
|
export * from './weak_r/index.js'
|
|
450
450
|
export * from './week/index.js'
|
|
451
|
+
export * from './window__ctx__set/index.js'
|
|
451
452
|
export * from './wrap_a/index.js'
|
|
452
453
|
export * from './wrap_a_item/index.js'
|
|
453
454
|
export * from './wrap_aa/index.js'
|
package/all/index.js
CHANGED
|
@@ -448,6 +448,7 @@ export * from './waitfor/index.js'
|
|
|
448
448
|
export * from './waitfor_fibonacci_backoff/index.js'
|
|
449
449
|
export * from './weak_r/index.js'
|
|
450
450
|
export * from './week/index.js'
|
|
451
|
+
export * from './window__ctx__set/index.js'
|
|
451
452
|
export * from './wrap_a/index.js'
|
|
452
453
|
export * from './wrap_a_item/index.js'
|
|
453
454
|
export * from './wrap_aa/index.js'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './index.js'
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/// <reference types="ctx-core" />
|
|
2
|
+
import { ctx__get } from '../be_/index.js'
|
|
3
|
+
/**
|
|
4
|
+
* @param {Ctx_wide_T<''>}ctx
|
|
5
|
+
*/
|
|
6
|
+
export function window__ctx__set(ctx) {
|
|
7
|
+
window.ctx = ctx
|
|
8
|
+
/**
|
|
9
|
+
* @param {string}key
|
|
10
|
+
* @param {string}[ns]
|
|
11
|
+
* @returns {unknown}
|
|
12
|
+
*/
|
|
13
|
+
window.ctx__get = (key, ns)=>{
|
|
14
|
+
return ctx__get(window.ctx, key, ns)
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* @param {string}key
|
|
18
|
+
* @param {string}[ns]
|
|
19
|
+
* @returns {unknown}
|
|
20
|
+
*/
|
|
21
|
+
window.ctx__get_ = (key, ns)=>{
|
|
22
|
+
return ctx__get(window.ctx, key, ns)()
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { build } from 'esbuild'
|
|
2
|
+
import { JSDOM } from 'jsdom'
|
|
3
|
+
import { dirname, join } from 'node:path'
|
|
4
|
+
import { test } from 'uvu'
|
|
5
|
+
import { equal } from 'uvu/assert'
|
|
6
|
+
import { be_ } from '../be_/index.js'
|
|
7
|
+
import { ctx__new } from '../ctx/index.js'
|
|
8
|
+
import { memo_, type memo_T } from '../rmemo/index.js'
|
|
9
|
+
import { window__ctx__set as browser_window__ctx__set } from './index.browser.js'
|
|
10
|
+
import { window__ctx__set } from './index.js'
|
|
11
|
+
test('window__ctx__set|server', ()=>{
|
|
12
|
+
const ctx = ctx__new()
|
|
13
|
+
window__ctx__set(ctx)
|
|
14
|
+
})
|
|
15
|
+
test('window__ctx__set|browser', ()=>{
|
|
16
|
+
const jsdom = new JSDOM()
|
|
17
|
+
const { window } = jsdom.window
|
|
18
|
+
const prev__window = globalThis['window']
|
|
19
|
+
globalThis['window'] = window as never
|
|
20
|
+
try {
|
|
21
|
+
const ctx = ctx__new()
|
|
22
|
+
const val$ = be_(()=>
|
|
23
|
+
memo_(()=>1),
|
|
24
|
+
{ id: 'val' })
|
|
25
|
+
browser_window__ctx__set(ctx)
|
|
26
|
+
equal(val$(ctx)(), 1)
|
|
27
|
+
equal(window.ctx__get<memo_T<number>>('val'), val$(ctx))
|
|
28
|
+
equal(window.ctx__get<memo_T<number>>('val')(), 1)
|
|
29
|
+
equal(window.ctx__get_('val'), 1)
|
|
30
|
+
} finally {
|
|
31
|
+
globalThis['window'] = prev__window
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
test('browser|build', async ()=>{
|
|
35
|
+
await build({
|
|
36
|
+
entryPoints: [join(dirname(new URL(import.meta.url).pathname), 'index.browser.js')],
|
|
37
|
+
platform: 'browser',
|
|
38
|
+
bundle: true,
|
|
39
|
+
format: 'esm',
|
|
40
|
+
write: false,
|
|
41
|
+
})
|
|
42
|
+
})
|
|
43
|
+
test.run()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ctx-core",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.35.0",
|
|
4
4
|
"description": "ctx-core core library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ctx-core",
|
|
@@ -152,6 +152,10 @@
|
|
|
152
152
|
"browser": "./deep_equal/index.browser.js",
|
|
153
153
|
"default": "./deep_equal/index.js"
|
|
154
154
|
},
|
|
155
|
+
"./dom": {
|
|
156
|
+
"browser": "./dom/index.browser.js",
|
|
157
|
+
"default": "./dom/index.js"
|
|
158
|
+
},
|
|
155
159
|
"./env": {
|
|
156
160
|
"browser": "./env/index.browser.js",
|
|
157
161
|
"default": "./env/index.js"
|
|
@@ -290,12 +294,14 @@
|
|
|
290
294
|
"@arethetypeswrong/cli": "^0.13.6",
|
|
291
295
|
"@ctx-core/preprocess": "^0.1.1",
|
|
292
296
|
"@size-limit/preset-small-lib": "^11.0.2",
|
|
297
|
+
"@types/jsdom": "^21.1.6",
|
|
293
298
|
"@types/node": "^20.11.10",
|
|
294
299
|
"@types/sinon": "^17.0.3",
|
|
295
300
|
"c8": "^9.1.0",
|
|
296
301
|
"check-dts": "^0.7.2",
|
|
297
302
|
"esbuild": "^0.20.0",
|
|
298
303
|
"esmock": "^2.6.3",
|
|
304
|
+
"jsdom": "^24.0.0",
|
|
299
305
|
"sinon": "^17.0.1",
|
|
300
306
|
"size-limit": "^11.0.2",
|
|
301
307
|
"tsx": "^4.7.0",
|