@rx-signals/angular-provider
Advanced tools
Comparing version 3.0.0-rc1 to 3.0.0-rc10
@@ -1,14 +0,19 @@ | ||
import { ModuleWithProviders } from '@angular/core'; | ||
import { EnvironmentProviders, ModuleWithProviders } from '@angular/core'; | ||
import { Store } from '@rx-signals/store'; | ||
import * as i0 from "@angular/core"; | ||
/** | ||
* The argument type for store providers | ||
*/ | ||
export type SetupWithStore = (store: Store) => void; | ||
export declare class RxSignalsStoreModule { | ||
/** | ||
* Use withRootStore, if you need the root store that shares the lifecycle of the whole application. | ||
* Also lazy-loaded feature modules will receive the same root-store instance, if you use withRootStore. | ||
* Use withRootStore, if you want the root store (the store that shares the lifecycle of the whole application). | ||
* If your module is a lazy-loaded feature module, it will still receive the same root-store instance, if you use withRootStore. | ||
* This should be the standard case. | ||
* Pass as many setup functions as you like. | ||
* | ||
* @param {function} setup - optional callback that receives the store and performs setup | ||
* @param {SetupWithStore[]} setups - 0 to n optional setup functions (that will be called with the store instance) | ||
* @returns {ModuleWithProviders<RxSignalsStoreModule>} the module providing the root-store | ||
*/ | ||
static withRootStore(setup?: (store: Store) => void): ModuleWithProviders<RxSignalsStoreModule>; | ||
static withRootStore(...setups: SetupWithStore[]): ModuleWithProviders<RxSignalsStoreModule>; | ||
/** | ||
@@ -18,6 +23,6 @@ * Use withChildStore, if you need a child store that is derived from the root-store. | ||
* | ||
* @param {function} setup - optional callback that receives the child-store and performs setup | ||
* @param {SetupWithStore[]} setups - 0 to n optional setup functions (that will be called with the child-store instance) | ||
* @returns {ModuleWithProviders<RxSignalsStoreModule>} the module providing the child-store | ||
*/ | ||
static withChildStore(setup?: (store: Store) => void): ModuleWithProviders<RxSignalsStoreModule>; | ||
static withChildStore(...setups: SetupWithStore[]): ModuleWithProviders<RxSignalsStoreModule>; | ||
static ɵfac: i0.ɵɵFactoryDeclaration<RxSignalsStoreModule, never>; | ||
@@ -27,1 +32,17 @@ static ɵmod: i0.ɵɵNgModuleDeclaration<RxSignalsStoreModule, never, never, never>; | ||
} | ||
/** | ||
* Use provideStore, in bootstrapApplication to provide the rx-signals root-store (the store that shares the lifecycle of the whole application). | ||
* Pass as many setup functions as you like. | ||
* | ||
* @param {SetupWithStore[]} setups - 0 to n optional setup functions (that will be called with the store instance) | ||
*/ | ||
export declare const provideStore: (...setups: SetupWithStore[]) => EnvironmentProviders; | ||
/** | ||
* Use provideChildStore, in Route.providers to provide a rx-signals child-store to the route. | ||
* See store.createChildStore() for further documentation on child stores. | ||
* Pass as many setup functions as you like. | ||
* | ||
* @param {SetupWithStore[]} setups - 0 to n optional setup functions (that will be called with the child-store instance) | ||
*/ | ||
export declare const provideChildStore: (...setups: SetupWithStore[]) => EnvironmentProviders; | ||
//# sourceMappingURL=rx-signals-store.module.d.ts.map |
{ | ||
"name": "@rx-signals/angular-provider", | ||
"version": "3.0.0-rc1", | ||
"description": "angular module for an opinionated @rx-signals/store integration", | ||
"version": "3.0.0-rc10", | ||
"description": "Angular provider for @rx-signals/store", | ||
"author": "Gerd Neudert", | ||
@@ -9,3 +9,3 @@ "license": "MIT", | ||
"type": "git", | ||
"url": "https://github.com/gneu77/rx-signals-angular-provider" | ||
"url": "https://github.com/gneu77/rx-signals-angular-provider/tree/master/projects/rx-signals/angular-provider" | ||
}, | ||
@@ -28,5 +28,5 @@ "keywords": [ | ||
"peerDependencies": { | ||
"@angular/common": ">=10.0.0", | ||
"@angular/core": ">=10.0.0", | ||
"@rx-signals/store": ">=3.0.0-rc14" | ||
"@angular/common": ">=14.0.0", | ||
"@angular/core": ">=14.0.0", | ||
"@rx-signals/store": ">=3.0.0-rc42" | ||
}, | ||
@@ -41,3 +41,3 @@ "dependencies": { | ||
"fesm2015": "fesm2015/rx-signals-angular-provider.mjs", | ||
"typings": "rx-signals-angular-provider.d.ts", | ||
"typings": "index.d.ts", | ||
"exports": { | ||
@@ -48,3 +48,3 @@ "./package.json": { | ||
".": { | ||
"types": "./rx-signals-angular-provider.d.ts", | ||
"types": "./index.d.ts", | ||
"esm2020": "./esm2020/rx-signals-angular-provider.mjs", | ||
@@ -51,0 +51,0 @@ "es2020": "./fesm2020/rx-signals-angular-provider.mjs", |
export * from './lib/rx-signals-store.module'; | ||
export * from './lib/pipes/rxs-no-value-to-undefined.pipe'; | ||
export * from './lib/pipes/pick.pipe'; | ||
export * from './lib/pipes/any-lens-key.pipe'; | ||
export * from './lib/pipes/lens-key.pipe'; | ||
export * from './lib/directives/rxs-validation.directive'; | ||
//# sourceMappingURL=public-api.d.ts.map |
# @rx-signals/angular-provider | ||
**An angular module for an opinionated @rx-signals/store integration** | ||
You can use this lib for an opinionated [_rx-signals_](https://github.com/gneu77/rx-signals) integration into your Angular application. | ||
Documentation will follow... | ||
## Installation | ||
**`npm install --save @rx-signals/angular-provider@3.0.0-rc10`** | ||
If you have not yet installed the _rx-signals_ store, please see [@rx-signals/store](https://github.com/gneu77/rx-signals#installation) documentation on how to install the latest 3.x version of that peer-dependency. | ||
## License | ||
[MIT](https://choosealicense.com/licenses/mit/) | ||
## Usage | ||
### Modern usage without NgModule | ||
In your `bootstrapApplication`, just use `provideStore()`. | ||
This will provide a `Store` singleton everywhere (so even lazy-loaded routes will receive the same store instance). | ||
If you have functions performing setup with the store (`(store: Store) => void`), you can pass 0 to N of those setup-functions as arguments to `provideStore()`. | ||
#### Optionally using child-stores on child-routes | ||
If you're really sure a child-route should use its own child-store, you can do so by using `provideChildStore()` in the corresponding routes providers array. | ||
Make sure to [read the documentation on child-stores](https://rawcdn.githack.com/gneu77/rx-signals/master/docs/tsdoc/classes/Store.html#createChildStore). | ||
Also, be aware that [store-lifecycles](https://rawcdn.githack.com/gneu77/rx-signals/master/docs/tsdoc/classes/Store.html#getLifecycleHandle) might be a better option for your use-case. | ||
### Usage with classic NgModule | ||
In the topmost module that should use the store (AppModule, SharedModule, CoreModule, or whatever it is for you), you can just import `RxSignalsStoreModule`. | ||
This will provide a `Store` singleton everywhere (so even lazy-loaded feature-modules will receive the same instance). | ||
Instead, if you have functions performing setup with the store (`(store: Store) => void`), you can use `RxSignalsStoreModule.withRootStore()`, passing as many of those setup-functions as arguments as you like. | ||
You can also use `RxSignalsStoreModule.withRootStore()` in your feature-modules (whether lazy or not) to pass corresponding setup-functions of those feature-modules. | ||
> You might be used to modules that come with `forRoot()` and `forFeature()` functions. | ||
> These names make no sense in case of the RxSignalsStoreModule, because the standard-case is to use a single store-instance in all your modules and thus, all these modules should call `withRootStore()`. | ||
> See the next section on use-cases for `withChildStore()`. | ||
#### Optionally using child-stores | ||
If you are really sure that you have a feature-module where you want to use a child-store (derived from the root-store that you get with `RxSignalsStoreModule` or `RxSignalsStoreModule.withRootStore()`), then you can do so by importing `RxSignalsStoreModule.withChildStore()`. | ||
Make sure to [read the documentation on child-stores](https://rawcdn.githack.com/gneu77/rx-signals/master/docs/tsdoc/classes/Store.html#createChildStore). | ||
Also, be aware that [store-lifecycles](https://rawcdn.githack.com/gneu77/rx-signals/master/docs/tsdoc/classes/Store.html#getLifecycleHandle) might be a better option for your use-case. | ||
### Setup effects | ||
If you read about the [concept about side-effect-isolation with the store](https://github.com/gneu77/rx-signals/blob/master/docs/rx-signals_start.md#effect-isolation), you know that the only side-effect that the functions passed to `RxSignalsStoreModule.withRootStore()` and/or `RxSignalsStoreModule.withChildStore()` are allowed to do is calling methods of the passed store. | ||
All the signals being setup in this process should be free of side-effects (allowing you to call the setup-functions in your tests without any need of mockup). | ||
Consequently, the side-effects must be injected to the store by corresponding calls to `store.addEffect`. | ||
In your unit-tests, you would then just mock the effects themselves by `store.addEffect(effectId, () => someMockupReturn)` (so no need to mock anything else). |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
140830
31
1115
61