本文整理匯總了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;
};