@rs-x/angular 2.0.0-next.6 → 2.0.0-next.7
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,5 +1,5 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { InjectionToken, APP_INITIALIZER, inject, ChangeDetectorRef, Pipe } from '@angular/core';
|
|
2
|
+
import { InjectionToken, APP_INITIALIZER, inject, ChangeDetectorRef, NgZone, Pipe } from '@angular/core';
|
|
3
3
|
import { InjectionContainer, Type, UnsupportedException } from '@rs-x/core';
|
|
4
4
|
import { RsXExpressionParserInjectionTokens, RsXExpressionParserModule, AbstractExpression, CompiledExpression } from '@rs-x/expression-parser';
|
|
5
5
|
|
|
@@ -33,6 +33,7 @@ function providexRsx() {
|
|
|
33
33
|
|
|
34
34
|
class RsxPipe {
|
|
35
35
|
_changeDetectorRef = inject(ChangeDetectorRef);
|
|
36
|
+
_ngZone = inject(NgZone);
|
|
36
37
|
_expressionFactory = inject(IExpressionFactoryToken);
|
|
37
38
|
_expression;
|
|
38
39
|
_changedSubscription;
|
|
@@ -77,8 +78,18 @@ class RsxPipe {
|
|
|
77
78
|
return;
|
|
78
79
|
}
|
|
79
80
|
this._value = this._expression.value;
|
|
81
|
+
this.requestViewCheck();
|
|
80
82
|
this._changedSubscription = this._expression.changed.subscribe(() => {
|
|
81
83
|
this._value = this._expression.value;
|
|
84
|
+
this.requestViewCheck();
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
requestViewCheck() {
|
|
88
|
+
if (NgZone.isInAngularZone()) {
|
|
89
|
+
this._changeDetectorRef.markForCheck();
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
this._ngZone.run(() => {
|
|
82
93
|
this._changeDetectorRef.markForCheck();
|
|
83
94
|
});
|
|
84
95
|
}
|
|
@@ -86,17 +97,16 @@ class RsxPipe {
|
|
|
86
97
|
if (this._ownsExpression) {
|
|
87
98
|
this._expression?.dispose();
|
|
88
99
|
}
|
|
89
|
-
this._ownsExpression = false;
|
|
90
100
|
this._changedSubscription?.unsubscribe();
|
|
91
101
|
this._changedSubscription = undefined;
|
|
92
102
|
this._expression = undefined;
|
|
103
|
+
this._ownsExpression = false;
|
|
93
104
|
}
|
|
94
105
|
isExpressionInstance(value) {
|
|
95
106
|
if (!value || Type.isString(value)) {
|
|
96
107
|
return false;
|
|
97
108
|
}
|
|
98
|
-
return (value instanceof AbstractExpression ||
|
|
99
|
-
value instanceof CompiledExpression);
|
|
109
|
+
return (value instanceof AbstractExpression || value instanceof CompiledExpression);
|
|
100
110
|
}
|
|
101
111
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.1", ngImport: i0, type: RsxPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
|
|
102
112
|
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "21.1.1", ngImport: i0, type: RsxPipe, isStandalone: true, name: "rsx", pure: false });
|
|
@@ -106,6 +116,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.1", ngImpor
|
|
|
106
116
|
args: [{
|
|
107
117
|
name: 'rsx',
|
|
108
118
|
pure: false,
|
|
119
|
+
standalone: true,
|
|
109
120
|
}]
|
|
110
121
|
}] });
|
|
111
122
|
|
|
@@ -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 {\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
|
|
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 NgZone,\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 standalone: true,\n})\nexport class RsxPipe implements PipeTransform, OnDestroy {\n private readonly _changeDetectorRef = inject(ChangeDetectorRef);\n private readonly _ngZone = inject(NgZone);\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 this.tryToSubscribeToExpression();\n }\n\n private tryToSubscribeToExpression(): void {\n if (!this._expression) {\n return;\n }\n\n this._value = this._expression.value;\n this.requestViewCheck();\n this._changedSubscription = this._expression.changed.subscribe(() => {\n this._value = this._expression!.value;\n this.requestViewCheck();\n });\n }\n\n private requestViewCheck(): void {\n if (NgZone.isInAngularZone()) {\n this._changeDetectorRef.markForCheck();\n return;\n }\n\n this._ngZone.run(() => {\n this._changeDetectorRef.markForCheck();\n });\n }\n\n private disposeExpression(): void {\n if (this._ownsExpression) {\n this._expression?.dispose();\n }\n this._changedSubscription?.unsubscribe();\n this._changedSubscription = undefined;\n this._expression = undefined;\n this._ownsExpression = false;\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\n return (\n value instanceof AbstractExpression || 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,UAAU,EAAE,MACV,kBAAkB,CAAC,GAAG,CACpB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,WAAW,GAAG,SAAS;AAC5B,QAAA,IAAI,CAAC,eAAe,GAAG,KAAK;IAC9B;AAEQ,IAAA,oBAAoB,CAC1B,KAA8C,EAAA;QAE9C,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;AAClC,YAAA,OAAO,KAAK;QACd;QAEA,QACE,KAAK,YAAY,kBAAkB,IAAI,KAAK,YAAY,kBAAkB;IAE9E;uGAlGW,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;kBALnB,IAAI;AAAC,YAAA,IAAA,EAAA,CAAA;AACJ,oBAAA,IAAI,EAAE,KAAK;AACX,oBAAA,IAAI,EAAE,KAAK;AACX,oBAAA,UAAU,EAAE,IAAI;AACjB,iBAAA;;;ACvBD;;AAEG;;ACFH;;AAEG;;;;"}
|
package/package.json
CHANGED
package/types/rs-x-angular.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { IExpression, IExpressionFactory, IExpressionChangeTransactionManager }
|
|
|
4
4
|
|
|
5
5
|
declare class RsxPipe implements PipeTransform, OnDestroy {
|
|
6
6
|
private readonly _changeDetectorRef;
|
|
7
|
+
private readonly _ngZone;
|
|
7
8
|
private readonly _expressionFactory;
|
|
8
9
|
private _expression?;
|
|
9
10
|
private _changedSubscription?;
|
|
@@ -15,6 +16,7 @@ declare class RsxPipe implements PipeTransform, OnDestroy {
|
|
|
15
16
|
ngOnDestroy(): void;
|
|
16
17
|
private createExpression;
|
|
17
18
|
private tryToSubscribeToExpression;
|
|
19
|
+
private requestViewCheck;
|
|
18
20
|
private disposeExpression;
|
|
19
21
|
private isExpressionInstance;
|
|
20
22
|
static ɵfac: i0.ɵɵFactoryDeclaration<RsxPipe, never>;
|