本文整理匯總了TypeScript中es6-shim.Object.assign方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Object.assign方法的具體用法?TypeScript Object.assign怎麽用?TypeScript Object.assign使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類es6-shim.Object
的用法示例。
在下文中一共展示了Object.assign方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: switch
const copyFileAndShowSummary = (state: AppState = initialState, action: any) => {
switch (action.type) {
case types.COPY_FILE_CONTENTS:
let copy_action: CopyFileContents = action;
return ES6.Object.assign({}, state, {
fileNameOrErrorMessage: copy_action.fileName,
text: copy_action.contents
})
case types.REJECT_FILE:
let reject_action: RejectFile = action;
return ES6.Object.assign({}, state, {
fileNameOrErrorMessage: reject_action.errorMessage
})
case types.SHOW_TEXT_SUMMARY:
let summarize_action: ShowTextSummary = action;
let line_number = summarize_action.text.split('\n').length;
if (summarize_action.text === "") {
line_number = 0
}
let char_and_space_count = summarize_action.text.length;
// convert [\r\n\t\s]+ to spaces
let text = summarize_action.text.replace(/[\r\n\t\s]+/g, " ").trim();
let word_count = text.split(" ").length;
if (text === "") {
word_count = 0
}
// remove spaces
text = text.replace(/ /g, "");
let char_count = text.length;
return ES6.Object.assign({}, state, {
text: summarize_action.text,
summary: {
character_count: char_count,
character_and_space_count: char_and_space_count,
word_count: word_count,
line_number: line_number
}
})
default:
return state
}
}
示例2:
const changeColor = (state, action) =>
ES6.Object.assign({}, state, { color: action.color });
示例3:
export const changeShape = (state, action) => {
var shape = ES6.Object.assign({}, state.shapes.filter(x => x.id === action.id)[0],
{ top: action.top, left: action.left });
return ES6.Object.assign({}, state, { shapes: [...state.shapes.filter(x => x.id !== action.id), shape] });
};