當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript lodash.clonedeep類代碼示例

本文整理匯總了TypeScript中lodash.clonedeep的典型用法代碼示例。如果您正苦於以下問題:TypeScript clonedeep類的具體用法?TypeScript clonedeep怎麽用?TypeScript clonedeep使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了clonedeep類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: validate

    /**
     * Validate Legacy Jobs
     * DEPRECATED to accommadate for new Job APIs,
     * use validateConfig
    */
    validate(job: any) {
        let validJob = cloneDeep(job);

        // this is used if an operation needs to provide additional validation beyond its own scope
        const topLevelJobValidators : crossValidationFn[] = [];

        // top level job validation occurs, but not operations
        validJob = validateJobConfig(this.schema, validJob);

        validJob.operations = job.operations.map((opConfig: OpConfig) => {
            const operation = this.opLoader.load(opConfig._op, job.assets);

            this.hasSchema(operation, opConfig._op);

            const validOP = validateOpConfig(operation.schema(), opConfig);

            if (operation.selfValidation) {
                operation.selfValidation(validOP);
            }

            if (operation.crossValidation) {
                topLevelJobValidators.push(operation.crossValidation);
            }

            return validOP;
        });

        registerApis(this.context, job);

        topLevelJobValidators.forEach((fn) => {
            fn(validJob, this.context.sysconfig);
        });

        return validJob;
    }
開發者ID:jeffmontagna,項目名稱:teraslice,代碼行數:40,代碼來源:job-validator.ts

示例2: handleModule

    validateConfig(_jobConfig: JobConfig): ValidatedJobConfig {
        // top level job validation occurs, but not operations
        const jobConfig = validateJobConfig(this.schema, cloneDeep(_jobConfig));
        const assetIds = jobConfig.assets || [];
        const apis = {};

        type validateJobFn = (job: ValidatedJobConfig) => void;
        const validateJobFns: validateJobFn[] = [];

        const handleModule = (opConfig: OpConfig, op: OperationModule) => {
            const { Schema, API } = op;

            if (API != null) {
                apis[opConfig._op] = API;
            }

            const schema = new Schema(this.context);

            validateJobFns.push((job) => {
                if (!schema.validateJob) return;
                schema.validateJob(job);
            });

            return schema.validate(opConfig);
        };

        jobConfig.operations = jobConfig.operations.map((opConfig, index) => {
            if (index === 0) {
                return handleModule(opConfig, this.opLoader.loadReader(opConfig._op, assetIds));
            }

            return handleModule(opConfig, this.opLoader.loadProcessor(opConfig._op, assetIds));
        });

        registerApis(this.context, jobConfig);

        validateJobFns.forEach((fn) => { fn(jobConfig); });

        Object.keys(apis).forEach((name) => {
            const api = apis[name];
            this.context.apis.executionContext.addToRegistry(name, api);
        });

        // @ts-ignore
        return jobConfig;
    }
開發者ID:jeffmontagna,項目名稱:teraslice,代碼行數:46,代碼來源:job-validator.ts

示例3: cloneDeep

// Exports
export default function ensureModel<T extends object = object>(
  jsonSchema: object,
  data: T | any,
  message: string = 'Invalid data provided',
): T {
  const safeProps = cloneDeep(data);
  const isValid = schema.validate(jsonSchema, safeProps);
  if (!isValid) {
    throw Schema.createValidationError({
      data,
      message,
      schema: jsonSchema,
      errors: schema.errors,
    });
  }
  return safeProps;
}
開發者ID:komapijs,項目名稱:komapi,代碼行數:18,代碼來源:ensureModel.ts

示例4: setIn

export function setIn(obj: any, path: string, value: any): any {
  let res: any = {};
  let resVal: any = res;
  let i = 0;
  let pathArray = toPath(path);

  for (; i < pathArray.length - 1; i++) {
    const currentPath: string = pathArray[i];
    let currentObj: any = getIn(obj, pathArray.slice(0, i + 1));

    if (resVal[currentPath]) {
      resVal = resVal[currentPath];
    } else if (currentObj) {
      resVal = resVal[currentPath] = cloneDeep(currentObj);
    } else {
      const nextPath: string = pathArray[i + 1];
      resVal = resVal[currentPath] =
        isInteger(nextPath) && Number(nextPath) >= 0 ? [] : {};
    }
  }

  resVal[pathArray[i]] = value;
  return { ...obj, ...res };
}
開發者ID:kurienkoa,項目名稱:formik,代碼行數:24,代碼來源:utils.ts


注:本文中的lodash.clonedeep類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。