@manyducks.co/dolla 0.69.5 → 0.70.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/lib/app.d.ts +8 -0
- package/lib/index.js +45 -4
- package/lib/index.js.map +3 -3
- package/lib/stores/language.d.ts +1 -0
- package/package.json +1 -1
package/lib/app.d.ts
CHANGED
|
@@ -49,6 +49,14 @@ export interface StoreRegistration<O = any> {
|
|
|
49
49
|
instance?: ReturnType<typeof initStore>;
|
|
50
50
|
}
|
|
51
51
|
interface ConfigureContext {
|
|
52
|
+
/**
|
|
53
|
+
* Returns the shared instance of `store`.
|
|
54
|
+
*/
|
|
55
|
+
getStore<T extends Store<any, any>>(store: T): ReturnType<T>;
|
|
56
|
+
/**
|
|
57
|
+
* Returns the shared instance of a built-in store.
|
|
58
|
+
*/
|
|
59
|
+
getStore<N extends keyof BuiltInStores>(name: N): BuiltInStores[N];
|
|
52
60
|
}
|
|
53
61
|
type ConfigureCallback = (ctx: ConfigureContext) => void | Promise<void>;
|
|
54
62
|
export interface IApp {
|
package/lib/index.js
CHANGED
|
@@ -2345,6 +2345,37 @@ function App(options) {
|
|
|
2345
2345
|
if (configureCallback) {
|
|
2346
2346
|
await configureCallback({
|
|
2347
2347
|
// TODO: Add context methods
|
|
2348
|
+
getStore(store) {
|
|
2349
|
+
let name;
|
|
2350
|
+
if (typeof store === "string") {
|
|
2351
|
+
name = store;
|
|
2352
|
+
} else {
|
|
2353
|
+
name = store.name;
|
|
2354
|
+
}
|
|
2355
|
+
if (typeof store !== "string") {
|
|
2356
|
+
let ec = elementContext;
|
|
2357
|
+
while (ec) {
|
|
2358
|
+
if (ec.stores.has(store)) {
|
|
2359
|
+
return ec.stores.get(store)?.instance.exports;
|
|
2360
|
+
}
|
|
2361
|
+
ec = ec.parent;
|
|
2362
|
+
}
|
|
2363
|
+
}
|
|
2364
|
+
if (appContext.stores.has(store)) {
|
|
2365
|
+
const _store = appContext.stores.get(store);
|
|
2366
|
+
if (!_store.instance) {
|
|
2367
|
+
appContext.crashCollector.crash({
|
|
2368
|
+
componentName: "@manyducks.co/dolla/App",
|
|
2369
|
+
error: new Error(`Store '${name}' is not registered on this app.`)
|
|
2370
|
+
});
|
|
2371
|
+
}
|
|
2372
|
+
return _store.instance.exports;
|
|
2373
|
+
}
|
|
2374
|
+
appContext.crashCollector.crash({
|
|
2375
|
+
componentName: "@manyducks.co/dolla/App",
|
|
2376
|
+
error: new Error(`Store '${name}' is not registered on this app.`)
|
|
2377
|
+
});
|
|
2378
|
+
}
|
|
2348
2379
|
});
|
|
2349
2380
|
}
|
|
2350
2381
|
appContext.rootView.connect(appContext.rootElement);
|
|
@@ -3470,15 +3501,15 @@ function LanguageStore(ctx) {
|
|
|
3470
3501
|
realTag = firstLanguage.name;
|
|
3471
3502
|
}
|
|
3472
3503
|
}
|
|
3473
|
-
if (!realTag || !languages.has(
|
|
3504
|
+
if (!realTag || !languages.has(realTag)) {
|
|
3474
3505
|
throw new Error(`Language '${tag}' is not configured for this app.`);
|
|
3475
3506
|
}
|
|
3476
|
-
const lang = languages.get(
|
|
3507
|
+
const lang = languages.get(realTag);
|
|
3477
3508
|
try {
|
|
3478
3509
|
const translation = await getTranslation(lang);
|
|
3479
3510
|
$$translation.set(translation);
|
|
3480
|
-
$$language.set(
|
|
3481
|
-
ctx.info("set language to " +
|
|
3511
|
+
$$language.set(realTag);
|
|
3512
|
+
ctx.info("set language to " + realTag);
|
|
3482
3513
|
} catch (error) {
|
|
3483
3514
|
if (error instanceof Error) {
|
|
3484
3515
|
ctx.crash(error);
|
|
@@ -3489,6 +3520,16 @@ function LanguageStore(ctx) {
|
|
|
3489
3520
|
$$isLoaded.set(true);
|
|
3490
3521
|
});
|
|
3491
3522
|
return {
|
|
3523
|
+
loaded: new Promise((resolve2, reject) => {
|
|
3524
|
+
const stop = observe($$isLoaded, (isLoaded) => {
|
|
3525
|
+
if (isLoaded) {
|
|
3526
|
+
setTimeout(() => {
|
|
3527
|
+
stop();
|
|
3528
|
+
resolve2();
|
|
3529
|
+
}, 0);
|
|
3530
|
+
}
|
|
3531
|
+
});
|
|
3532
|
+
}),
|
|
3492
3533
|
$isLoaded: $($$isLoaded),
|
|
3493
3534
|
$currentLanguage: $($$language),
|
|
3494
3535
|
supportedLanguages: [...languages.keys()],
|