How to use the @ngrx/schematics/schematics-core.addImportToModule function in @ngrx/schematics

To help you get started, we’ve selected a few @ngrx/schematics examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ngrx / platform / modules / schematics / src / effect / index.ts View on Github external
`/${options.path}/` +
      (options.flat ? '' : stringUtils.dasherize(options.name) + '/') +
      (options.group ? 'effects/' : '') +
      stringUtils.dasherize(options.name) +
      '.effects';
    const relativePath = buildRelativePath(modulePath, effectsPath);
    const effectsImport = insertImport(
      source,
      modulePath,
      effectsName,
      relativePath
    );

    const effectsSetup =
      options.root && options.minimal ? `[]` : `[${effectsName}]`;
    const [effectsNgModuleImport] = addImportToModule(
      source,
      modulePath,
      `EffectsModule.for${options.root ? 'Root' : 'Feature'}(${effectsSetup})`,
      relativePath
    );

    let changes = [effectsModuleImport, effectsNgModuleImport];

    if (!options.root || (options.root && !options.minimal)) {
      changes = changes.concat([effectsImport]);
    }

    const recorder = host.beginUpdate(modulePath);
    for (const change of changes) {
      if (change instanceof InsertChange) {
        recorder.insertLeft(change.pos, change.toAdd);
github ngrx / platform / modules / schematics / src / store / index.ts View on Github external
const runtimeChecks = `
      runtimeChecks: {
        strictStateImmutability: true,
        strictActionImmutability: true,
      }
   `;

    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();