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


TypeScript object-path.get函數代碼示例

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


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

示例1: storageGet

export function storageGet(key: string, paths: string[], defaultValue: any = null): any {
    if (paths.length === 0)
        throwError( "storageSet(): paths.length===0 для key='" + key + "'");
    if (paths.length > 3)
        throwError( "storageSet(): paths.length>3 для key='" + key + "'");


    for (let i = 0; i < 2; i++) {
        let fullKey = "<user>:" + key;
        if (i === 0)
            fullKey = appState.userId + ":" + key;

        let objStr = localStorage.getItem(fullKey);

        if (objStr) {
            let obj = XJSON_parse(objStr);
            if (paths[2]) {
                let value = objectPath.get(obj, paths[0] + "." + paths[1] + "." + paths[2], null);
                if (value) return value;
            }
            if (paths[1]) {
                let value = objectPath.get(obj, paths[0] + "." + paths[1], null);
                if (value) return value;
            }
            let value = objectPath.get(obj, paths[0], null);
            if (value) return value;

        }
    }

    return defaultValue;
}
開發者ID:KostiaSA,項目名稱:BuhtaClient2019,代碼行數:32,代碼來源:storageGet.ts

示例2: mergeMap

    mergeMap(({ payload: { serverId, kernelName } }) => {
      const configPath = [
        "entities",
        "serversById",
        serverId,
        "server",
        "config"
      ];
      const config = objectPath.get(state$.value, configPath);
      return kernels.start(config, kernelName, "").pipe(
        mergeMap(data => {
          const session = uuid();
          const kernel = Object.assign({}, data.response, {
            channel: kernels.connect(
              config,
              data.response.id,
              session
            )
          });

          kernel.channel.next(kernelInfoRequest());

          return merge(
            of(
              actions.activateKernelFulfilled({
                serverId,
                kernelName,
                kernel
              })
            )
          );
        })
      );
    })
開發者ID:nteract,項目名稱:play,代碼行數:34,代碼來源:epics.ts

示例3: formReducer

export default function formReducer(state = {}, action: any): FormState {
  switch (action.type) {
    case VALUE:
      return immutable.set(state, action.payload.path, action.payload.value)

    case VALIDATION_ERROR:
      // if error already exists at path, dont overwrite it
      return objectPath.get(state, ['errors', action.payload.path])
        ? state
        : immutable.set(state, ['errors', action.payload.path], action.payload.error)

    case CLEAR_VALIDATION_ERROR:
      const newState = immutable.del(state, ['errors', action.payload.path])

      // delete errors key from state if empty array
      if (newState.errors && Object.keys(newState.errors).length === 0) {
        delete newState.errors
      }

      return newState

    case SET_STATE:
      return { ...state, ...action.payload }

    case INIT_STATE:
      return action.payload

    default:
      return state
  }
}
開發者ID:jschr,項目名稱:react-redux-local-form,代碼行數:31,代碼來源:formReducer.ts

示例4: runValidator

    async function runValidator(validator: Validator): Promise<boolean> {
      const formState = getFormState()
      const value = objectPath.get(formState, validator.path)

      try {
        await validator.fn(value, formState, validator.path)
        dispatch(actions.clearValidationError(validator.path))
        return true
      } catch (err) {
        dispatch(actions.setValidationError(validator.path, err))
        return false
      }
    }
開發者ID:jschr,項目名稱:react-redux-local-form,代碼行數:13,代碼來源:formEnhancer.ts

示例5: objectPathGet

export function objectPathGet(object: any, propPath: string, defaultValue?: any): any {
    return objectPath.get(object, propPath, defaultValue);
}
開發者ID:KostiaSA,項目名稱:BuhtaClient2019,代碼行數:3,代碼來源:objectPathGet.ts

示例6:

 getKey: action => objectPath.get(action, "payload.serverId"),
開發者ID:nteract,項目名稱:play,代碼行數:1,代碼來源:reducer.ts


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