本文整理汇总了TypeScript中ramda.clone函数的典型用法代码示例。如果您正苦于以下问题:TypeScript clone函数的具体用法?TypeScript clone怎么用?TypeScript clone使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了clone函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: rowGenerator
export function rowGenerator(state: State, table: string, schema: RelationTree): Route[] {
let history: History = R.clone(state.history || []);
if (history.length >= state.options.relationLimit) {
return [];
}
let last = R.last(history);
let relation = schema[table].relations[last && last['table']];
let identifier = `${schema[table].model}_id`;
if (relation) {
history.push({
type: 'row',
table: table,
model: schema[table].model
});
}
else {
history[0] = {
type: 'row',
table: table,
model: schema[table].model,
identifier: identifier
};
}
let identifierString = state.options.idFormat === 'colons' ?
`:${identifier}` : `{${identifier}}`;
let newPath = relation ?
`${state.path}/${schema[table].model}` : `${state.path}/${identifierString}`;
let newState = {
options: state.options,
path: newPath,
history: history
};
let tables = R.flatten(Object.keys(schema[table].relations).map((relation) => {
if (schema[table].relations[relation] === 'one') {
return rowGenerator(newState, relation, schema);
}
else {
return tableGenerator(newState, relation, schema);
}
}));
return R.concat(
scopes.row.methods.map((method) => {
return {
path: newPath,
method: method,
history: history
};
}),
tables
);
};
示例2: dialogReducer
export default function dialogReducer(
state: dialogReducerState = {
help_open: false,
settings_open: false,
add_project_open: false,
delete_file_open: false,
delete_project_open: false,
rename_file_open: false,
copy_file_open: false,
add_file_open: false,
add_test_open: false,
add_question_open: false,
reset_open: false,
archive_open: false
},
action: dialogAction) {
state = clone(state);
switch (action.type) {
case dialogActions.open:
state[action.payload] = true;
break;
case dialogActions.close:
state[action.payload] = false;
break;
case dialogActions.toggle:
state[action.payload] = !state[action.payload];
break;
}
return state;
}
示例3: pathGenerator
return pathGenerator(schema, options).map((route: HandleRoute) => {
let state = R.clone(route.history[route.history.length - 1]);
let model = sequelize.models[state.model];
let queryParser = sequelizeQueryParser(schema, model);
let queryGenerator = sequelizeQueryGenerator(sequelize, route.history);
route.query = function(context) {
// console.log(context);
context.query = queryParser(context.query || {});
context.method = route.method;
if (route.method === 'get') {
context.query.limit = context.query.limit || options.defaultLimit;
if (context.query.limit > options.maxItems) {
context.query.limit = options.maxItems;
}
}
let query = queryGenerator(context);
let base;
if (context.query.scope) {
base = sequelize.models[state.model].scope(context.query.scope);
}
else {
base = sequelize.models[state.model];
}
let f = base[methodMap[state.type][route.method]];
let fParams = [query];
if (R.contains(route.method, ['put', 'post', 'update'])) {
fParams.unshift(context.payload);
}
return f.apply(base, fParams).then((response) => {
if (route.method === 'put') {
let updated = response[1];
if (state.type === 'row') {
return updated.length === 0 ? null : updated[0];
}
else {
return updated;
}
}
if (route.method === 'delete') {
return {id: context.identifiers[state.identifier]};
}
else {
return response;
}
});
};
return route;
});
示例4: loadArgs
export function loadArgs(args: string[], defaults = DEFAULTS) {
let config = R.clone(defaults);
let argv = minimist(args, OPTIONS);
if (argv['config']) {
let file = argv['config'];
if (typeof file === 'string') config = loadFile(file, config);
}
let object: any = {};
object.client = {};
if (argv['client']) object.client.name = argv['client'];
if (argv['client-config']) {
let clientConfig = argv['client-config'];
if (typeof clientConfig === 'string') {
object.client.config = JSON.parse(clientConfig);
}
}
if (argv['journal-table']) object.client.journalTable = argv['journal-table'];
if (argv['directory']) object.files = {directory: argv['directory']};
if (argv['status']) object.command = 'status';
if (argv['migrations']) object.command = 'migrations';
if (argv['journal']) object.command = 'journal';
if (argv['create']) object.command = 'create';
if (argv['apply']) object.command = 'apply';
if (argv['revert']) object.command = 'revert';
if (argv['help']) object.command = 'help';
if (argv['version']) object.command = 'version';
let command: any = {};
object.commands = {[object.command]: command};
if (argv['id']) command.id = argv['id'];
if (argv['long']) command.long = true;
if (argv['combined']) command.split = false;
if (argv['split']) command.split = true;
command.templatePaths = {};
if (argv['template']) command.templatePaths.combined = argv['template'];
if (argv['up-template']) command.templatePaths.up = argv['up-template'];
if (argv['down-template']) command.templatePaths.down = argv['down-template'];
if (argv['all']) command.method = 'all';
if (argv['each']) command.method = 'each';
if (argv['dry']) command.method = 'dry';
if (argv['pending']) command.pending = true;
if (argv['to']) command.to = argv['to'];
if (argv['number']) command.number = argv['number'];
if (argv['_'].length) command.name = argv['_'].join('-');
return loadObject(object, config);
}
示例5: constructors
function constructors(state = [], action): Array<Constructor> {
// CREATE A NEW TEST CONTROLER
let newConstructorcopy = Array.from(state);
switch (action.type) {
case constants.CREATE_NEW_CONSTRUCTOR:
newConstructorcopy.push(R.merge(action.elements, {
browsers: R.clone(getState("browsersSelect"))
}));
return newConstructorcopy;
default:
return state;
}
}
示例6: browsersSelect
function browsersSelect(
state: BrowsersDef = Object.freeze(initialState.browsersSelect),
action: {
type: string,
payload: {
id?: string,
value?: string,
browser?: string
}
}): BrowsersDef {
// MANAGE THE BROWSERS ICONS
let browsersSelectCopy: BrowsersDef;
switch (action.type) {
case constants.SET_BROWSERS_FOR_TESTS:
/*
* CHANGE THE ASPECT FILTER AND STATE FOR BROWSERS ITEMS
*/
browsersSelectCopy = R.clone(state);
browsersSelectCopy[action.payload.browser] = !browsersSelectCopy[action.payload.browser];
return browsersSelectCopy;
case constants.CONSTRUCTOR_FLOAT_CLOSE:
/*
* WHEN THE CONSTRUCTOR FLOAT IS CLOSED DESTROY THE GHOST CONTRUCTOR
*/
// return the init model state
return initialState.browsersSelect;
default:
return state;
}
}
示例7: tableGenerator
export function tableGenerator(state: State, table: string, schema: RelationTree): Route[] {
let history = R.clone(state.history || []);
if (history.length >= state.options.relationLimit || (state.path || '').indexOf(table) !== -1) {
return [];
}
else {
let useRoot = history.length > 0 ? 'methods' : 'rootMethods';
history.push({
type: 'table',
table: table,
model: schema[table].model
});
let newPath = `${state.path || state.options.prefix}/${table}`;
let newState = {
options: state.options,
path: newPath,
history: history
};
let rows = rowGenerator(newState, table, schema);
return R.concat(
scopes.table[useRoot].map((method: string) => {
return {
path: newPath,
method: method,
history: history
};
}),
rows
);
}
};
示例8: loadObject
export function loadObject(object: any, defaults = DEFAULTS): Config {
let config = R.clone(defaults);
if (object.hasOwnProperty('client')) {
let client = object.client;
ConfigTypeError.assert('client', 'object', client);
setKey(config.client, ['client', 'name'], 'string', client);
setKey(config.client, ['client', 'config'], 'object', client);
setKey(config.client, ['client', 'journalTable'], 'string', client);
}
if (object.hasOwnProperty('files')) {
ConfigTypeError.assert('files', 'object', object.files);
setKey(config.files, ['files', 'directory'], 'string', object.files);
}
setEnumKey(config, ['command'], Command, object);
if (object.hasOwnProperty('commands')) {
let commands = object.commands;
ConfigTypeError.assert('commands', 'object', commands);
if (commands.hasOwnProperty('migrations')) {
let migrations = commands.migrations;
ConfigTypeError.assert('commands.migrations', 'object', migrations);
setKey(
config.commands.migrations,
['commands', 'migrations', 'long'],
'boolean',
migrations
);
setKey(
config.commands.migrations,
['commands', 'migrations', 'id'],
'string',
migrations
);
}
if (commands.hasOwnProperty('status')) {
let status = commands.status;
ConfigTypeError.assert('commands.status', 'object', status);
setKey(
config.commands.status,
['commands', 'status', 'id'],
'string',
status
);
}
if (commands.hasOwnProperty('journal')) {
let journal = commands.journal;
ConfigTypeError.assert('commands.journal', 'object', journal);
setKey(
config.commands.journal,
['commands', 'journal', 'id'],
'string',
journal
);
}
if (commands.hasOwnProperty('create')) {
let create = commands.create;
ConfigTypeError.assert('commands.create', 'object', create);
setKey(
config.commands.create,
['commands', 'create', 'generateID'],
'function',
create
);
setKey(
config.commands.create,
['commands', 'create', 'split'],
'boolean',
create
);
setKey(
config.commands.create,
['commands', 'create', 'name'],
'string',
create
);
if (create.hasOwnProperty('templatePaths')) {
let templatePaths = create.templatePaths;
ConfigTypeError.assert('commands.create.templatePaths', 'object', templatePaths);
setKey(
config.commands.create.templatePaths,
['commands', 'create', 'templatePaths', 'combined'],
'string',
templatePaths
);
setKey(
//.........这里部分代码省略.........
示例9: queryGenerator
module.exports = R.curry(function queryGenerator(sequelize, pathHistory, context) {
let history = R.clone(pathHistory);
return generator(sequelize, history, context);
});