Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async loadTemplateFromUrl(templateURL) {
const thisTemplateURL = templateURL;
this.setState({ loading: true });
console.log(`Loading template: ${thisTemplateURL}`);
let template;
try {
template = await Template.fromUrl(thisTemplateURL);
} catch (error) {
console.log(`LOAD FAILED! ${error.message}`); // Error!
this.handleLoadingFailed(error.message);
return false;
}
try {
const newState = {...this.state};
newState.templateURL = thisTemplateURL;
newState.clause = new Clause(template);
newState.templateName = newState.clause.getTemplate().getMetadata().getName();
newState.templateVersion = newState.clause.getTemplate().getMetadata().getVersion();
newState.templateType = newState.clause.getTemplate().getMetadata().getTemplateType();
newState.package = JSON.stringify(template.getMetadata().getPackageJson(), null, 2);
newState.grammar = template.getParserManager().getTemplatizedGrammar();
newState.model = template.getModelManager().getModels();
newState.logic = template.getScriptManager().getLogic();
export function* addTemplateObjectToStore(action) {
const templateObjects = yield select(selectors.templateObjects);
if (!templateObjects || !templateObjects[action.uri]) {
try {
const templateObj = yield Template.fromUrl(action.uri);
yield put(actions.loadTemplateObjectSuccess(action.uri, templateObj));
return templateObj;
} catch (err) {
yield put(appActions.addAppError('Failed to load template object', err));
return err;
}
}
return templateObjects[action.uri];
}
export function* addTemplateObjectToStore(action) {
const templateObjects = yield select(selectors.templateObjects);
if (!templateObjects || !templateObjects[action.uri]) {
try {
const templateObj = yield Template.fromUrl(action.uri);
yield put(actions.loadTemplateObjectSuccess(action.uri, templateObj));
return templateObj;
} catch (err) {
yield put(appActions.addAppError('Failed to load template object', err));
return err;
}
}
return templateObjects[action.uri];
}