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

To help you get started, we’ve selected a few @ngrx/store 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 / store-builds / schematics / ng-add / index.js View on Github external
throw new schematics_1.SchematicsException(`File ${modulePath} does not exist.`);
            }
            const sourceText = text.toString('utf-8');
            const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
            const storeModuleReducers = options.minimal ? `{}` : `reducers`;
            const storeModuleConfig = options.minimal
                ? `{}`
                : `{
      metaReducers
    }`;
            const storeModuleSetup = `StoreModule.forRoot(${storeModuleReducers}, ${storeModuleConfig})`;
            const statePath = `/${options.path}/${options.statePath}`;
            const relativePath = schematics_core_1.buildRelativePath(modulePath, statePath);
            const [storeNgModuleImport] = schematics_core_1.addImportToModule(source, modulePath, storeModuleSetup, relativePath);
            let changes = [
                schematics_core_1.insertImport(source, modulePath, 'StoreModule', '@ngrx/store'),
                storeNgModuleImport,
            ];
            if (!options.minimal) {
                changes = changes.concat([
                    schematics_core_1.insertImport(source, modulePath, 'reducers, metaReducers', relativePath),
                ]);
            }
            const recorder = host.beginUpdate(modulePath);
            for (const change of changes) {
                if (change instanceof schematics_core_1.InsertChange) {
                    recorder.insertLeft(change.pos, change.toAdd);
                }
            }
            host.commitUpdate(recorder);
            return host;
        };
github ngrx / store-builds / schematics / ng-add / index.js View on Github external
const storeModuleConfig = options.minimal
                ? `{}`
                : `{
      metaReducers
    }`;
            const storeModuleSetup = `StoreModule.forRoot(${storeModuleReducers}, ${storeModuleConfig})`;
            const statePath = `/${options.path}/${options.statePath}`;
            const relativePath = schematics_core_1.buildRelativePath(modulePath, statePath);
            const [storeNgModuleImport] = schematics_core_1.addImportToModule(source, modulePath, storeModuleSetup, relativePath);
            let changes = [
                schematics_core_1.insertImport(source, modulePath, 'StoreModule', '@ngrx/store'),
                storeNgModuleImport,
            ];
            if (!options.minimal) {
                changes = changes.concat([
                    schematics_core_1.insertImport(source, modulePath, 'reducers, metaReducers', relativePath),
                ]);
            }
            const recorder = host.beginUpdate(modulePath);
            for (const change of changes) {
                if (change instanceof schematics_core_1.InsertChange) {
                    recorder.insertLeft(change.pos, change.toAdd);
                }
            }
            host.commitUpdate(recorder);
            return host;
        };
    }
github ngrx / platform / modules / store / schematics / ng-add / index.ts View on Github external
strictActionImmutability: true
      }
    }`;
    const storeModuleSetup = `StoreModule.forRoot(${storeModuleReducers}, ${storeModuleConfig})`;

    const statePath = `/${options.path}/${options.statePath}`;
    const relativePath = buildRelativePath(modulePath, statePath);
    const [storeNgModuleImport] = addImportToModule(
      source,
      modulePath,
      storeModuleSetup,
      relativePath
    );

    let changes = [
      insertImport(source, modulePath, 'StoreModule', '@ngrx/store'),
      storeNgModuleImport,
    ];

    if (!options.minimal) {
      changes = changes.concat([
        insertImport(
          source,
          modulePath,
          'reducers, metaReducers',
          relativePath
        ),
      ]);
    }

    const recorder = host.beginUpdate(modulePath);
github ngrx / platform / modules / store / schematics / ng-add / index.ts View on Github external
const relativePath = buildRelativePath(modulePath, statePath);
    const [storeNgModuleImport] = addImportToModule(
      source,
      modulePath,
      storeModuleSetup,
      relativePath
    );

    let changes = [
      insertImport(source, modulePath, 'StoreModule', '@ngrx/store'),
      storeNgModuleImport,
    ];

    if (!options.minimal) {
      changes = changes.concat([
        insertImport(
          source,
          modulePath,
          'reducers, metaReducers',
          relativePath
        ),
      ]);
    }

    const recorder = host.beginUpdate(modulePath);

    for (const change of changes) {
      if (change instanceof InsertChange) {
        recorder.insertLeft(change.pos, change.toAdd);
      }
    }
    host.commitUpdate(recorder);