本文整理汇总了TypeScript中@ngrx/schematics/schematics-core.stringUtils.dasherize方法的典型用法代码示例。如果您正苦于以下问题:TypeScript stringUtils.dasherize方法的具体用法?TypeScript stringUtils.dasherize怎么用?TypeScript stringUtils.dasherize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@ngrx/schematics/schematics-core.stringUtils
的用法示例。
在下文中一共展示了stringUtils.dasherize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: return
return (host: Tree) => {
if (!options.state && !options.stateInterface) {
return host;
}
const statePath = `/${options.path}/${options.state}`;
if (options.state) {
if (!host.exists(statePath)) {
throw new Error(`The Specified state path ${statePath} does not exist`);
}
}
const componentPath =
`/${options.path}/` +
(options.flat ? '' : stringUtils.dasherize(options.name) + '/') +
stringUtils.dasherize(options.name) +
'.component.ts';
const text = host.read(componentPath);
if (text === null) {
throw new SchematicsException(`File ${componentPath} does not exist.`);
}
const sourceText = text.toString('utf-8');
const source = ts.createSourceFile(
componentPath,
sourceText,
ts.ScriptTarget.Latest,
true
);
const stateImportPath = buildRelativePath(componentPath, statePath);
const storeImport = insertImport(
source,
componentPath,
'Store',
'@ngrx/store'
);
const stateImport = options.state
? insertImport(
source,
componentPath,
`* as fromStore`,
stateImportPath,
true
)
: new NoopChange();
const componentClass = source.statements.find(
stm => stm.kind === ts.SyntaxKind.ClassDeclaration
);
const component = componentClass as ts.ClassDeclaration;
const componentConstructor = component.members.find(
member => member.kind === ts.SyntaxKind.Constructor
);
const cmpCtr = componentConstructor as ts.ConstructorDeclaration;
const { pos } = cmpCtr;
const stateType = options.state
? `fromStore.${options.stateInterface}`
: 'any';
const constructorText = cmpCtr.getText();
const [start, end] = constructorText.split('()');
const storeText = `private store: Store<${stateType}>`;
const storeConstructor = [start, `(${storeText})`, end].join('');
const constructorUpdate = new ReplaceChange(
componentPath,
pos,
` ${constructorText}\n\n`,
`\n\n ${storeConstructor}`
);
const changes = [storeImport, stateImport, constructorUpdate];
const recorder = host.beginUpdate(componentPath);
for (const change of changes) {
if (change instanceof InsertChange) {
recorder.insertLeft(change.pos, change.toAdd);
} else if (change instanceof ReplaceChange) {
recorder.remove(pos, change.oldText.length);
recorder.insertLeft(change.order, change.newText);
}
}
host.commitUpdate(recorder);
return host;
};