@rs-x/angular 0.4.22 → 1.0.1
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/README.md
CHANGED
|
@@ -51,7 +51,7 @@ bootstrapApplication(App, {
|
|
|
51
51
|
|
|
52
52
|
The `rsx` pipe enables binding RS-X expressions or strings to Angular templates and automatically updates the view whenever the underlying data changes. It transforms expressions into reactive values, subscribes to changes, triggers Angular change detection, and cleans up subscriptions when no longer needed. It supports both synchronous and asynchronous data sources.
|
|
53
53
|
|
|
54
|
-
The value passed to the `rsx
|
|
54
|
+
The value passed to the `rsx(' pipe can be either an expression string or an expression tree. Expression trees are created by the expression factory. The ')rsx` pipe also requires a model, as the expression tree is bound to that model to resolve the necessary data.
|
|
55
55
|
|
|
56
56
|
Example:
|
|
57
57
|
|
|
@@ -38,6 +38,7 @@ class RsxPipe {
|
|
|
38
38
|
_changedSubscription;
|
|
39
39
|
_lastExpressionString;
|
|
40
40
|
_lastContext;
|
|
41
|
+
_ownsExpression = false;
|
|
41
42
|
_value;
|
|
42
43
|
transform(expression, context) {
|
|
43
44
|
if ((expression instanceof AbstractExpression &&
|
|
@@ -56,11 +57,13 @@ class RsxPipe {
|
|
|
56
57
|
if (expression instanceof AbstractExpression) {
|
|
57
58
|
this._lastExpressionString = undefined;
|
|
58
59
|
this._expression = expression;
|
|
60
|
+
this._ownsExpression = false;
|
|
59
61
|
}
|
|
60
62
|
else if (Type.isString(expression)) {
|
|
61
63
|
this._lastExpressionString = expression;
|
|
62
64
|
if (context) {
|
|
63
65
|
this._expression = this._expressionFactory.create(context, expression);
|
|
66
|
+
this._ownsExpression = true;
|
|
64
67
|
}
|
|
65
68
|
}
|
|
66
69
|
else if (!Type.isNullOrUndefined(expression)) {
|
|
@@ -79,11 +82,12 @@ class RsxPipe {
|
|
|
79
82
|
});
|
|
80
83
|
}
|
|
81
84
|
disposeExpression() {
|
|
82
|
-
this.
|
|
83
|
-
this._changedSubscription = undefined;
|
|
84
|
-
if (this._lastExpressionString) {
|
|
85
|
+
if (this._ownsExpression) {
|
|
85
86
|
this._expression?.dispose();
|
|
86
87
|
}
|
|
88
|
+
this._ownsExpression = false;
|
|
89
|
+
this._changedSubscription?.unsubscribe();
|
|
90
|
+
this._changedSubscription = undefined;
|
|
87
91
|
this._expression = undefined;
|
|
88
92
|
}
|
|
89
93
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: RsxPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
|
|
@@ -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 { AbstractExpression, type IExpression } 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 _value: unknown;\n\n public transform<T>(\n expression: string | IExpression<T> | null | undefined,\n context?: object,\n ): T {\n if (\n (expression instanceof AbstractExpression &&\n this._expression !== expression) ||\n 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 (expression instanceof AbstractExpression) {\n this._lastExpressionString = undefined;\n this._expression = expression;\n } else if (Type.isString(expression)) {\n this._lastExpressionString = expression;\n if (context) {\n this._expression = this._expressionFactory.create(context, expression);\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._changedSubscription = this._expression.changed.subscribe(() => {\n this._value = this._expression!.value;\n this._changeDetectorRef.markForCheck();\n });\n }\n\n private disposeExpression(): void {\n this.
|
|
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 { AbstractExpression, type IExpression } 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 if (\n (expression instanceof AbstractExpression &&\n this._expression !== expression) ||\n 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 (expression instanceof AbstractExpression) {\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._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","/*\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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AG,SAAS;AACrC,QAAA,IAAI,CAAC,WAAW,GAAG,SAAS;IAC9B;uGAxEW,OAAO,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;;;ACjBD;;AAEG;;ACFH;;AAEG;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rs-x/angular",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Angular integration for RS-X, providing the RsxPipe",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "fesm2022/rs-x-angular.mjs",
|
|
@@ -35,11 +35,11 @@
|
|
|
35
35
|
"provenance": true
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@angular/core": ">=21.1.0",
|
|
39
38
|
"@angular/common": ">=21.1.0",
|
|
40
|
-
"
|
|
41
|
-
"@rs-x/core": "^0.
|
|
42
|
-
"@rs-x/expression-parser": "^0.
|
|
39
|
+
"@angular/core": ">=21.1.0",
|
|
40
|
+
"@rs-x/core": "^1.0.0",
|
|
41
|
+
"@rs-x/expression-parser": "^1.0.0",
|
|
42
|
+
"rxjs": ">=7.8.0"
|
|
43
43
|
},
|
|
44
44
|
"peerDependenciesMeta": {
|
|
45
45
|
"@rs-x/core": {
|
package/types/rs-x-angular.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ declare class RsxPipe implements PipeTransform, OnDestroy {
|
|
|
9
9
|
private _changedSubscription?;
|
|
10
10
|
private _lastExpressionString?;
|
|
11
11
|
private _lastContext?;
|
|
12
|
+
private _ownsExpression;
|
|
12
13
|
private _value;
|
|
13
14
|
transform<T>(expression: string | IExpression<T> | null | undefined, context?: object): T;
|
|
14
15
|
ngOnDestroy(): void;
|