@aerogel/core 0.0.0-next.ea2e864c719d0a4d01b04729a9b681c0e9c85ea7 → 0.0.0-next.eb6fcafb87cdccbc72933f616799ca3124d1eca8

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.
@@ -12,6 +12,7 @@ import type { Constructor, Nullable } from '@noeldemartin/utils';
12
12
  import type { Store } from 'pinia';
13
13
 
14
14
  import ServiceBootError from '@aerogel/core/errors/ServiceBootError';
15
+ import { appNamespace } from '@aerogel/core/utils/app';
15
16
  import { defineServiceStore } from '@aerogel/core/services/store';
16
17
  import type { Unref } from '@aerogel/core/utils/vue';
17
18
 
@@ -164,7 +165,7 @@ export default class Service<
164
165
  }
165
166
 
166
167
  public hasPersistedState(): boolean {
167
- return Storage.has(this._name);
168
+ return Storage.has(this.storageKey);
168
169
  }
169
170
 
170
171
  public hasState<P extends keyof State>(property: P): boolean {
@@ -231,6 +232,10 @@ export default class Service<
231
232
  this.setState({ [property]: value } as Partial<State>);
232
233
  }
233
234
 
235
+ protected get storageKey(): string {
236
+ return `${appNamespace()}:${this._name}`;
237
+ }
238
+
234
239
  protected onStateUpdated(update: Partial<State>, old: Partial<State>): void {
235
240
  const persisted = objectOnly(update, this.static('persist'));
236
241
 
@@ -250,13 +255,13 @@ export default class Service<
250
255
  }
251
256
 
252
257
  protected onPersistentStateUpdated(persisted: Partial<State>): void {
253
- const storage = Storage.get<ServiceStorage>(this._name);
258
+ const storage = Storage.get<ServiceStorage>(this.storageKey);
254
259
 
255
260
  if (!storage) {
256
261
  return;
257
262
  }
258
263
 
259
- Storage.set(this._name, {
264
+ Storage.set(this.storageKey, {
260
265
  ...storage,
261
266
  ...this.serializePersistedState(objectDeepClone(persisted) as Partial<State>),
262
267
  });
@@ -303,14 +308,14 @@ export default class Service<
303
308
  return;
304
309
  }
305
310
 
306
- if (Storage.has(this._name)) {
307
- const persisted = Storage.require<ServiceStorage>(this._name);
311
+ if (Storage.has(this.storageKey)) {
312
+ const persisted = Storage.require<ServiceStorage>(this.storageKey);
308
313
  this.setState(this.deserializePersistedState(persisted));
309
314
 
310
315
  return;
311
316
  }
312
317
 
313
- Storage.set(this._name, objectOnly(this.getState(), this.static('persist')));
318
+ Storage.set(this.storageKey, objectOnly(this.getState(), this.static('persist')));
314
319
  }
315
320
 
316
321
  protected requireStore(): Store<string, State, ComputedState, {}> {
@@ -2,10 +2,13 @@ import { isTesting } from '@noeldemartin/utils';
2
2
  import type { GetClosureArgs } from '@noeldemartin/utils';
3
3
 
4
4
  import Events from '@aerogel/core/services/Events';
5
+ import { App } from '@aerogel/core/services';
5
6
  import { definePlugin } from '@aerogel/core/plugins';
7
+ import type { Services } from '@aerogel/core/services';
6
8
 
7
9
  export interface AerogelTestingRuntime {
8
10
  on: (typeof Events)['on'];
11
+ service<T extends keyof Services>(name: T): Services[T] | null;
9
12
  }
10
13
 
11
14
  export default definePlugin({
@@ -16,6 +19,7 @@ export default definePlugin({
16
19
 
17
20
  globalThis.testingRuntime = {
18
21
  on: ((...args: GetClosureArgs<(typeof Events)['on']>) => Events.on(...args)) as (typeof Events)['on'],
22
+ service: (name) => App.service(name),
19
23
  };
20
24
  },
21
25
  });
package/src/ui/UI.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { after, facade, fail, isDevelopment, required, uuid } from '@noeldemartin/utils';
2
- import { markRaw, nextTick } from 'vue';
2
+ import { markRaw, nextTick, unref } from 'vue';
3
3
  import type { ComponentExposed, ComponentProps } from 'vue-component-type-helpers';
4
4
  import type { Component } from 'vue';
5
5
  import type { ClosureArgs } from '@noeldemartin/utils';
@@ -64,6 +64,7 @@ export type LoadingOptions = AcceptRefs<{
64
64
  title?: string;
65
65
  message?: string;
66
66
  progress?: number;
67
+ delay?: number;
67
68
  }>;
68
69
 
69
70
  export interface ConfirmOptionsWithCheckboxes<T extends ConfirmModalCheckboxes = ConfirmModalCheckboxes>
@@ -218,7 +219,11 @@ export class UIService extends Service {
218
219
  operation?: Promise<T> | (() => T),
219
220
  ): Promise<T> {
220
221
  const processOperation = (o: Promise<T> | (() => T)) => (typeof o === 'function' ? Promise.resolve(o()) : o);
221
- const processArgs = (): { operationPromise: Promise<T>; props?: AcceptRefs<LoadingModalProps> } => {
222
+ const processArgs = (): {
223
+ operationPromise: Promise<T>;
224
+ props?: AcceptRefs<LoadingModalProps>;
225
+ delay?: number;
226
+ } => {
222
227
  if (typeof operationOrMessageOrOptions === 'string') {
223
228
  return {
224
229
  props: { message: operationOrMessageOrOptions },
@@ -230,13 +235,24 @@ export class UIService extends Service {
230
235
  return { operationPromise: processOperation(operationOrMessageOrOptions) };
231
236
  }
232
237
 
238
+ const { delay, ...props } = operationOrMessageOrOptions;
239
+
233
240
  return {
234
- props: operationOrMessageOrOptions,
241
+ props,
242
+ delay: unref(delay),
235
243
  operationPromise: processOperation(operation as Promise<T> | (() => T)),
236
244
  };
237
245
  };
238
246
 
239
- const { operationPromise, props } = processArgs();
247
+ let delayed = false;
248
+ const { operationPromise, props, delay } = processArgs();
249
+
250
+ delay && (await Promise.race([after({ ms: delay }).then(() => (delayed = true)), operationPromise]));
251
+
252
+ if (delay && !delayed) {
253
+ return operationPromise;
254
+ }
255
+
240
256
  const modal = await this.modal(this.requireComponent('loading-modal'), props);
241
257
 
242
258
  try {
@@ -0,0 +1,7 @@
1
+ import Aerogel from 'virtual:aerogel';
2
+
3
+ import { stringToSlug } from '@noeldemartin/utils';
4
+
5
+ export function appNamespace(): string {
6
+ return Aerogel.namespace ?? stringToSlug(Aerogel.name);
7
+ }
@@ -1,3 +1,4 @@
1
+ export * from './app';
1
2
  export * from './classes';
2
3
  export * from './composition/events';
3
4
  export * from './composition/forms';