@daffodil/core 0.68.1 → 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/constructable/constructable.d.ts +1 -1
- package/esm2022/constructable/constructable.mjs +1 -1
- package/esm2022/external-script/daffodil-core-external-script.mjs +5 -0
- package/esm2022/external-script/external-script.service.mjs +90 -0
- package/esm2022/external-script/index.mjs +2 -0
- package/esm2022/external-script/interface.mjs +2 -0
- package/esm2022/external-script/public_api.mjs +2 -0
- package/esm2022/external-script/script.mjs +2 -0
- package/esm2022/external-script/testing/constants.mjs +2 -0
- package/esm2022/external-script/testing/daffodil-core-external-script-testing.mjs +5 -0
- package/esm2022/external-script/testing/external-script.service.mjs +53 -0
- package/esm2022/external-script/testing/index.mjs +2 -0
- package/esm2022/external-script/testing/public_api.mjs +2 -0
- package/esm2022/state/actions/failure.type.mjs +1 -1
- package/esm2022/state/actions/public_api.mjs +1 -1
- package/esm2022/state/operation/adapter.mjs +3 -3
- package/esm2022/state/operation/entity/adapter.mjs +69 -36
- package/esm2022/state/operation/entity/helpers/create-fake-id.mjs +10 -0
- package/esm2022/state/operation/entity/public_api.mjs +2 -2
- package/esm2022/state/operation/entity/selectors.mjs +2 -1
- package/esm2022/state/operation/selectors.mjs +4 -3
- package/esm2022/state/states/helpers.mjs +15 -0
- package/esm2022/state/states/public_api.mjs +2 -2
- package/esm2022/state/states/state.enum.mjs +1 -1
- package/esm2022/utils/identity.mjs +8 -0
- package/esm2022/utils/public_api.mjs +2 -1
- package/external-script/external-script.service.d.ts +50 -0
- package/external-script/index.d.ts +1 -0
- package/external-script/interface.d.ts +11 -0
- package/external-script/public_api.d.ts +3 -0
- package/external-script/script.d.ts +33 -0
- package/external-script/testing/constants.d.ts +4 -0
- package/external-script/testing/external-script.service.d.ts +40 -0
- package/external-script/testing/index.d.ts +1 -0
- package/external-script/testing/public_api.d.ts +2 -0
- package/fesm2022/daffodil-core-external-script-testing.mjs +60 -0
- package/fesm2022/daffodil-core-external-script-testing.mjs.map +1 -0
- package/fesm2022/daffodil-core-external-script.mjs +97 -0
- package/fesm2022/daffodil-core-external-script.mjs.map +1 -0
- package/fesm2022/daffodil-core-state.mjs +89 -49
- package/fesm2022/daffodil-core-state.mjs.map +1 -1
- package/fesm2022/daffodil-core.mjs +9 -1
- package/fesm2022/daffodil-core.mjs.map +1 -1
- package/package.json +1 -1
- package/state/actions/failure.type.d.ts +6 -4
- package/state/operation/entity/adapter.d.ts +21 -1
- package/state/operation/entity/{helpers.d.ts → helpers/create-fake-id.d.ts} +0 -5
- package/state/operation/entity/public_api.d.ts +1 -1
- package/state/operation/entity/selectors.d.ts +1 -1
- package/state/states/helpers.d.ts +9 -0
- package/state/states/public_api.d.ts +1 -0
- package/state/states/state.enum.d.ts +16 -4
- package/utils/identity.d.ts +5 -0
- package/utils/public_api.d.ts +1 -0
- package/esm2022/state/operation/entity/helpers.mjs +0 -19
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export {};
|
|
2
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
2
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3RhdGUuZW51bS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uL2xpYnMvY29yZS9zdGF0ZS9zcmMvc3RhdGVzL3N0YXRlLmVudW0udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiIsInNvdXJjZXNDb250ZW50IjpbIi8qKlxuICogVGhlIERhZmZTdGF0ZSBlbnVtZXJhdGVzIHRoZSB2YXN0IG1ham9yaXR5IG9mIHN0YXRlIG1vZGlmaWNhdGlvbnMgdGhhdCBjYW4gZXhpc3RcbiAqIGluIFVJIGFwcGxpY2F0aW9ucy5cbiAqL1xuZXhwb3J0IGNvbnN0IGVudW0gRGFmZlN0YXRlIHtcbiAgLyoqXG4gICAqIFRoZSAnU3RhYmxlJyBzdGF0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QW4gYWxpYXMgZm9yICdTdGFibGUnLlxuICAgKlxuICAgKiBAZGVwcmVjYXRlZFxuICAgKiBVc2UgRGFmZlN0YXRlLlN0YWJsZSBpbnN0ZWFkLlxuICAgKi9cbiAgLy8gZXNsaW50LWRpc2FibGUtbmV4dC1saW5lIEB0eXBlc2NyaXB0LWVzbGludC9uby1kdXBsaWNhdGUtZW51bS12YWx1ZXNcbiAgQ29tcGxldGUgPSAnU3RhYmxlJyxcblxuICAvKipcbiAgICogSW5kaWNhdGVzIHRoYXQgdGhlIG1vc3QgcmVjZW50IG9wZXJhdGlvbiBzcGVjaWZpZmMgdG8gdGhpcyBlbnRpdHkgaGFzIGZhaWxlZC5cbiAgICovXG4gIEVycm9yID0gJ0Vycm9yJ1xufVxuIl19
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The unary identity function.
|
|
3
|
+
* Returns whatever is passed to it.
|
|
4
|
+
*/
|
|
5
|
+
export function identity(v) {
|
|
6
|
+
return v;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaWRlbnRpdHkuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9saWJzL2NvcmUvc3JjL3V0aWxzL2lkZW50aXR5LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7R0FHRztBQUNILE1BQU0sVUFBVSxRQUFRLENBQUksQ0FBSTtJQUM5QixPQUFPLENBQUMsQ0FBQztBQUNYLENBQUMiLCJzb3VyY2VzQ29udGVudCI6WyIvKipcbiAqIFRoZSB1bmFyeSBpZGVudGl0eSBmdW5jdGlvbi5cbiAqIFJldHVybnMgd2hhdGV2ZXIgaXMgcGFzc2VkIHRvIGl0LlxuICovXG5leHBvcnQgZnVuY3Rpb24gaWRlbnRpdHk8VD4odjogVCk6IFQge1xuICByZXR1cm4gdjtcbn1cbiJdfQ==
|
|
@@ -12,4 +12,5 @@ export { shallowCompare } from './shallow-compare';
|
|
|
12
12
|
export { shuffle } from './shuffle';
|
|
13
13
|
export { unique } from './unique';
|
|
14
14
|
export * from './long-arithmetic';
|
|
15
|
-
|
|
15
|
+
export * from './identity';
|
|
16
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHVibGljX2FwaS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL2xpYnMvY29yZS9zcmMvdXRpbHMvcHVibGljX2FwaS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsT0FBTyxFQUFFLE1BQU0sV0FBVyxDQUFDO0FBQ3BDLE9BQU8sRUFBRSxPQUFPLEVBQUUsTUFBTSxtQkFBbUIsQ0FBQztBQUM1QyxPQUFPLEVBQUUsZUFBZSxFQUFFLE1BQU0saUJBQWlCLENBQUM7QUFDbEQsT0FBTyxFQUFFLFVBQVUsRUFBRSxNQUFNLG1CQUFtQixDQUFDO0FBQy9DLE9BQU8sRUFBRSxZQUFZLEVBQUUsTUFBTSxtQkFBbUIsQ0FBQztBQUNqRCxPQUFPLEVBQUUsWUFBWSxFQUFFLE1BQU0sbUJBQW1CLENBQUM7QUFDakQsT0FBTyxFQUFFLFdBQVcsRUFBRSxNQUFNLGdCQUFnQixDQUFDO0FBQzdDLE9BQU8sRUFBRSxZQUFZLEVBQUUsTUFBTSxpQkFBaUIsQ0FBQztBQUMvQyxPQUFPLEVBQUUsS0FBSyxFQUFFLE1BQU0sU0FBUyxDQUFDO0FBQ2hDLE9BQU8sRUFBRSxNQUFNLEVBQUUsTUFBTSxVQUFVLENBQUM7QUFDbEMsT0FBTyxFQUFFLGNBQWMsRUFBRSxNQUFNLG1CQUFtQixDQUFDO0FBQ25ELE9BQU8sRUFBRSxPQUFPLEVBQUUsTUFBTSxXQUFXLENBQUM7QUFDcEMsT0FBTyxFQUFFLE1BQU0sRUFBRSxNQUFNLFVBQVUsQ0FBQztBQUNsQyxjQUFjLG1CQUFtQixDQUFDO0FBQ2xDLGNBQWMsWUFBWSxDQUFDIiwic291cmNlc0NvbnRlbnQiOlsiZXhwb3J0IHsgY29sbGVjdCB9IGZyb20gJy4vY29sbGVjdCc7XG5leHBvcnQgeyBkYWZmQWRkIH0gZnJvbSAnLi9sb25nLWFyaXRobWV0aWMnO1xuZXhwb3J0IHsgZGFmZkFycmF5VG9EaWN0IH0gZnJvbSAnLi9hcnJheS10by1kaWN0JztcbmV4cG9ydCB7IGRhZmZEaXZpZGUgfSBmcm9tICcuL2xvbmctYXJpdGhtZXRpYyc7XG5leHBvcnQgeyBkYWZmTXVsdGlwbHkgfSBmcm9tICcuL2xvbmctYXJpdGhtZXRpYyc7XG5leHBvcnQgeyBkYWZmU3VidHJhY3QgfSBmcm9tICcuL2xvbmctYXJpdGhtZXRpYyc7XG5leHBvcnQgeyByYW5kb21TbGljZSB9IGZyb20gJy4vcmFuZG9tLXNsaWNlJztcbmV4cG9ydCB7IHJhbmRvbVN1YnNldCB9IGZyb20gJy4vcmFuZG9tLXN1YnNldCc7XG5leHBvcnQgeyByYW5nZSB9IGZyb20gJy4vcmFuZ2UnO1xuZXhwb3J0IHsgc2FtcGxlIH0gZnJvbSAnLi9zYW1wbGUnO1xuZXhwb3J0IHsgc2hhbGxvd0NvbXBhcmUgfSBmcm9tICcuL3NoYWxsb3ctY29tcGFyZSc7XG5leHBvcnQgeyBzaHVmZmxlIH0gZnJvbSAnLi9zaHVmZmxlJztcbmV4cG9ydCB7IHVuaXF1ZSB9IGZyb20gJy4vdW5pcXVlJztcbmV4cG9ydCAqIGZyb20gJy4vbG9uZy1hcml0aG1ldGljJztcbmV4cG9ydCAqIGZyb20gJy4vaWRlbnRpdHknO1xuIl19
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { DaffExternalScriptServiceInterface } from './interface';
|
|
3
|
+
import { DaffExternalScript } from './script';
|
|
4
|
+
import * as i0 from "@angular/core";
|
|
5
|
+
export interface LoadedExternalScript extends DaffExternalScript {
|
|
6
|
+
ready: boolean | undefined;
|
|
7
|
+
subject: Observable<boolean>;
|
|
8
|
+
el: HTMLElement | undefined;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* A service for loading external scripts into the document.
|
|
12
|
+
*
|
|
13
|
+
* ### Usage example
|
|
14
|
+
*
|
|
15
|
+
* The following loads an external script into the document.
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { DOCUMENT } from '@angular/common';
|
|
19
|
+
* import { inject } from '@angular/core';
|
|
20
|
+
*
|
|
21
|
+
* import { DaffExternalScriptService } from '@daffodil/core/external-script';
|
|
22
|
+
*
|
|
23
|
+
* const externalScriptService = new DaffExternalScriptService(inject(DOCUMENT));
|
|
24
|
+
*
|
|
25
|
+
* externalScriptService.load('exampleScript', {
|
|
26
|
+
* src: 'https://example.com/script.js',
|
|
27
|
+
* async: true,
|
|
28
|
+
* defer: false,
|
|
29
|
+
* 'data-custom-attribute': 'value',
|
|
30
|
+
* }).subscribe({
|
|
31
|
+
* next: (result) => {
|
|
32
|
+
* console.log('Script loaded successfully:', result);
|
|
33
|
+
* },
|
|
34
|
+
* error: (error) => {
|
|
35
|
+
* console.error('Error loading script:', error);
|
|
36
|
+
* },
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export declare class DaffExternalScriptService implements DaffExternalScriptServiceInterface {
|
|
41
|
+
readonly scriptMap: Map<string, LoadedExternalScript>;
|
|
42
|
+
private doc;
|
|
43
|
+
constructor(doc: any);
|
|
44
|
+
/**
|
|
45
|
+
* @inheritdoc
|
|
46
|
+
*/
|
|
47
|
+
load(name: string, script: DaffExternalScript): Observable<boolean>;
|
|
48
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<DaffExternalScriptService, never>;
|
|
49
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<DaffExternalScriptService>;
|
|
50
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './public_api';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { DaffExternalScript } from './script';
|
|
3
|
+
export interface DaffExternalScriptServiceInterface {
|
|
4
|
+
/**
|
|
5
|
+
* Load a script into the document.
|
|
6
|
+
* @param name The name of the script.
|
|
7
|
+
* @param script The script object containing details like src, async, defer, and custom attributes.
|
|
8
|
+
* @returns An Observable that emits true when the script is loaded successfully, or emits an error if loading fails.
|
|
9
|
+
*/
|
|
10
|
+
load(name: string, script: DaffExternalScript): Observable<boolean>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents the structure of an external script that can be loaded into a document.
|
|
3
|
+
*
|
|
4
|
+
* ```ts
|
|
5
|
+
* // Example of using DaffExternalScript interface to define an external script object.
|
|
6
|
+
*
|
|
7
|
+
* const externalScript: DaffExternalScript = {
|
|
8
|
+
* src: 'https://example.com/script.js',
|
|
9
|
+
* async: true,
|
|
10
|
+
* defer: false,
|
|
11
|
+
* 'data-custom-attribute': 'value',
|
|
12
|
+
* };
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export interface DaffExternalScript {
|
|
16
|
+
/** The source URL of the script. */
|
|
17
|
+
src: string;
|
|
18
|
+
/**
|
|
19
|
+
* Optional. Indicates whether the script should be loaded asynchronously.
|
|
20
|
+
* @default false
|
|
21
|
+
*/
|
|
22
|
+
async?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Optional. Indicates whether the script should be deferred in loading.
|
|
25
|
+
* @default false
|
|
26
|
+
*/
|
|
27
|
+
defer?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Optional. Custom attributes for the script.
|
|
30
|
+
* The keys must start with 'data-' followed by any string.
|
|
31
|
+
*/
|
|
32
|
+
[key: `data-${string}`]: string;
|
|
33
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { DaffExternalScriptServiceInterface } from '@daffodil/core/external-script';
|
|
3
|
+
import { DaffExternalScript } from '@daffodil/core/external-script';
|
|
4
|
+
import * as i0 from "@angular/core";
|
|
5
|
+
/**
|
|
6
|
+
* A service for loading external scripts into the document.
|
|
7
|
+
*
|
|
8
|
+
* ### Usage example
|
|
9
|
+
*
|
|
10
|
+
* The following loads an external script into the document.
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
*
|
|
14
|
+
* import { DaffExternalScriptTestingService } from '@daffodil/core/external-script/testing';
|
|
15
|
+
*
|
|
16
|
+
* const externalScriptService = new DaffExternalScriptTestingService();
|
|
17
|
+
*
|
|
18
|
+
* externalScriptService.load(TestScripts.SUCCESS, {
|
|
19
|
+
* src: 'https://example.com/script.js',
|
|
20
|
+
* async: true,
|
|
21
|
+
* defer: false,
|
|
22
|
+
* 'data-custom-attribute': 'value',
|
|
23
|
+
* }).subscribe({
|
|
24
|
+
* next: (result) => {
|
|
25
|
+
* console.log('Script loaded successfully:', result);
|
|
26
|
+
* },
|
|
27
|
+
* error: (error) => {
|
|
28
|
+
* console.error('Error loading script:', error);
|
|
29
|
+
* },
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare class DaffExternalScriptTestingService implements DaffExternalScriptServiceInterface {
|
|
34
|
+
/**
|
|
35
|
+
* @inheritdoc
|
|
36
|
+
*/
|
|
37
|
+
load(name: string, script: DaffExternalScript): Observable<boolean>;
|
|
38
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<DaffExternalScriptTestingService, never>;
|
|
39
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<DaffExternalScriptTestingService>;
|
|
40
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './public_api';
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { Injectable } from '@angular/core';
|
|
3
|
+
import { throwError, of } from 'rxjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A service for loading external scripts into the document.
|
|
7
|
+
*
|
|
8
|
+
* ### Usage example
|
|
9
|
+
*
|
|
10
|
+
* The following loads an external script into the document.
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
*
|
|
14
|
+
* import { DaffExternalScriptTestingService } from '@daffodil/core/external-script/testing';
|
|
15
|
+
*
|
|
16
|
+
* const externalScriptService = new DaffExternalScriptTestingService();
|
|
17
|
+
*
|
|
18
|
+
* externalScriptService.load(TestScripts.SUCCESS, {
|
|
19
|
+
* src: 'https://example.com/script.js',
|
|
20
|
+
* async: true,
|
|
21
|
+
* defer: false,
|
|
22
|
+
* 'data-custom-attribute': 'value',
|
|
23
|
+
* }).subscribe({
|
|
24
|
+
* next: (result) => {
|
|
25
|
+
* console.log('Script loaded successfully:', result);
|
|
26
|
+
* },
|
|
27
|
+
* error: (error) => {
|
|
28
|
+
* console.error('Error loading script:', error);
|
|
29
|
+
* },
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
class DaffExternalScriptTestingService {
|
|
34
|
+
/**
|
|
35
|
+
* @inheritdoc
|
|
36
|
+
*/
|
|
37
|
+
load(name, script) {
|
|
38
|
+
switch (name) {
|
|
39
|
+
case "0" /* TestScripts.SUCCESS */:
|
|
40
|
+
return of(true);
|
|
41
|
+
default:
|
|
42
|
+
return throwError(() => new Error(`Failed to load ${script.src}`));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.1.1", ngImport: i0, type: DaffExternalScriptTestingService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
46
|
+
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.1.1", ngImport: i0, type: DaffExternalScriptTestingService, providedIn: 'root' }); }
|
|
47
|
+
}
|
|
48
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.1.1", ngImport: i0, type: DaffExternalScriptTestingService, decorators: [{
|
|
49
|
+
type: Injectable,
|
|
50
|
+
args: [{
|
|
51
|
+
providedIn: 'root',
|
|
52
|
+
}]
|
|
53
|
+
}] });
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Generated bundle index. Do not edit.
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
export { DaffExternalScriptTestingService };
|
|
60
|
+
//# sourceMappingURL=daffodil-core-external-script-testing.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"daffodil-core-external-script-testing.mjs","sources":["../../../libs/core/external-script/testing/src/external-script.service.ts","../../../libs/core/external-script/testing/src/daffodil-core-external-script-testing.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\nimport {\n Observable,\n of,\n throwError,\n} from 'rxjs';\n\nimport { DaffExternalScriptServiceInterface } from '@daffodil/core/external-script';\nimport { DaffExternalScript } from '@daffodil/core/external-script';\n\nimport { TestScripts } from './constants';\n\n/**\n * A service for loading external scripts into the document.\n *\n * ### Usage example\n *\n * The following loads an external script into the document.\n *\n * ```ts\n *\n * import { DaffExternalScriptTestingService } from '@daffodil/core/external-script/testing';\n *\n * const externalScriptService = new DaffExternalScriptTestingService();\n *\n * externalScriptService.load(TestScripts.SUCCESS, {\n * src: 'https://example.com/script.js',\n * async: true,\n * defer: false,\n * 'data-custom-attribute': 'value',\n * }).subscribe({\n * next: (result) => {\n * console.log('Script loaded successfully:', result);\n * },\n * error: (error) => {\n * console.error('Error loading script:', error);\n * },\n * });\n * ```\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class DaffExternalScriptTestingService implements DaffExternalScriptServiceInterface {\n\n /**\n * @inheritdoc\n */\n load(name: string, script: DaffExternalScript): Observable<boolean> {\n switch(name) {\n case TestScripts.SUCCESS:\n return of(true);\n default:\n return throwError(() => new Error(`Failed to load ${ script.src }`));\n }\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;AAYA;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BG;MAIU,gCAAgC,CAAA;AAE3C;;AAEG;IACH,IAAI,CAAC,IAAY,EAAE,MAA0B,EAAA;AAC3C,QAAA,QAAO,IAAI;AACT,YAAA,KAAA,GAAA;AACE,gBAAA,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC;AAClB,YAAA;AACE,gBAAA,OAAO,UAAU,CAAC,MAAM,IAAI,KAAK,CAAC,CAAA,eAAA,EAAmB,MAAM,CAAC,GAAI,CAAE,CAAA,CAAC,CAAC,CAAC;AACxE,SAAA;KACF;iIAZU,gCAAgC,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA,CAAA,EAAA;AAAhC,uBAAA,SAAA,IAAA,CAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,gCAAgC,cAF/B,MAAM,EAAA,CAAA,CAAA,EAAA;;2FAEP,gCAAgC,EAAA,UAAA,EAAA,CAAA;kBAH5C,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACV,oBAAA,UAAU,EAAE,MAAM;AACnB,iBAAA,CAAA;;;AC1CD;;AAEG;;;;"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { DOCUMENT } from '@angular/common';
|
|
2
|
+
import * as i0 from '@angular/core';
|
|
3
|
+
import { Injectable, Inject } from '@angular/core';
|
|
4
|
+
import { BehaviorSubject } from 'rxjs';
|
|
5
|
+
import { filter } from 'rxjs/operators';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A service for loading external scripts into the document.
|
|
9
|
+
*
|
|
10
|
+
* ### Usage example
|
|
11
|
+
*
|
|
12
|
+
* The following loads an external script into the document.
|
|
13
|
+
*
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { DOCUMENT } from '@angular/common';
|
|
16
|
+
* import { inject } from '@angular/core';
|
|
17
|
+
*
|
|
18
|
+
* import { DaffExternalScriptService } from '@daffodil/core/external-script';
|
|
19
|
+
*
|
|
20
|
+
* const externalScriptService = new DaffExternalScriptService(inject(DOCUMENT));
|
|
21
|
+
*
|
|
22
|
+
* externalScriptService.load('exampleScript', {
|
|
23
|
+
* src: 'https://example.com/script.js',
|
|
24
|
+
* async: true,
|
|
25
|
+
* defer: false,
|
|
26
|
+
* 'data-custom-attribute': 'value',
|
|
27
|
+
* }).subscribe({
|
|
28
|
+
* next: (result) => {
|
|
29
|
+
* console.log('Script loaded successfully:', result);
|
|
30
|
+
* },
|
|
31
|
+
* error: (error) => {
|
|
32
|
+
* console.error('Error loading script:', error);
|
|
33
|
+
* },
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
class DaffExternalScriptService {
|
|
38
|
+
constructor(doc) {
|
|
39
|
+
this.scriptMap = new Map();
|
|
40
|
+
this.doc = doc;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* @inheritdoc
|
|
44
|
+
*/
|
|
45
|
+
load(name, script) {
|
|
46
|
+
// Don't load the same script twice.
|
|
47
|
+
if (this.scriptMap.has(name)) {
|
|
48
|
+
return this.scriptMap.get(name).subject;
|
|
49
|
+
}
|
|
50
|
+
const scriptEl = this.doc.createElement('script');
|
|
51
|
+
scriptEl.setAttribute('type', 'text/javascript');
|
|
52
|
+
scriptEl.setAttribute('src', script.src);
|
|
53
|
+
scriptEl.setAttribute('charset', 'utf-8');
|
|
54
|
+
// Set custom attributes prefixed with 'data-'.
|
|
55
|
+
Object.keys(script).filter(key => key.startsWith('data-')).map((key) => {
|
|
56
|
+
// setAttribute would lowercase the value of "key", which isn't always correct.
|
|
57
|
+
// setAttributeNS maintains key casing.
|
|
58
|
+
scriptEl.setAttributeNS(null, key, script[key]);
|
|
59
|
+
});
|
|
60
|
+
if (script.async) {
|
|
61
|
+
scriptEl.async = true;
|
|
62
|
+
}
|
|
63
|
+
if (script.defer) {
|
|
64
|
+
scriptEl.defer = true;
|
|
65
|
+
}
|
|
66
|
+
const readySubject = new BehaviorSubject(undefined);
|
|
67
|
+
scriptEl.onload = () => {
|
|
68
|
+
this.scriptMap.get(name).ready = true;
|
|
69
|
+
readySubject.next(true);
|
|
70
|
+
};
|
|
71
|
+
scriptEl.onerror = () => {
|
|
72
|
+
this.scriptMap.get(name).ready = false;
|
|
73
|
+
readySubject.error(new Error(`Failed to load ${script.src}`));
|
|
74
|
+
};
|
|
75
|
+
this.doc.body.appendChild(scriptEl);
|
|
76
|
+
this.scriptMap.set(name, { ...script, ready: undefined, subject: readySubject, el: scriptEl });
|
|
77
|
+
return readySubject.pipe(filter((s) => s !== undefined));
|
|
78
|
+
}
|
|
79
|
+
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.1.1", ngImport: i0, type: DaffExternalScriptService, deps: [{ token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
80
|
+
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.1.1", ngImport: i0, type: DaffExternalScriptService, providedIn: 'root' }); }
|
|
81
|
+
}
|
|
82
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.1.1", ngImport: i0, type: DaffExternalScriptService, decorators: [{
|
|
83
|
+
type: Injectable,
|
|
84
|
+
args: [{
|
|
85
|
+
providedIn: 'root',
|
|
86
|
+
}]
|
|
87
|
+
}], ctorParameters: () => [{ type: undefined, decorators: [{
|
|
88
|
+
type: Inject,
|
|
89
|
+
args: [DOCUMENT]
|
|
90
|
+
}] }] });
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Generated bundle index. Do not edit.
|
|
94
|
+
*/
|
|
95
|
+
|
|
96
|
+
export { DaffExternalScriptService };
|
|
97
|
+
//# sourceMappingURL=daffodil-core-external-script.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"daffodil-core-external-script.mjs","sources":["../../../libs/core/external-script/src/external-script.service.ts","../../../libs/core/external-script/src/daffodil-core-external-script.ts"],"sourcesContent":["import { DOCUMENT } from '@angular/common';\nimport {\n Inject,\n Injectable,\n} from '@angular/core';\nimport {\n BehaviorSubject,\n Observable,\n Subject,\n} from 'rxjs';\nimport { filter } from 'rxjs/operators';\n\nimport { DaffExternalScriptServiceInterface } from './interface';\nimport { DaffExternalScript } from './script';\n\nexport interface LoadedExternalScript extends DaffExternalScript {\n ready: boolean | undefined;\n subject: Observable<boolean>;\n el: HTMLElement | undefined;\n}\n\n/**\n * A service for loading external scripts into the document.\n *\n * ### Usage example\n *\n * The following loads an external script into the document.\n *\n * ```ts\n * import { DOCUMENT } from '@angular/common';\n * import { inject } from '@angular/core';\n *\n * import { DaffExternalScriptService } from '@daffodil/core/external-script';\n *\n * const externalScriptService = new DaffExternalScriptService(inject(DOCUMENT));\n *\n * externalScriptService.load('exampleScript', {\n * src: 'https://example.com/script.js',\n * async: true,\n * defer: false,\n * 'data-custom-attribute': 'value',\n * }).subscribe({\n * next: (result) => {\n * console.log('Script loaded successfully:', result);\n * },\n * error: (error) => {\n * console.error('Error loading script:', error);\n * },\n * });\n * ```\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class DaffExternalScriptService implements DaffExternalScriptServiceInterface {\n readonly scriptMap: Map<string, LoadedExternalScript> = new Map();\n private doc: Document;\n\n constructor(\n @Inject(DOCUMENT) doc,\n ) {\n this.doc = doc;\n }\n\n /**\n * @inheritdoc\n */\n load(name: string, script: DaffExternalScript): Observable<boolean> {\n // Don't load the same script twice.\n if(this.scriptMap.has(name)){\n return this.scriptMap.get(name).subject;\n }\n\n const scriptEl = this.doc.createElement('script');\n\n scriptEl.setAttribute('type', 'text/javascript');\n\n scriptEl.setAttribute('src', script.src);\n\n scriptEl.setAttribute('charset', 'utf-8');\n\n // Set custom attributes prefixed with 'data-'.\n Object.keys(script).filter(key => key.startsWith('data-')).map((key) => {\n // setAttribute would lowercase the value of \"key\", which isn't always correct.\n // setAttributeNS maintains key casing.\n scriptEl.setAttributeNS(null, key,script[key]);\n });\n\n if(script.async) {\n scriptEl.async = true;\n }\n\n if(script.defer) {\n scriptEl.defer = true;\n }\n\n const readySubject = new BehaviorSubject<boolean | undefined>(undefined);\n\n scriptEl.onload = () => {\n this.scriptMap.get(name).ready = true;\n readySubject.next(true);\n };\n\n scriptEl.onerror = () => {\n this.scriptMap.get(name).ready = false;\n readySubject.error(new Error(`Failed to load ${ script.src }`));\n };\n\n this.doc.body.appendChild(scriptEl);\n this.scriptMap.set(name, { ...script, ready: undefined, subject: readySubject, el: scriptEl });\n\n return readySubject.pipe(\n filter((s) => s !== undefined),\n );\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;AAqBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BG;MAIU,yBAAyB,CAAA;AAIpC,IAAA,WAAA,CACkB,GAAG,EAAA;AAJZ,QAAA,IAAA,CAAA,SAAS,GAAsC,IAAI,GAAG,EAAE,CAAC;AAMhE,QAAA,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;KAChB;AAED;;AAEG;IACH,IAAI,CAAC,IAAY,EAAE,MAA0B,EAAA;;QAE3C,IAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,EAAC;YAC1B,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC;AACzC,SAAA;QAED,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,aA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E,SAAC,CAAC;QAEF,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;QACpC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,GAAG,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;AAE/F,QAAA,OAAO,YAAY,CAAC,IAAI,CACtB,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,SAAS,CAAC,CAC/B,CAAC;KACH;AA5DU,uBAAA,SAAA,IAAA,CAAA,IAAA,GAAA,EAAA,CAAA,kBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,yBAAyB,kBAK5B,QAAQ,EAAA,CAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA,CAAA,EAAA;AALL,uBAAA,SAAA,IAAA,CAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,yBAAyB,cAFxB,MAAM,EAAA,CAAA,CAAA,EAAA;;2FAEP,yBAAyB,EAAA,UAAA,EAAA,CAAA;kBAHrC,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACV,oBAAA,UAAU,EAAE,MAAM;AACnB,iBAAA,CAAA;;0BAME,MAAM;2BAAC,QAAQ,CAAA;;;AC3DlB;;AAEG;;;;"}
|
|
@@ -191,7 +191,7 @@ function daffStartResolution(state) {
|
|
|
191
191
|
function daffStartMutation(state) {
|
|
192
192
|
return {
|
|
193
193
|
...state,
|
|
194
|
-
daffState: "
|
|
194
|
+
daffState: "Updating" /* DaffState.Mutating */,
|
|
195
195
|
};
|
|
196
196
|
}
|
|
197
197
|
;
|
|
@@ -214,7 +214,7 @@ function daffCompleteOperation(state) {
|
|
|
214
214
|
function daffOperationFailed(errors, state) {
|
|
215
215
|
return {
|
|
216
216
|
...state,
|
|
217
|
-
daffState: "
|
|
217
|
+
daffState: "Error" /* DaffState.Error */,
|
|
218
218
|
daffErrors: errors,
|
|
219
219
|
};
|
|
220
220
|
}
|
|
@@ -235,6 +235,21 @@ const daffOperationInitialState = {
|
|
|
235
235
|
daffErrors: [],
|
|
236
236
|
};
|
|
237
237
|
|
|
238
|
+
/**
|
|
239
|
+
* Returns whether the state is one that represents an operation in progress.
|
|
240
|
+
*/
|
|
241
|
+
function daffStateIsLoading(daffState) {
|
|
242
|
+
return daffStateIsMutating(daffState) || daffState === "Resolving" /* DaffState.Resolving */;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Returns whether the state is one that represents a mutable operation in progress.
|
|
246
|
+
*/
|
|
247
|
+
function daffStateIsMutating(daffState) {
|
|
248
|
+
return daffState === "Adding" /* DaffState.Adding */
|
|
249
|
+
|| daffState === "Updating" /* DaffState.Updating */
|
|
250
|
+
|| daffState === "Deleting" /* DaffState.Deleting */;
|
|
251
|
+
}
|
|
252
|
+
|
|
238
253
|
/**
|
|
239
254
|
* Creates a set of selectors for an operation state.
|
|
240
255
|
*
|
|
@@ -242,9 +257,9 @@ const daffOperationInitialState = {
|
|
|
242
257
|
*/
|
|
243
258
|
function daffOperationStateSelectorFactory(selectState) {
|
|
244
259
|
const selectLoadingState = createSelector(selectState, state => state.daffState);
|
|
245
|
-
const selectLoading = createSelector(selectLoadingState, loadingState => loadingState
|
|
260
|
+
const selectLoading = createSelector(selectLoadingState, loadingState => daffStateIsLoading(loadingState));
|
|
246
261
|
const selectResolving = createSelector(selectLoadingState, loadingState => loadingState === "Resolving" /* DaffState.Resolving */);
|
|
247
|
-
const selectMutating = createSelector(selectLoadingState, loadingState => loadingState
|
|
262
|
+
const selectMutating = createSelector(selectLoadingState, loadingState => daffStateIsMutating(loadingState));
|
|
248
263
|
const selectErrors = createSelector(selectState, state => state.daffErrors);
|
|
249
264
|
const selectHasErrors = createSelector(selectErrors, errors => errors.length > 0);
|
|
250
265
|
return {
|
|
@@ -271,35 +286,48 @@ function daffOperationEntityStateSelectorFactory(entitySelectors) {
|
|
|
271
286
|
// ignore placeholders with errors
|
|
272
287
|
!(entity.daffTemp && entity.daffErrors.length > 0)));
|
|
273
288
|
return {
|
|
289
|
+
...entitySelectors,
|
|
274
290
|
selectEntity,
|
|
275
291
|
selectOptimisticList,
|
|
276
292
|
};
|
|
277
293
|
}
|
|
278
294
|
;
|
|
279
295
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
296
|
+
/**
|
|
297
|
+
* @inheritdoc
|
|
298
|
+
*/
|
|
299
|
+
class DaffOperationEntityStateAdapter {
|
|
300
|
+
constructor(adapter = createEntityAdapter()) {
|
|
301
|
+
this.adapter = adapter;
|
|
302
|
+
}
|
|
303
|
+
list(entities, state) {
|
|
304
|
+
return this.adapter.setAll(entities.map(entity => ({
|
|
284
305
|
daffState: "Stable" /* DaffState.Stable */,
|
|
306
|
+
...entity,
|
|
285
307
|
daffErrors: [],
|
|
286
308
|
daffTemp: false,
|
|
287
|
-
})), state)
|
|
288
|
-
|
|
309
|
+
})), state);
|
|
310
|
+
}
|
|
311
|
+
preload(id, state) {
|
|
312
|
+
return this.adapter.upsertOne({
|
|
289
313
|
// TODO: allow for non identifiable entities?
|
|
290
|
-
id
|
|
314
|
+
id,
|
|
291
315
|
daffState: "Resolving" /* DaffState.Resolving */,
|
|
292
316
|
daffErrors: [],
|
|
293
|
-
daffTemp: !state.entities[
|
|
294
|
-
}, state)
|
|
295
|
-
|
|
296
|
-
|
|
317
|
+
daffTemp: !state.entities[id],
|
|
318
|
+
}, state);
|
|
319
|
+
}
|
|
320
|
+
load(entity, state) {
|
|
321
|
+
return this.adapter.upsertOne({
|
|
297
322
|
daffState: "Stable" /* DaffState.Stable */,
|
|
323
|
+
...entity,
|
|
298
324
|
daffErrors: [],
|
|
299
325
|
daffTemp: false,
|
|
300
|
-
}, state)
|
|
301
|
-
|
|
302
|
-
|
|
326
|
+
}, state);
|
|
327
|
+
}
|
|
328
|
+
preadd(entity, state, placeholderId) {
|
|
329
|
+
return placeholderId
|
|
330
|
+
? this.adapter.upsertOne({
|
|
303
331
|
...entity,
|
|
304
332
|
// TODO: allow for non identifiable entities?
|
|
305
333
|
id: placeholderId,
|
|
@@ -307,56 +335,68 @@ function daffCreateOperationEntityStateAdapter(adapter = createEntityAdapter())
|
|
|
307
335
|
daffErrors: [],
|
|
308
336
|
daffTemp: true,
|
|
309
337
|
}, state)
|
|
310
|
-
: state
|
|
311
|
-
|
|
312
|
-
|
|
338
|
+
: state;
|
|
339
|
+
}
|
|
340
|
+
add(entity, state, placeholderId) {
|
|
341
|
+
return this.adapter.upsertOne({
|
|
313
342
|
daffState: "Added" /* DaffState.Added */,
|
|
343
|
+
...entity,
|
|
314
344
|
daffErrors: [],
|
|
315
345
|
daffTemp: false,
|
|
316
|
-
}, placeholderId ? adapter.removeOne(placeholderId, state) : state)
|
|
317
|
-
|
|
346
|
+
}, placeholderId ? this.adapter.removeOne(placeholderId, state) : state);
|
|
347
|
+
}
|
|
348
|
+
preupdate(entity, state) {
|
|
349
|
+
return this.adapter.upsertOne({
|
|
318
350
|
...state.entities[entity.id],
|
|
319
|
-
daffState: "
|
|
351
|
+
daffState: "Updating" /* DaffState.Mutating */,
|
|
320
352
|
daffErrors: [],
|
|
321
|
-
}, state)
|
|
322
|
-
|
|
353
|
+
}, state);
|
|
354
|
+
}
|
|
355
|
+
update(entity, state) {
|
|
356
|
+
return this.adapter.updateOne({
|
|
323
357
|
id: entity.id,
|
|
324
358
|
changes: {
|
|
359
|
+
daffState: "Updated" /* DaffState.Mutated */,
|
|
325
360
|
...entity,
|
|
326
|
-
daffState: "Mutated" /* DaffState.Mutated */,
|
|
327
361
|
daffErrors: [],
|
|
328
362
|
daffTemp: false,
|
|
329
363
|
},
|
|
330
|
-
}, state)
|
|
331
|
-
|
|
364
|
+
}, state);
|
|
365
|
+
}
|
|
366
|
+
preremove(key, state) {
|
|
367
|
+
return this.adapter.upsertOne({
|
|
332
368
|
...state.entities[key],
|
|
333
369
|
daffErrors: [],
|
|
334
370
|
daffState: "Deleting" /* DaffState.Deleting */,
|
|
335
|
-
}, state)
|
|
336
|
-
|
|
337
|
-
|
|
371
|
+
}, state);
|
|
372
|
+
}
|
|
373
|
+
remove(key, state) {
|
|
374
|
+
return this.adapter.removeOne(key, state);
|
|
375
|
+
}
|
|
376
|
+
operationFailed(key, errors, state) {
|
|
377
|
+
return this.adapter.upsertOne({
|
|
338
378
|
...state.entities[key],
|
|
339
|
-
daffState: "
|
|
379
|
+
daffState: "Error" /* DaffState.Error */,
|
|
340
380
|
daffErrors: errors,
|
|
341
|
-
}, state)
|
|
342
|
-
|
|
381
|
+
}, state);
|
|
382
|
+
}
|
|
383
|
+
resetState(key, state) {
|
|
384
|
+
return this.adapter.upsertOne({
|
|
343
385
|
...state.entities[key],
|
|
344
386
|
daffState: "Stable" /* DaffState.Stable */,
|
|
345
|
-
}, state)
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
387
|
+
}, state);
|
|
388
|
+
}
|
|
389
|
+
getInitialState(state) {
|
|
390
|
+
return this.adapter.getInitialState(state);
|
|
391
|
+
}
|
|
392
|
+
getSelectors(selectState) {
|
|
393
|
+
return daffOperationEntityStateSelectorFactory(this.adapter.getSelectors(selectState));
|
|
394
|
+
}
|
|
349
395
|
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
* Returns whether the state is one that represents an operation in progress.
|
|
353
|
-
*/
|
|
354
|
-
function daffStateIsLoading(daffState) {
|
|
355
|
-
return daffState === "Adding" /* DaffState.Adding */
|
|
356
|
-
|| daffState === "Mutating" /* DaffState.Mutating */
|
|
357
|
-
|| daffState === "Resolving" /* DaffState.Resolving */
|
|
358
|
-
|| daffState === "Deleting" /* DaffState.Deleting */;
|
|
396
|
+
function daffCreateOperationEntityStateAdapter(adapter = createEntityAdapter()) {
|
|
397
|
+
return new DaffOperationEntityStateAdapter(adapter);
|
|
359
398
|
}
|
|
399
|
+
|
|
360
400
|
/**
|
|
361
401
|
* Generate a fake ID for use with placeholder entities.
|
|
362
402
|
*
|
|
@@ -424,5 +464,5 @@ const daffIdentityReducer = (state, action) => state;
|
|
|
424
464
|
* Generated bundle index. Do not edit.
|
|
425
465
|
*/
|
|
426
466
|
|
|
427
|
-
export { DaffCollectionFacade, DaffCollectionStateAdapter, daffClearErrors, daffCollectionReducerInitialState, daffCollectionSelectorFactory, daffCompleteOperation, daffComposeReducers, daffCreateOperationEntityStateAdapter, daffIdentityReducer, daffOperationEntityCreateFakeId, daffOperationEntityStateSelectorFactory, daffOperationFailed, daffOperationInitialState, daffOperationStateSelectorFactory, daffStartMutation, daffStartResolution, daffStateIsLoading, daffTransformErrorToStateError, getCollectionStateAdapter, substream };
|
|
467
|
+
export { DaffCollectionFacade, DaffCollectionStateAdapter, DaffOperationEntityStateAdapter, daffClearErrors, daffCollectionReducerInitialState, daffCollectionSelectorFactory, daffCompleteOperation, daffComposeReducers, daffCreateOperationEntityStateAdapter, daffIdentityReducer, daffOperationEntityCreateFakeId, daffOperationEntityStateSelectorFactory, daffOperationFailed, daffOperationInitialState, daffOperationStateSelectorFactory, daffStartMutation, daffStartResolution, daffStateIsLoading, daffStateIsMutating, daffTransformErrorToStateError, getCollectionStateAdapter, substream };
|
|
428
468
|
//# sourceMappingURL=daffodil-core-state.mjs.map
|