本文整理汇总了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"),