Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function getEffectStart(name: string, creators?: boolean): string {
const effectName = stringUtils.classify(name);
return creators
? `load${effectName}s$ = createEffect(() => {` +
'\n return this.actions$.pipe( \n'
: '@Effect()\n' + ` load${effectName}s$ = this.actions$.pipe(`;
}
}
const text = host.read(modulePath);
if (text === null) {
throw new SchematicsException(`File ${modulePath} does not exist.`);
}
const sourceText = text.toString('utf-8');
const source = ts.createSourceFile(
modulePath,
sourceText,
ts.ScriptTarget.Latest,
true
);
const effectsName = `${stringUtils.classify(`${options.name}Effects`)}`;
const effectsModuleImport = insertImport(
source,
modulePath,
'EffectsModule',
'@ngrx/effects'
);
const effectsPath =
`/${options.path}/` +
(options.flat ? '' : stringUtils.dasherize(options.name) + '/') +
(options.group ? 'effects/' : '') +
stringUtils.dasherize(options.name) +
'.effects';
const relativePath = buildRelativePath(modulePath, effectsPath);
const effectsImport = insertImport(
}
`;
const rootStoreReducers = options.minimal ? `{}` : `reducers`;
const rootStoreConfig = options.minimal
? `{ ${runtimeChecks} }`
: `{
metaReducers, ${runtimeChecks} }`;
const storeNgModuleImport = addImportToModule(
source,
modulePath,
options.root
? `StoreModule.forRoot(${rootStoreReducers}, ${rootStoreConfig})`
: `StoreModule.forFeature(from${stringUtils.classify(
options.name
)}.${stringUtils.camelize(
options.name
)}FeatureKey, from${stringUtils.classify(
options.name
)}.reducers, { metaReducers: from${stringUtils.classify(
options.name
)}.metaReducers })`,
relativePath
).shift();
let commonImports = [
insertImport(source, modulePath, 'StoreModule', '@ngrx/store'),
storeNgModuleImport,
];
const srcPath = dirname(options.path as Path);
const environmentsPath = buildRelativePath(
statePath,
`${srcPath}/environments/environment`
);
if (options.module) {
options.module = findModuleFromOptions(host, options);
}
if (
options.root &&
options.stateInterface &&
options.stateInterface !== 'State'
) {
options.stateInterface = stringUtils.classify(options.stateInterface);
}
const templateSource = apply(url('./files'), [
options.root && options.minimal ? filter(_ => false) : noop(),
applyTemplates({
...stringUtils,
...(options as object),
isLib: isLib(host, options),
environmentsPath,
}),
move(parsedPath.path),
]);
return chain([
branchAndMerge(
chain([addImportToNgModule(options), mergeWith(templateSource)])