本文整理匯總了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;
}
示例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
})
)
);
})
);
})
示例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
}
}
示例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
}
}
示例5: objectPathGet
export function objectPathGet(object: any, propPath: string, defaultValue?: any): any {
return objectPath.get(object, propPath, defaultValue);
}
示例6:
getKey: action => objectPath.get(action, "payload.serverId"),