juliette-ng
Version:
Angular Plugin for Juliette
115 lines (108 loc) • 6.24 kB
JavaScript
import * as i0 from '@angular/core';
import { InjectionToken, NgModule, Inject } from '@angular/core';
import { Observable } from 'rxjs';
import * as i1 from 'juliette';
import { registerEffects, createStore, Store } from 'juliette';
const INITIAL_ROOT_STATE = new InjectionToken('__julietteNgInternal/initialRootState__');
const FEATURE_KEYS = new InjectionToken('__julietteNgInternal/featureKeys__');
const INITIAL_FEATURE_STATES = new InjectionToken('__julietteNgInternal/initialFeatureStates__');
const DEV_MODE = new InjectionToken('__julietteNgInternal/devMode__');
const OBJECTS_WITH_EFFECTS = new InjectionToken('__julietteNgInternal/objectsWithEffects__');
const fromClassesWithEffectsToClassProviders = (injectionToken, classesWithEffects) => classesWithEffects.map(classWithEffects => ({
provide: injectionToken,
useClass: classWithEffects,
multi: true,
}));
const fromObjectsWithEffectsToEffects = (objectsWithEffects) => objectsWithEffects.reduce((acc, objectWithEffects) => {
const effectsFromCurrentObject = Object.getOwnPropertyNames(objectWithEffects)
.filter(prop => objectWithEffects[prop] instanceof Observable)
.map(prop => objectWithEffects[prop]);
return [...acc, ...effectsFromCurrentObject];
}, []);
class EffectsModule {
constructor(store, objectsWithEffects) {
const effects = fromObjectsWithEffectsToEffects(objectsWithEffects.splice(0, objectsWithEffects.length));
registerEffects(store, effects);
}
static register(classesWithEffects) {
return {
ngModule: EffectsModule,
providers: [
...fromClassesWithEffectsToClassProviders(OBJECTS_WITH_EFFECTS, classesWithEffects),
],
};
}
}
EffectsModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.3", ngImport: i0, type: EffectsModule, deps: [{ token: i1.Store }, { token: OBJECTS_WITH_EFFECTS }], target: i0.ɵɵFactoryTarget.NgModule });
EffectsModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.0.3", ngImport: i0, type: EffectsModule });
EffectsModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.0.3", ngImport: i0, type: EffectsModule });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.3", ngImport: i0, type: EffectsModule, decorators: [{
type: NgModule
}], ctorParameters: function () { return [{ type: i1.Store }, { type: undefined, decorators: [{
type: Inject,
args: [OBJECTS_WITH_EFFECTS]
}] }]; } });
function createStoreFactory(initialState, devMode) {
return createStore(initialState, devMode);
}
class StoreRootModule {
}
StoreRootModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.3", ngImport: i0, type: StoreRootModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
StoreRootModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.0.3", ngImport: i0, type: StoreRootModule });
StoreRootModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.0.3", ngImport: i0, type: StoreRootModule });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.3", ngImport: i0, type: StoreRootModule, decorators: [{
type: NgModule
}] });
class StoreFeatureModule {
constructor(store, featureKeys, initialStates) {
store.addFeatureState(featureKeys.pop(), initialStates.pop());
}
}
StoreFeatureModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.3", ngImport: i0, type: StoreFeatureModule, deps: [{ token: i1.Store }, { token: FEATURE_KEYS }, { token: INITIAL_FEATURE_STATES }], target: i0.ɵɵFactoryTarget.NgModule });
StoreFeatureModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.0.3", ngImport: i0, type: StoreFeatureModule });
StoreFeatureModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.0.3", ngImport: i0, type: StoreFeatureModule });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.3", ngImport: i0, type: StoreFeatureModule, decorators: [{
type: NgModule
}], ctorParameters: function () { return [{ type: i1.Store }, { type: undefined, decorators: [{
type: Inject,
args: [FEATURE_KEYS]
}] }, { type: undefined, decorators: [{
type: Inject,
args: [INITIAL_FEATURE_STATES]
}] }]; } });
class StoreModule {
static forRoot(initialState, devMode = false) {
return {
ngModule: StoreRootModule,
providers: [
{ provide: INITIAL_ROOT_STATE, useValue: initialState },
{ provide: DEV_MODE, useValue: devMode },
{
provide: Store,
useFactory: createStoreFactory,
deps: [INITIAL_ROOT_STATE, DEV_MODE],
},
],
};
}
static forFeature(featureKey, initialState) {
return {
ngModule: StoreFeatureModule,
providers: [
{ provide: FEATURE_KEYS, multi: true, useValue: featureKey },
{ provide: INITIAL_FEATURE_STATES, multi: true, useValue: initialState },
],
};
}
}
StoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.3", ngImport: i0, type: StoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
StoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.0.3", ngImport: i0, type: StoreModule });
StoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.0.3", ngImport: i0, type: StoreModule });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.3", ngImport: i0, type: StoreModule, decorators: [{
type: NgModule
}] });
/**
* Generated bundle index. Do not edit.
*/
export { EffectsModule, StoreFeatureModule, StoreModule, StoreRootModule, createStoreFactory };
//# sourceMappingURL=juliette-ng.js.map