@rs-x/angular 2.0.0-next.4 → 2.0.0-next.6
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
2
|
import { InjectionToken, APP_INITIALIZER, inject, ChangeDetectorRef, Pipe } from '@angular/core';
|
|
3
3
|
import { InjectionContainer, Type, UnsupportedException } from '@rs-x/core';
|
|
4
|
-
import { RsXExpressionParserInjectionTokens, RsXExpressionParserModule, AbstractExpression } from '@rs-x/expression-parser';
|
|
4
|
+
import { RsXExpressionParserInjectionTokens, RsXExpressionParserModule, AbstractExpression, CompiledExpression } from '@rs-x/expression-parser';
|
|
5
5
|
|
|
6
6
|
const IExpressionFactoryToken = new InjectionToken('IExpressionFactoryProvider');
|
|
7
7
|
const IExpressionChangeTransactionManagerToken = new InjectionToken('IExpressionChangeTransactionManager');
|
|
@@ -41,9 +41,9 @@ class RsxPipe {
|
|
|
41
41
|
_ownsExpression = false;
|
|
42
42
|
_value;
|
|
43
43
|
transform(expression, context) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
expression !== this._lastExpressionString ||
|
|
44
|
+
const isExpression = this.isExpressionInstance(expression);
|
|
45
|
+
if ((isExpression && this._expression !== expression) ||
|
|
46
|
+
(!isExpression && expression !== this._lastExpressionString) ||
|
|
47
47
|
context !== this._lastContext) {
|
|
48
48
|
this.disposeExpression();
|
|
49
49
|
this.createExpression(expression, context);
|
|
@@ -54,7 +54,7 @@ class RsxPipe {
|
|
|
54
54
|
this.disposeExpression();
|
|
55
55
|
}
|
|
56
56
|
createExpression(expression, context) {
|
|
57
|
-
if (expression
|
|
57
|
+
if (this.isExpressionInstance(expression)) {
|
|
58
58
|
this._lastExpressionString = undefined;
|
|
59
59
|
this._expression = expression;
|
|
60
60
|
this._ownsExpression = false;
|
|
@@ -76,6 +76,7 @@ class RsxPipe {
|
|
|
76
76
|
if (!this._expression) {
|
|
77
77
|
return;
|
|
78
78
|
}
|
|
79
|
+
this._value = this._expression.value;
|
|
79
80
|
this._changedSubscription = this._expression.changed.subscribe(() => {
|
|
80
81
|
this._value = this._expression.value;
|
|
81
82
|
this._changeDetectorRef.markForCheck();
|
|
@@ -90,6 +91,13 @@ class RsxPipe {
|
|
|
90
91
|
this._changedSubscription = undefined;
|
|
91
92
|
this._expression = undefined;
|
|
92
93
|
}
|
|
94
|
+
isExpressionInstance(value) {
|
|
95
|
+
if (!value || Type.isString(value)) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
return (value instanceof AbstractExpression ||
|
|
99
|
+
value instanceof CompiledExpression);
|
|
100
|
+
}
|
|
93
101
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: RsxPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
|
|
94
102
|
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "21.1.1", ngImport: i0, type: RsxPipe, isStandalone: true, name: "rsx", pure: false });
|
|
95
103
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rs-x-angular.mjs","sources":["../../../projects/rsx/src/lib/rsx.providers.ts","../../../projects/rsx/src/lib/rsx.pipe.ts","../../../projects/rsx/src/public-api.ts","../../../projects/rsx/src/rs-x-angular.ts"],"sourcesContent":["import { APP_INITIALIZER, InjectionToken, type Provider } from '@angular/core';\n\nimport { InjectionContainer } from '@rs-x/core';\nimport {\n type IExpressionChangeTransactionManager,\n type IExpressionFactory,\n RsXExpressionParserInjectionTokens,\n RsXExpressionParserModule,\n} from '@rs-x/expression-parser';\n\nexport const IExpressionFactoryToken = new InjectionToken<IExpressionFactory>(\n 'IExpressionFactoryProvider',\n);\n\nexport const IExpressionChangeTransactionManagerToken =\n new InjectionToken<IExpressionChangeTransactionManager>(\n 'IExpressionChangeTransactionManager',\n );\n\nfunction initializeRsx(): () => Promise<void> {\n return () => {\n if (\n InjectionContainer.isBound(\n RsXExpressionParserInjectionTokens.IExpressionFactory,\n )\n ) {\n return Promise.resolve();\n }\n return InjectionContainer.load(RsXExpressionParserModule);\n };\n}\n\nexport function providexRsx(): Provider[] {\n return [\n {\n provide: APP_INITIALIZER,\n useFactory: initializeRsx,\n multi: true,\n },\n {\n provide: IExpressionFactoryToken,\n useFactory: () =>\n InjectionContainer.get(\n RsXExpressionParserInjectionTokens.IExpressionFactory,\n ),\n },\n {\n provide: IExpressionChangeTransactionManagerToken,\n useFactory: () =>\n InjectionContainer.get(\n RsXExpressionParserInjectionTokens.IExpressionChangeTransactionManager,\n ),\n },\n ];\n}\n","import {\n ChangeDetectorRef,\n inject,\n type OnDestroy,\n Pipe,\n type PipeTransform,\n} from '@angular/core';\nimport { Subscription } from 'rxjs';\n\nimport { Type, UnsupportedException } from '@rs-x/core';\nimport {
|
|
1
|
+
{"version":3,"file":"rs-x-angular.mjs","sources":["../../../projects/rsx/src/lib/rsx.providers.ts","../../../projects/rsx/src/lib/rsx.pipe.ts","../../../projects/rsx/src/public-api.ts","../../../projects/rsx/src/rs-x-angular.ts"],"sourcesContent":["import { APP_INITIALIZER, InjectionToken, type Provider } from '@angular/core';\n\nimport { InjectionContainer } from '@rs-x/core';\nimport {\n type IExpressionChangeTransactionManager,\n type IExpressionFactory,\n RsXExpressionParserInjectionTokens,\n RsXExpressionParserModule,\n} from '@rs-x/expression-parser';\n\nexport const IExpressionFactoryToken = new InjectionToken<IExpressionFactory>(\n 'IExpressionFactoryProvider',\n);\n\nexport const IExpressionChangeTransactionManagerToken =\n new InjectionToken<IExpressionChangeTransactionManager>(\n 'IExpressionChangeTransactionManager',\n );\n\nfunction initializeRsx(): () => Promise<void> {\n return () => {\n if (\n InjectionContainer.isBound(\n RsXExpressionParserInjectionTokens.IExpressionFactory,\n )\n ) {\n return Promise.resolve();\n }\n return InjectionContainer.load(RsXExpressionParserModule);\n };\n}\n\nexport function providexRsx(): Provider[] {\n return [\n {\n provide: APP_INITIALIZER,\n useFactory: initializeRsx,\n multi: true,\n },\n {\n provide: IExpressionFactoryToken,\n useFactory: () =>\n InjectionContainer.get(\n RsXExpressionParserInjectionTokens.IExpressionFactory,\n ),\n },\n {\n provide: IExpressionChangeTransactionManagerToken,\n useFactory: () =>\n InjectionContainer.get(\n RsXExpressionParserInjectionTokens.IExpressionChangeTransactionManager,\n ),\n },\n ];\n}\n","import {\n ChangeDetectorRef,\n inject,\n type OnDestroy,\n Pipe,\n type PipeTransform,\n} from '@angular/core';\nimport { Subscription } from 'rxjs';\n\nimport { Type, UnsupportedException } from '@rs-x/core';\nimport {\n AbstractExpression,\n CompiledExpression,\n type IExpression,\n} from '@rs-x/expression-parser';\n\nimport { IExpressionFactoryToken } from './rsx.providers';\n\n@Pipe({\n name: 'rsx',\n pure: false,\n})\nexport class RsxPipe implements PipeTransform, OnDestroy {\n private readonly _changeDetectorRef = inject(ChangeDetectorRef);\n private readonly _expressionFactory = inject(IExpressionFactoryToken);\n private _expression?: IExpression<unknown>;\n private _changedSubscription?: Subscription;\n private _lastExpressionString?: string;\n private _lastContext?: object;\n private _ownsExpression = false;\n private _value: unknown;\n\n public transform<T>(\n expression: string | IExpression<T> | null | undefined,\n context?: object,\n ): T {\n const isExpression = this.isExpressionInstance(expression);\n if (\n (isExpression && this._expression !== expression) ||\n (!isExpression && expression !== this._lastExpressionString) ||\n context !== this._lastContext\n ) {\n this.disposeExpression();\n this.createExpression(expression, context);\n }\n\n return this._value as T;\n }\n\n public ngOnDestroy(): void {\n this.disposeExpression();\n }\n\n private createExpression(\n expression: string | IExpression | null | undefined,\n context?: object,\n ): void {\n if (this.isExpressionInstance(expression)) {\n this._lastExpressionString = undefined;\n this._expression = expression;\n this._ownsExpression = false;\n } else if (Type.isString(expression)) {\n this._lastExpressionString = expression;\n if (context) {\n this._expression = this._expressionFactory.create(context, expression);\n this._ownsExpression = true;\n }\n } else if (!Type.isNullOrUndefined(expression)) {\n throw new UnsupportedException(`string or IExpression expected`);\n }\n\n this._lastContext = context;\n\n this.tryToSubscribeToExpression();\n }\n\n private tryToSubscribeToExpression(): void {\n if (!this._expression) {\n return;\n }\n this._value = this._expression.value;\n this._changedSubscription = this._expression.changed.subscribe(() => {\n this._value = this._expression!.value;\n this._changeDetectorRef.markForCheck();\n });\n }\n\n private disposeExpression(): void {\n if (this._ownsExpression) {\n this._expression?.dispose();\n }\n this._ownsExpression = false;\n this._changedSubscription?.unsubscribe();\n this._changedSubscription = undefined;\n this._expression = undefined;\n }\n\n private isExpressionInstance(\n value: string | IExpression | null | undefined,\n ): value is IExpression {\n if (!value || Type.isString(value)) {\n return false;\n }\n return (\n value instanceof AbstractExpression ||\n value instanceof CompiledExpression\n );\n }\n}\n","/*\n * Public API Surface of rsx\n */\n\nexport * from './lib';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;MAUa,uBAAuB,GAAG,IAAI,cAAc,CACvD,4BAA4B;MAGjB,wCAAwC,GACnD,IAAI,cAAc,CAChB,qCAAqC;AAGzC,SAAS,aAAa,GAAA;AACpB,IAAA,OAAO,MAAK;QACV,IACE,kBAAkB,CAAC,OAAO,CACxB,kCAAkC,CAAC,kBAAkB,CACtD,EACD;AACA,YAAA,OAAO,OAAO,CAAC,OAAO,EAAE;QAC1B;AACA,QAAA,OAAO,kBAAkB,CAAC,IAAI,CAAC,yBAAyB,CAAC;AAC3D,IAAA,CAAC;AACH;SAEgB,WAAW,GAAA;IACzB,OAAO;AACL,QAAA;AACE,YAAA,OAAO,EAAE,eAAe;AACxB,YAAA,UAAU,EAAE,aAAa;AACzB,YAAA,KAAK,EAAE,IAAI;AACZ,SAAA;AACD,QAAA;AACE,YAAA,OAAO,EAAE,uBAAuB;YAChC,UAAU,EAAE,MACV,kBAAkB,CAAC,GAAG,CACpB,kCAAkC,CAAC,kBAAkB,CACtD;AACJ,SAAA;AACD,QAAA;AACE,YAAA,OAAO,EAAE,wCAAwC;YACjD,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,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,IAAA,EAAA,CAAA;qGAAP,OAAO,EAAA,YAAA,EAAA,IAAA,EAAA,IAAA,EAAA,KAAA,EAAA,IAAA,EAAA,KAAA,EAAA,CAAA;;2FAAP,OAAO,EAAA,UAAA,EAAA,CAAA;kBAJnB,IAAI;AAAC,YAAA,IAAA,EAAA,CAAA;AACJ,oBAAA,IAAI,EAAE,KAAK;AACX,oBAAA,IAAI,EAAE,KAAK;AACZ,iBAAA;;;ACrBD;;AAEG;;ACFH;;AAEG;;;;"}
|
package/package.json
CHANGED
package/types/rs-x-angular.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ declare class RsxPipe implements PipeTransform, OnDestroy {
|
|
|
16
16
|
private createExpression;
|
|
17
17
|
private tryToSubscribeToExpression;
|
|
18
18
|
private disposeExpression;
|
|
19
|
+
private isExpressionInstance;
|
|
19
20
|
static ɵfac: i0.ɵɵFactoryDeclaration<RsxPipe, never>;
|
|
20
21
|
static ɵpipe: i0.ɵɵPipeDeclaration<RsxPipe, "rsx", true>;
|
|
21
22
|
}
|