repo
stringlengths 5
67
| path
stringlengths 4
116
| func_name
stringlengths 0
58
| original_string
stringlengths 52
373k
| language
stringclasses 1
value | code
stringlengths 52
373k
| code_tokens
sequence | docstring
stringlengths 4
11.8k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 86
226
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
linzjs/linz | lib/api/formtools/list.js | getActiveFilters | function getActiveFilters (req, selectedFilters, data, modelName, cb) {
if (!req) {
throw new Error('req is required.');
}
if (!selectedFilters || !Array.isArray(selectedFilters) || !selectedFilters.length) {
throw new Error('selectedFilters is required and must be of type Array and cannot be empty.');
}
if (typeof modelName !== 'string' || !modelName.length) {
throw new Error('modelName is required and must be of type String and cannot be empty.');
}
if (!(!Object.is(data, null) && !Array.isArray(data) && data === Object(data))) {
throw new Error('data is required and must be of type Object.');
}
linz.api.model.list(req, modelName, function (err, list) {
if (err) {
return cb(err);
}
if (!Object.keys(list.filters).length) {
return cb(null);
}
var activeFilters = {};
async.each(selectedFilters, function (fieldName, filtersDone) {
// call the filter binder to render active filter form controls with form value added
list.filters[fieldName].filter.bind(fieldName, data, function (filterErr, result) {
if (filterErr) {
return filtersDone(filterErr);
}
activeFilters[fieldName] = {
label: list.filters[fieldName].label,
controls: result
}
return filtersDone(null);
});
}, function (filterErr) {
return cb(filterErr, activeFilters);
});
});
} | javascript | function getActiveFilters (req, selectedFilters, data, modelName, cb) {
if (!req) {
throw new Error('req is required.');
}
if (!selectedFilters || !Array.isArray(selectedFilters) || !selectedFilters.length) {
throw new Error('selectedFilters is required and must be of type Array and cannot be empty.');
}
if (typeof modelName !== 'string' || !modelName.length) {
throw new Error('modelName is required and must be of type String and cannot be empty.');
}
if (!(!Object.is(data, null) && !Array.isArray(data) && data === Object(data))) {
throw new Error('data is required and must be of type Object.');
}
linz.api.model.list(req, modelName, function (err, list) {
if (err) {
return cb(err);
}
if (!Object.keys(list.filters).length) {
return cb(null);
}
var activeFilters = {};
async.each(selectedFilters, function (fieldName, filtersDone) {
// call the filter binder to render active filter form controls with form value added
list.filters[fieldName].filter.bind(fieldName, data, function (filterErr, result) {
if (filterErr) {
return filtersDone(filterErr);
}
activeFilters[fieldName] = {
label: list.filters[fieldName].label,
controls: result
}
return filtersDone(null);
});
}, function (filterErr) {
return cb(filterErr, activeFilters);
});
});
} | [
"function",
"getActiveFilters",
"(",
"req",
",",
"selectedFilters",
",",
"data",
",",
"modelName",
",",
"cb",
")",
"{",
"if",
"(",
"!",
"req",
")",
"{",
"throw",
"new",
"Error",
"(",
"'req is required.'",
")",
";",
"}",
"if",
"(",
"!",
"selectedFilters",
"||",
"!",
"Array",
".",
"isArray",
"(",
"selectedFilters",
")",
"||",
"!",
"selectedFilters",
".",
"length",
")",
"{",
"throw",
"new",
"Error",
"(",
"'selectedFilters is required and must be of type Array and cannot be empty.'",
")",
";",
"}",
"if",
"(",
"typeof",
"modelName",
"!==",
"'string'",
"||",
"!",
"modelName",
".",
"length",
")",
"{",
"throw",
"new",
"Error",
"(",
"'modelName is required and must be of type String and cannot be empty.'",
")",
";",
"}",
"if",
"(",
"!",
"(",
"!",
"Object",
".",
"is",
"(",
"data",
",",
"null",
")",
"&&",
"!",
"Array",
".",
"isArray",
"(",
"data",
")",
"&&",
"data",
"===",
"Object",
"(",
"data",
")",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"'data is required and must be of type Object.'",
")",
";",
"}",
"linz",
".",
"api",
".",
"model",
".",
"list",
"(",
"req",
",",
"modelName",
",",
"function",
"(",
"err",
",",
"list",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"cb",
"(",
"err",
")",
";",
"}",
"if",
"(",
"!",
"Object",
".",
"keys",
"(",
"list",
".",
"filters",
")",
".",
"length",
")",
"{",
"return",
"cb",
"(",
"null",
")",
";",
"}",
"var",
"activeFilters",
"=",
"{",
"}",
";",
"async",
".",
"each",
"(",
"selectedFilters",
",",
"function",
"(",
"fieldName",
",",
"filtersDone",
")",
"{",
"list",
".",
"filters",
"[",
"fieldName",
"]",
".",
"filter",
".",
"bind",
"(",
"fieldName",
",",
"data",
",",
"function",
"(",
"filterErr",
",",
"result",
")",
"{",
"if",
"(",
"filterErr",
")",
"{",
"return",
"filtersDone",
"(",
"filterErr",
")",
";",
"}",
"activeFilters",
"[",
"fieldName",
"]",
"=",
"{",
"label",
":",
"list",
".",
"filters",
"[",
"fieldName",
"]",
".",
"label",
",",
"controls",
":",
"result",
"}",
"return",
"filtersDone",
"(",
"null",
")",
";",
"}",
")",
";",
"}",
",",
"function",
"(",
"filterErr",
")",
"{",
"return",
"cb",
"(",
"filterErr",
",",
"activeFilters",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Get active filters from form post data
@param {Array} selectedFilters An array of selected filter field names
@param {Object} data Form data
@param {String} modelName Name of model
@param {Function} cb Callback function
@return {Object} or undefined
@api public | [
"Get",
"active",
"filters",
"from",
"form",
"post",
"data"
] | 0ac03e722747406d29f9e1eed7e96b6be04456e8 | https://github.com/linzjs/linz/blob/0ac03e722747406d29f9e1eed7e96b6be04456e8/lib/api/formtools/list.js#L197-L253 | train |
linzjs/linz | lib/formtools/overview.js | setTabId | function setTabId (sections) {
sections.forEach(function (section, sectionIndex) {
if (!Array.isArray(section)) {
return;
}
section.forEach(function (tab, tabIndex) {
// Replace white space from tab.label with "-", make it lowercase and add the index number at the end.
// sectionIndex and tabIndex number are added at the end to make the tabID unique in case when more then one tab have the same label (title)
tab.tabId = (tab.label).replace(/\s+/g, '-').toLowerCase() + '-' + sectionIndex + '-' + tabIndex;
});
});
} | javascript | function setTabId (sections) {
sections.forEach(function (section, sectionIndex) {
if (!Array.isArray(section)) {
return;
}
section.forEach(function (tab, tabIndex) {
// Replace white space from tab.label with "-", make it lowercase and add the index number at the end.
// sectionIndex and tabIndex number are added at the end to make the tabID unique in case when more then one tab have the same label (title)
tab.tabId = (tab.label).replace(/\s+/g, '-').toLowerCase() + '-' + sectionIndex + '-' + tabIndex;
});
});
} | [
"function",
"setTabId",
"(",
"sections",
")",
"{",
"sections",
".",
"forEach",
"(",
"function",
"(",
"section",
",",
"sectionIndex",
")",
"{",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"section",
")",
")",
"{",
"return",
";",
"}",
"section",
".",
"forEach",
"(",
"function",
"(",
"tab",
",",
"tabIndex",
")",
"{",
"tab",
".",
"tabId",
"=",
"(",
"tab",
".",
"label",
")",
".",
"replace",
"(",
"/",
"\\s+",
"/",
"g",
",",
"'-'",
")",
".",
"toLowerCase",
"(",
")",
"+",
"'-'",
"+",
"sectionIndex",
"+",
"'-'",
"+",
"tabIndex",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Set unique tabId to each tab in overview.body
@param {Array} sections overview body array | [
"Set",
"unique",
"tabId",
"to",
"each",
"tab",
"in",
"overview",
".",
"body"
] | 0ac03e722747406d29f9e1eed7e96b6be04456e8 | https://github.com/linzjs/linz/blob/0ac03e722747406d29f9e1eed7e96b6be04456e8/lib/formtools/overview.js#L10-L28 | train |
linzjs/linz | lib/formtools/overview.js | renderCell | function renderCell (record, field, model, cb) {
let fieldName = (typeof field === 'object') ? field.fieldName : field,
renderer = (model.schema.tree[fieldName] && model.schema.tree[fieldName].ref && linz.api.model.getObjectIdFromRefField(record[fieldName]) instanceof linz.mongoose.Types.ObjectId) ?
'reference' :
(record[fieldName] && linz.api.model.getObjectIdFromRefField(record[fieldName]) instanceof linz.mongoose.Types.ObjectId && linz.mongoose.models[record[fieldName].ref]) ? 'referenceValue' :
'text';
// Users can supply their own renderer fields (use it if provided).
(field.renderer || cellRenderers[renderer])(record[fieldName], record, fieldName, model, function (err, value) {
if (err) {
return cb(err);
}
return cb(null, {
label: field.label ? field.label : model.linz.formtools.labels[fieldName],
value: value
});
});
} | javascript | function renderCell (record, field, model, cb) {
let fieldName = (typeof field === 'object') ? field.fieldName : field,
renderer = (model.schema.tree[fieldName] && model.schema.tree[fieldName].ref && linz.api.model.getObjectIdFromRefField(record[fieldName]) instanceof linz.mongoose.Types.ObjectId) ?
'reference' :
(record[fieldName] && linz.api.model.getObjectIdFromRefField(record[fieldName]) instanceof linz.mongoose.Types.ObjectId && linz.mongoose.models[record[fieldName].ref]) ? 'referenceValue' :
'text';
// Users can supply their own renderer fields (use it if provided).
(field.renderer || cellRenderers[renderer])(record[fieldName], record, fieldName, model, function (err, value) {
if (err) {
return cb(err);
}
return cb(null, {
label: field.label ? field.label : model.linz.formtools.labels[fieldName],
value: value
});
});
} | [
"function",
"renderCell",
"(",
"record",
",",
"field",
",",
"model",
",",
"cb",
")",
"{",
"let",
"fieldName",
"=",
"(",
"typeof",
"field",
"===",
"'object'",
")",
"?",
"field",
".",
"fieldName",
":",
"field",
",",
"renderer",
"=",
"(",
"model",
".",
"schema",
".",
"tree",
"[",
"fieldName",
"]",
"&&",
"model",
".",
"schema",
".",
"tree",
"[",
"fieldName",
"]",
".",
"ref",
"&&",
"linz",
".",
"api",
".",
"model",
".",
"getObjectIdFromRefField",
"(",
"record",
"[",
"fieldName",
"]",
")",
"instanceof",
"linz",
".",
"mongoose",
".",
"Types",
".",
"ObjectId",
")",
"?",
"'reference'",
":",
"(",
"record",
"[",
"fieldName",
"]",
"&&",
"linz",
".",
"api",
".",
"model",
".",
"getObjectIdFromRefField",
"(",
"record",
"[",
"fieldName",
"]",
")",
"instanceof",
"linz",
".",
"mongoose",
".",
"Types",
".",
"ObjectId",
"&&",
"linz",
".",
"mongoose",
".",
"models",
"[",
"record",
"[",
"fieldName",
"]",
".",
"ref",
"]",
")",
"?",
"'referenceValue'",
":",
"'text'",
";",
"(",
"field",
".",
"renderer",
"||",
"cellRenderers",
"[",
"renderer",
"]",
")",
"(",
"record",
"[",
"fieldName",
"]",
",",
"record",
",",
"fieldName",
",",
"model",
",",
"function",
"(",
"err",
",",
"value",
")",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"cb",
"(",
"err",
")",
";",
"}",
"return",
"cb",
"(",
"null",
",",
"{",
"label",
":",
"field",
".",
"label",
"?",
"field",
".",
"label",
":",
"model",
".",
"linz",
".",
"formtools",
".",
"labels",
"[",
"fieldName",
"]",
",",
"value",
":",
"value",
"}",
")",
";",
"}",
")",
";",
"}"
] | Return the rendered value of field.
@param {Object} record Overview record object
@param {Object or String} Field name or Object containing field name and field label
@param {Obect} model Model object
@param {Function} cb Callback function
@return {Object} Return object: { label: '', value: '' } | [
"Return",
"the",
"rendered",
"value",
"of",
"field",
"."
] | 0ac03e722747406d29f9e1eed7e96b6be04456e8 | https://github.com/linzjs/linz/blob/0ac03e722747406d29f9e1eed7e96b6be04456e8/lib/formtools/overview.js#L38-L60 | train |
linzjs/linz | public/js/documentarray.js | getOffset | function getOffset(offset) {
var symbol = offset.charAt(0);
var time = offset.substring(1).split(':');
var hours = Number.parseInt(time[0], 10) * 60;
var minutes = Number.parseInt(time[1], 10);
var total = Number.parseInt(symbol + (hours + minutes));
return total;
} | javascript | function getOffset(offset) {
var symbol = offset.charAt(0);
var time = offset.substring(1).split(':');
var hours = Number.parseInt(time[0], 10) * 60;
var minutes = Number.parseInt(time[1], 10);
var total = Number.parseInt(symbol + (hours + minutes));
return total;
} | [
"function",
"getOffset",
"(",
"offset",
")",
"{",
"var",
"symbol",
"=",
"offset",
".",
"charAt",
"(",
"0",
")",
";",
"var",
"time",
"=",
"offset",
".",
"substring",
"(",
"1",
")",
".",
"split",
"(",
"':'",
")",
";",
"var",
"hours",
"=",
"Number",
".",
"parseInt",
"(",
"time",
"[",
"0",
"]",
",",
"10",
")",
"*",
"60",
";",
"var",
"minutes",
"=",
"Number",
".",
"parseInt",
"(",
"time",
"[",
"1",
"]",
",",
"10",
")",
";",
"var",
"total",
"=",
"Number",
".",
"parseInt",
"(",
"symbol",
"+",
"(",
"hours",
"+",
"minutes",
")",
")",
";",
"return",
"total",
";",
"}"
] | Get the offsets as an integer | [
"Get",
"the",
"offsets",
"as",
"an",
"integer"
] | 0ac03e722747406d29f9e1eed7e96b6be04456e8 | https://github.com/linzjs/linz/blob/0ac03e722747406d29f9e1eed7e96b6be04456e8/public/js/documentarray.js#L320-L330 | train |
Yodata/yodata | packages/client/lib/get-options.js | getConfig | function getConfig(options) {
const profileOptions = {
baseUrl: get('pod.url'),
headers: {
'user-agent': `yodata/client (https://yodata.io)`,
'x-api-key': get('pod.secret')
},
hooks: {
beforeRequest: [
logRequest
],
afterResponse: [
parseResponseData
]
}
}
return defaults(options, profileOptions)
} | javascript | function getConfig(options) {
const profileOptions = {
baseUrl: get('pod.url'),
headers: {
'user-agent': `yodata/client (https://yodata.io)`,
'x-api-key': get('pod.secret')
},
hooks: {
beforeRequest: [
logRequest
],
afterResponse: [
parseResponseData
]
}
}
return defaults(options, profileOptions)
} | [
"function",
"getConfig",
"(",
"options",
")",
"{",
"const",
"profileOptions",
"=",
"{",
"baseUrl",
":",
"get",
"(",
"'pod.url'",
")",
",",
"headers",
":",
"{",
"'user-agent'",
":",
"`",
"`",
",",
"'x-api-key'",
":",
"get",
"(",
"'pod.secret'",
")",
"}",
",",
"hooks",
":",
"{",
"beforeRequest",
":",
"[",
"logRequest",
"]",
",",
"afterResponse",
":",
"[",
"parseResponseData",
"]",
"}",
"}",
"return",
"defaults",
"(",
"options",
",",
"profileOptions",
")",
"}"
] | get client options from currentProfile or default
@param {object} [options]
@param {string} [options.baseurl]
@param {object} [options.headers]
@returns {object} | [
"get",
"client",
"options",
"from",
"currentProfile",
"or",
"default"
] | d7aedd03e49ce5da6e45ab821f54b16d4d4409df | https://github.com/Yodata/yodata/blob/d7aedd03e49ce5da6e45ab821f54b16d4d4409df/packages/client/lib/get-options.js#L15-L32 | train |
linzjs/linz | lib/formtools/renderers-action-record.js | defaultRenderer | function defaultRenderer (data, callback) {
linz.api.views.renderPartial('action-record', data, (err, html) => {
if (err) {
return callback(err);
}
return callback(null, html);
});
} | javascript | function defaultRenderer (data, callback) {
linz.api.views.renderPartial('action-record', data, (err, html) => {
if (err) {
return callback(err);
}
return callback(null, html);
});
} | [
"function",
"defaultRenderer",
"(",
"data",
",",
"callback",
")",
"{",
"linz",
".",
"api",
".",
"views",
".",
"renderPartial",
"(",
"'action-record'",
",",
"data",
",",
"(",
"err",
",",
"html",
")",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"callback",
"(",
"err",
")",
";",
"}",
"return",
"callback",
"(",
"null",
",",
"html",
")",
";",
"}",
")",
";",
"}"
] | Default record action renderer.
@param {Object} data Data passed to the template.
@param {Function} callback Callback function.
@return {String} Rendered HTML content. | [
"Default",
"record",
"action",
"renderer",
"."
] | 0ac03e722747406d29f9e1eed7e96b6be04456e8 | https://github.com/linzjs/linz/blob/0ac03e722747406d29f9e1eed7e96b6be04456e8/lib/formtools/renderers-action-record.js#L11-L23 | train |
Yodata/yodata | packages/transform/src/get-context.js | getContext | async function getContext(target, contextOptions) {
if (isURL(target)) {
const cdef = await got(target)
.then(response => {
const contentType = response.headers["content-type"]
switch (contentType) {
case 'application/x-yaml':
case 'application/x-yml':
return yaml.load(response.body)
case 'application/json':
case 'application/ld+json':
return JSON.parse(response.body)
default:
throw new Error(`context type not recognized ${contentType}`)
}
})
return new Context(cdef, contextOptions)
} else {
return loadContext(target, contextOptions)
}
} | javascript | async function getContext(target, contextOptions) {
if (isURL(target)) {
const cdef = await got(target)
.then(response => {
const contentType = response.headers["content-type"]
switch (contentType) {
case 'application/x-yaml':
case 'application/x-yml':
return yaml.load(response.body)
case 'application/json':
case 'application/ld+json':
return JSON.parse(response.body)
default:
throw new Error(`context type not recognized ${contentType}`)
}
})
return new Context(cdef, contextOptions)
} else {
return loadContext(target, contextOptions)
}
} | [
"async",
"function",
"getContext",
"(",
"target",
",",
"contextOptions",
")",
"{",
"if",
"(",
"isURL",
"(",
"target",
")",
")",
"{",
"const",
"cdef",
"=",
"await",
"got",
"(",
"target",
")",
".",
"then",
"(",
"response",
"=>",
"{",
"const",
"contentType",
"=",
"response",
".",
"headers",
"[",
"\"content-type\"",
"]",
"switch",
"(",
"contentType",
")",
"{",
"case",
"'application/x-yaml'",
":",
"case",
"'application/x-yml'",
":",
"return",
"yaml",
".",
"load",
"(",
"response",
".",
"body",
")",
"case",
"'application/json'",
":",
"case",
"'application/ld+json'",
":",
"return",
"JSON",
".",
"parse",
"(",
"response",
".",
"body",
")",
"default",
":",
"throw",
"new",
"Error",
"(",
"`",
"${",
"contentType",
"}",
"`",
")",
"}",
"}",
")",
"return",
"new",
"Context",
"(",
"cdef",
",",
"contextOptions",
")",
"}",
"else",
"{",
"return",
"loadContext",
"(",
"target",
",",
"contextOptions",
")",
"}",
"}"
] | fetch and parse context from a file or http url
@param {string} target
@param {object} [contextOptions]
@returns {Promise} | [
"fetch",
"and",
"parse",
"context",
"from",
"a",
"file",
"or",
"http",
"url"
] | d7aedd03e49ce5da6e45ab821f54b16d4d4409df | https://github.com/Yodata/yodata/blob/d7aedd03e49ce5da6e45ab821f54b16d4d4409df/packages/transform/src/get-context.js#L18-L38 | train |
linzjs/linz | lib/api/model.js | form | function form (req, modelName, callback, formDsl) {
const formFn = () => new Promise((resolve, reject) => {
const formLabels = labels(modelName);
const schema = get(modelName, true).schema;
if (formDsl && typeof formDsl === 'function') {
return resolve(pluginHelpers.formSettings(req, schema, clone(formDsl()), formLabels));
}
if (formDsl) {
return resolve(pluginHelpers.formSettings(req, schema, clone(formDsl), formLabels));
}
// Get the form
get(modelName, true).getForm(req, (err, decoratedForm) => {
if (err) {
return reject(err);
}
return resolve(decoratedForm);
});
});
formFn()
.then((result) => callback(null, result))
.catch(callback);
} | javascript | function form (req, modelName, callback, formDsl) {
const formFn = () => new Promise((resolve, reject) => {
const formLabels = labels(modelName);
const schema = get(modelName, true).schema;
if (formDsl && typeof formDsl === 'function') {
return resolve(pluginHelpers.formSettings(req, schema, clone(formDsl()), formLabels));
}
if (formDsl) {
return resolve(pluginHelpers.formSettings(req, schema, clone(formDsl), formLabels));
}
// Get the form
get(modelName, true).getForm(req, (err, decoratedForm) => {
if (err) {
return reject(err);
}
return resolve(decoratedForm);
});
});
formFn()
.then((result) => callback(null, result))
.catch(callback);
} | [
"function",
"form",
"(",
"req",
",",
"modelName",
",",
"callback",
",",
"formDsl",
")",
"{",
"const",
"formFn",
"=",
"(",
")",
"=>",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"const",
"formLabels",
"=",
"labels",
"(",
"modelName",
")",
";",
"const",
"schema",
"=",
"get",
"(",
"modelName",
",",
"true",
")",
".",
"schema",
";",
"if",
"(",
"formDsl",
"&&",
"typeof",
"formDsl",
"===",
"'function'",
")",
"{",
"return",
"resolve",
"(",
"pluginHelpers",
".",
"formSettings",
"(",
"req",
",",
"schema",
",",
"clone",
"(",
"formDsl",
"(",
")",
")",
",",
"formLabels",
")",
")",
";",
"}",
"if",
"(",
"formDsl",
")",
"{",
"return",
"resolve",
"(",
"pluginHelpers",
".",
"formSettings",
"(",
"req",
",",
"schema",
",",
"clone",
"(",
"formDsl",
")",
",",
"formLabels",
")",
")",
";",
"}",
"get",
"(",
"modelName",
",",
"true",
")",
".",
"getForm",
"(",
"req",
",",
"(",
"err",
",",
"decoratedForm",
")",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"reject",
"(",
"err",
")",
";",
"}",
"return",
"resolve",
"(",
"decoratedForm",
")",
";",
"}",
")",
";",
"}",
")",
";",
"formFn",
"(",
")",
".",
"then",
"(",
"(",
"result",
")",
"=>",
"callback",
"(",
"null",
",",
"result",
")",
")",
".",
"catch",
"(",
"callback",
")",
";",
"}"
] | Retrieve the form DSL for a model
@param {Object} req A HTTP request object which can be used to customised the form
@param {String} modelName The name of the model
@param {Function} callback A callback to return the form DSL to
@return {Void} | [
"Retrieve",
"the",
"form",
"DSL",
"for",
"a",
"model"
] | 0ac03e722747406d29f9e1eed7e96b6be04456e8 | https://github.com/linzjs/linz/blob/0ac03e722747406d29f9e1eed7e96b6be04456e8/lib/api/model.js#L50-L82 | train |
linzjs/linz | lib/api/model.js | formAsPromise | function formAsPromise (req, modelName, formDsl) {
return new Promise((resolve, reject) => {
form(req, modelName, (err, decoratedForm) => {
if (err) {
return reject(err);
}
return resolve(decoratedForm);
}, formDsl);
});
} | javascript | function formAsPromise (req, modelName, formDsl) {
return new Promise((resolve, reject) => {
form(req, modelName, (err, decoratedForm) => {
if (err) {
return reject(err);
}
return resolve(decoratedForm);
}, formDsl);
});
} | [
"function",
"formAsPromise",
"(",
"req",
",",
"modelName",
",",
"formDsl",
")",
"{",
"return",
"new",
"Promise",
"(",
"(",
"resolve",
",",
"reject",
")",
"=>",
"{",
"form",
"(",
"req",
",",
"modelName",
",",
"(",
"err",
",",
"decoratedForm",
")",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"reject",
"(",
"err",
")",
";",
"}",
"return",
"resolve",
"(",
"decoratedForm",
")",
";",
"}",
",",
"formDsl",
")",
";",
"}",
")",
";",
"}"
] | Promise version of `form`.
See `form`.
@param {Object} req A HTTP request object which can be used to customised the form
@param {String} modelName The name of the model
@return {Promise} A promise with the decorated form DSL. | [
"Promise",
"version",
"of",
"form",
".",
"See",
"form",
"."
] | 0ac03e722747406d29f9e1eed7e96b6be04456e8 | https://github.com/linzjs/linz/blob/0ac03e722747406d29f9e1eed7e96b6be04456e8/lib/api/model.js#L91-L107 | train |
linzjs/linz | lib/api/model.js | list | function list (req, modelName, callback) {
return get(modelName, true).getList(req, callback);
} | javascript | function list (req, modelName, callback) {
return get(modelName, true).getList(req, callback);
} | [
"function",
"list",
"(",
"req",
",",
"modelName",
",",
"callback",
")",
"{",
"return",
"get",
"(",
"modelName",
",",
"true",
")",
".",
"getList",
"(",
"req",
",",
"callback",
")",
";",
"}"
] | Retrieve the list DSL for a model
@param {Object} req A HTTP request object which can be used to customised the list
@param {String} modelName The name of the model
@param {Function} callback A callback to return the list DSL to
@return {Void} | [
"Retrieve",
"the",
"list",
"DSL",
"for",
"a",
"model"
] | 0ac03e722747406d29f9e1eed7e96b6be04456e8 | https://github.com/linzjs/linz/blob/0ac03e722747406d29f9e1eed7e96b6be04456e8/lib/api/model.js#L116-L118 | train |
linzjs/linz | lib/api/model.js | permissions | function permissions (user, modelName, callback) {
return get(modelName, true).getPermissions(user, callback);
} | javascript | function permissions (user, modelName, callback) {
return get(modelName, true).getPermissions(user, callback);
} | [
"function",
"permissions",
"(",
"user",
",",
"modelName",
",",
"callback",
")",
"{",
"return",
"get",
"(",
"modelName",
",",
"true",
")",
".",
"getPermissions",
"(",
"user",
",",
"callback",
")",
";",
"}"
] | Retrieve the permissions DSL for a model
@param {Object} user The user to which the permissions should be customised
@param {String} modelName The name of the model
@param {Function} callback A callback to return the permissions DSL to
@return {Void} | [
"Retrieve",
"the",
"permissions",
"DSL",
"for",
"a",
"model"
] | 0ac03e722747406d29f9e1eed7e96b6be04456e8 | https://github.com/linzjs/linz/blob/0ac03e722747406d29f9e1eed7e96b6be04456e8/lib/api/model.js#L137-L139 | train |
linzjs/linz | lib/api/model.js | overview | function overview (req, modelName, callback) {
return get(modelName, true).getOverview(req, callback);
} | javascript | function overview (req, modelName, callback) {
return get(modelName, true).getOverview(req, callback);
} | [
"function",
"overview",
"(",
"req",
",",
"modelName",
",",
"callback",
")",
"{",
"return",
"get",
"(",
"modelName",
",",
"true",
")",
".",
"getOverview",
"(",
"req",
",",
"callback",
")",
";",
"}"
] | Retrieve the overview DSL for a model
@param {Object} req A HTTP request object which can be used to customised the overview
@param {String} modelName The name of the model
@param {Function} callback A callback to return the overview DSL to
@return {Void} | [
"Retrieve",
"the",
"overview",
"DSL",
"for",
"a",
"model"
] | 0ac03e722747406d29f9e1eed7e96b6be04456e8 | https://github.com/linzjs/linz/blob/0ac03e722747406d29f9e1eed7e96b6be04456e8/lib/api/model.js#L148-L150 | train |
linzjs/linz | lib/api/model.js | labels | function labels (modelName, callback) {
if (callback) {
return get(modelName, true).getLabels(callback);
}
return get(modelName, true).getLabels();
} | javascript | function labels (modelName, callback) {
if (callback) {
return get(modelName, true).getLabels(callback);
}
return get(modelName, true).getLabels();
} | [
"function",
"labels",
"(",
"modelName",
",",
"callback",
")",
"{",
"if",
"(",
"callback",
")",
"{",
"return",
"get",
"(",
"modelName",
",",
"true",
")",
".",
"getLabels",
"(",
"callback",
")",
";",
"}",
"return",
"get",
"(",
"modelName",
",",
"true",
")",
".",
"getLabels",
"(",
")",
";",
"}"
] | Retrieve the labels for a model
@param {String} modelName The name of the model
@param {Function} callback An optional callback to return the labels object to
@return {Void} | [
"Retrieve",
"the",
"labels",
"for",
"a",
"model"
] | 0ac03e722747406d29f9e1eed7e96b6be04456e8 | https://github.com/linzjs/linz/blob/0ac03e722747406d29f9e1eed7e96b6be04456e8/lib/api/model.js#L158-L166 | train |
linzjs/linz | lib/api/model.js | titleField | function titleField (modelName, field, callback) {
// Make this a no-op unless the field being evaluated is `'title'`.
if (field !== 'title') {
return callback(null, field);
}
if (get(modelName, true).schema.paths[field]) {
return callback(null, field);
}
model(modelName, (err, opts) => {
if (err) {
return callback(err);
}
return callback(null, opts.title);
});
} | javascript | function titleField (modelName, field, callback) {
// Make this a no-op unless the field being evaluated is `'title'`.
if (field !== 'title') {
return callback(null, field);
}
if (get(modelName, true).schema.paths[field]) {
return callback(null, field);
}
model(modelName, (err, opts) => {
if (err) {
return callback(err);
}
return callback(null, opts.title);
});
} | [
"function",
"titleField",
"(",
"modelName",
",",
"field",
",",
"callback",
")",
"{",
"if",
"(",
"field",
"!==",
"'title'",
")",
"{",
"return",
"callback",
"(",
"null",
",",
"field",
")",
";",
"}",
"if",
"(",
"get",
"(",
"modelName",
",",
"true",
")",
".",
"schema",
".",
"paths",
"[",
"field",
"]",
")",
"{",
"return",
"callback",
"(",
"null",
",",
"field",
")",
";",
"}",
"model",
"(",
"modelName",
",",
"(",
"err",
",",
"opts",
")",
"=>",
"{",
"if",
"(",
"err",
")",
"{",
"return",
"callback",
"(",
"err",
")",
";",
"}",
"return",
"callback",
"(",
"null",
",",
"opts",
".",
"title",
")",
";",
"}",
")",
";",
"}"
] | Retrieve the title field for a model
@param {String} modelName The name of the model.
@param {String} field A field in the model.
@param {Function} callback A callback to provide the result to.
@return {Void} | [
"Retrieve",
"the",
"title",
"field",
"for",
"a",
"model"
] | 0ac03e722747406d29f9e1eed7e96b6be04456e8 | https://github.com/linzjs/linz/blob/0ac03e722747406d29f9e1eed7e96b6be04456e8/lib/api/model.js#L175-L196 | train |
Yodata/yodata | packages/transform/src/compile.js | compileContext | async function compileContext(target, contextOptions) {
const context = await getContext(target, contextOptions)
return async function (data/** @param {object} */) {
return context.map(data)
}
} | javascript | async function compileContext(target, contextOptions) {
const context = await getContext(target, contextOptions)
return async function (data/** @param {object} */) {
return context.map(data)
}
} | [
"async",
"function",
"compileContext",
"(",
"target",
",",
"contextOptions",
")",
"{",
"const",
"context",
"=",
"await",
"getContext",
"(",
"target",
",",
"contextOptions",
")",
"return",
"async",
"function",
"(",
"data",
")",
"{",
"return",
"context",
".",
"map",
"(",
"data",
")",
"}",
"}"
] | fetch a conext by path or url and return an async context.map helper function
@param {string} target
@param {object} [contextOptions]
@returns {Promise<function>} | [
"fetch",
"a",
"conext",
"by",
"path",
"or",
"url",
"and",
"return",
"an",
"async",
"context",
".",
"map",
"helper",
"function"
] | d7aedd03e49ce5da6e45ab821f54b16d4d4409df | https://github.com/Yodata/yodata/blob/d7aedd03e49ce5da6e45ab821f54b16d4d4409df/packages/transform/src/compile.js#L14-L20 | train |
Becklyn/kaba | lib/print-package-versions.js | getMaxPackageNameLength | function getMaxPackageNameLength (packages)
{
return Object
.keys(packages)
.reduce((max, name) => Math.max(max, name.length), 0);
} | javascript | function getMaxPackageNameLength (packages)
{
return Object
.keys(packages)
.reduce((max, name) => Math.max(max, name.length), 0);
} | [
"function",
"getMaxPackageNameLength",
"(",
"packages",
")",
"{",
"return",
"Object",
".",
"keys",
"(",
"packages",
")",
".",
"reduce",
"(",
"(",
"max",
",",
"name",
")",
"=>",
"Math",
".",
"max",
"(",
"max",
",",
"name",
".",
"length",
")",
",",
"0",
")",
";",
"}"
] | Returns the max package name length
@private
@param {Object.<string,string>} packages
@return {number} | [
"Returns",
"the",
"max",
"package",
"name",
"length"
] | 8862f48c576762d39536b29b674ae3d074a94b25 | https://github.com/Becklyn/kaba/blob/8862f48c576762d39536b29b674ae3d074a94b25/lib/print-package-versions.js#L11-L16 | train |
Becklyn/kaba | lib/print-package-versions.js | padding | function padding (packageName, maxLength)
{
const length = packageName.length;
return (length < maxLength)
? " ".repeat(maxLength - length)
: "";
} | javascript | function padding (packageName, maxLength)
{
const length = packageName.length;
return (length < maxLength)
? " ".repeat(maxLength - length)
: "";
} | [
"function",
"padding",
"(",
"packageName",
",",
"maxLength",
")",
"{",
"const",
"length",
"=",
"packageName",
".",
"length",
";",
"return",
"(",
"length",
"<",
"maxLength",
")",
"?",
"\" \"",
".",
"repeat",
"(",
"maxLength",
"-",
"length",
")",
":",
"\"\"",
";",
"}"
] | Returns the padding for the given
@private
@param {string} packageName
@param {number} maxLength
@return {string} | [
"Returns",
"the",
"padding",
"for",
"the",
"given"
] | 8862f48c576762d39536b29b674ae3d074a94b25 | https://github.com/Becklyn/kaba/blob/8862f48c576762d39536b29b674ae3d074a94b25/lib/print-package-versions.js#L28-L35 | train |
iadvize/health-check-library | javascript/pure/pure.js | createServer | function createServer(port, f) {
f = f || noop;
http.createServer(handler).listen(port, f);
return statusHelper.changeStatus;
} | javascript | function createServer(port, f) {
f = f || noop;
http.createServer(handler).listen(port, f);
return statusHelper.changeStatus;
} | [
"function",
"createServer",
"(",
"port",
",",
"f",
")",
"{",
"f",
"=",
"f",
"||",
"noop",
";",
"http",
".",
"createServer",
"(",
"handler",
")",
".",
"listen",
"(",
"port",
",",
"f",
")",
";",
"return",
"statusHelper",
".",
"changeStatus",
";",
"}"
] | Create an HTTP server that always yield 200 HTTP status code
@param {number} port
@param {function} [f] callback | [
"Create",
"an",
"HTTP",
"server",
"that",
"always",
"yield",
"200",
"HTTP",
"status",
"code"
] | a3751271be44b88b4a558b512e02bd082b93848d | https://github.com/iadvize/health-check-library/blob/a3751271be44b88b4a558b512e02bd082b93848d/javascript/pure/pure.js#L11-L15 | train |
Becklyn/kaba | bin/run.js | runKaba | function runKaba (opts, isVerbose)
{
try
{
const logger = new Logger(kleur.bgYellow.black(" kaba "));
logger.log("kaba started");
const start = process.hrtime();
const cliConfig = new CliConfig(opts);
/** @type {Kaba} kaba */
const kaba = require(`${process.cwd()}/kaba.js`);
const buildConfig = kaba.getBuildConfig(cliConfig);
const scss = new SassRunner(buildConfig, cliConfig);
const webpack = new WebpackRunner(buildConfig);
Promise.all([scss.run(), webpack.run()])
.then(
([scssOk, webpackOk]) =>
{
const failed = (false === scssOk || false === webpackOk);
const status = failed
? kleur.red("failed")
: kleur.green("succeeded");
logger.logWithDuration(`kaba ${status}`, process.hrtime(start));
process.exit(failed ? 1 : 0);
}
)
.catch(
(...args) => console.log("something broke", args)
);
if (cliConfig.isWatch())
{
const exitCallback = () => {
scss.stop();
webpack.stop();
};
process.on("exit", exitCallback);
process.on("SIGINT", exitCallback);
process.on("SIGUSR1", exitCallback);
process.on("SIGUSR2", exitCallback);
}
}
catch (e)
{
if (/cannot find module.*?kaba\.js/i.test(e.message))
{
console.log(`${kleur.red("Error")}: Could not find ${kleur.yellow("kaba.js")}`);
}
else
{
console.log(kleur.red(`Run Error: ${e.message}`));
}
if (isVerbose)
{
console.error(e);
}
process.exit(1);
}
} | javascript | function runKaba (opts, isVerbose)
{
try
{
const logger = new Logger(kleur.bgYellow.black(" kaba "));
logger.log("kaba started");
const start = process.hrtime();
const cliConfig = new CliConfig(opts);
/** @type {Kaba} kaba */
const kaba = require(`${process.cwd()}/kaba.js`);
const buildConfig = kaba.getBuildConfig(cliConfig);
const scss = new SassRunner(buildConfig, cliConfig);
const webpack = new WebpackRunner(buildConfig);
Promise.all([scss.run(), webpack.run()])
.then(
([scssOk, webpackOk]) =>
{
const failed = (false === scssOk || false === webpackOk);
const status = failed
? kleur.red("failed")
: kleur.green("succeeded");
logger.logWithDuration(`kaba ${status}`, process.hrtime(start));
process.exit(failed ? 1 : 0);
}
)
.catch(
(...args) => console.log("something broke", args)
);
if (cliConfig.isWatch())
{
const exitCallback = () => {
scss.stop();
webpack.stop();
};
process.on("exit", exitCallback);
process.on("SIGINT", exitCallback);
process.on("SIGUSR1", exitCallback);
process.on("SIGUSR2", exitCallback);
}
}
catch (e)
{
if (/cannot find module.*?kaba\.js/i.test(e.message))
{
console.log(`${kleur.red("Error")}: Could not find ${kleur.yellow("kaba.js")}`);
}
else
{
console.log(kleur.red(`Run Error: ${e.message}`));
}
if (isVerbose)
{
console.error(e);
}
process.exit(1);
}
} | [
"function",
"runKaba",
"(",
"opts",
",",
"isVerbose",
")",
"{",
"try",
"{",
"const",
"logger",
"=",
"new",
"Logger",
"(",
"kleur",
".",
"bgYellow",
".",
"black",
"(",
"\" kaba \"",
")",
")",
";",
"logger",
".",
"log",
"(",
"\"kaba started\"",
")",
";",
"const",
"start",
"=",
"process",
".",
"hrtime",
"(",
")",
";",
"const",
"cliConfig",
"=",
"new",
"CliConfig",
"(",
"opts",
")",
";",
"const",
"kaba",
"=",
"require",
"(",
"`",
"${",
"process",
".",
"cwd",
"(",
")",
"}",
"`",
")",
";",
"const",
"buildConfig",
"=",
"kaba",
".",
"getBuildConfig",
"(",
"cliConfig",
")",
";",
"const",
"scss",
"=",
"new",
"SassRunner",
"(",
"buildConfig",
",",
"cliConfig",
")",
";",
"const",
"webpack",
"=",
"new",
"WebpackRunner",
"(",
"buildConfig",
")",
";",
"Promise",
".",
"all",
"(",
"[",
"scss",
".",
"run",
"(",
")",
",",
"webpack",
".",
"run",
"(",
")",
"]",
")",
".",
"then",
"(",
"(",
"[",
"scssOk",
",",
"webpackOk",
"]",
")",
"=>",
"{",
"const",
"failed",
"=",
"(",
"false",
"===",
"scssOk",
"||",
"false",
"===",
"webpackOk",
")",
";",
"const",
"status",
"=",
"failed",
"?",
"kleur",
".",
"red",
"(",
"\"failed\"",
")",
":",
"kleur",
".",
"green",
"(",
"\"succeeded\"",
")",
";",
"logger",
".",
"logWithDuration",
"(",
"`",
"${",
"status",
"}",
"`",
",",
"process",
".",
"hrtime",
"(",
"start",
")",
")",
";",
"process",
".",
"exit",
"(",
"failed",
"?",
"1",
":",
"0",
")",
";",
"}",
")",
".",
"catch",
"(",
"(",
"...",
"args",
")",
"=>",
"console",
".",
"log",
"(",
"\"something broke\"",
",",
"args",
")",
")",
";",
"if",
"(",
"cliConfig",
".",
"isWatch",
"(",
")",
")",
"{",
"const",
"exitCallback",
"=",
"(",
")",
"=>",
"{",
"scss",
".",
"stop",
"(",
")",
";",
"webpack",
".",
"stop",
"(",
")",
";",
"}",
";",
"process",
".",
"on",
"(",
"\"exit\"",
",",
"exitCallback",
")",
";",
"process",
".",
"on",
"(",
"\"SIGINT\"",
",",
"exitCallback",
")",
";",
"process",
".",
"on",
"(",
"\"SIGUSR1\"",
",",
"exitCallback",
")",
";",
"process",
".",
"on",
"(",
"\"SIGUSR2\"",
",",
"exitCallback",
")",
";",
"}",
"}",
"catch",
"(",
"e",
")",
"{",
"if",
"(",
"/",
"cannot find module.*?kaba\\.js",
"/",
"i",
".",
"test",
"(",
"e",
".",
"message",
")",
")",
"{",
"console",
".",
"log",
"(",
"`",
"${",
"kleur",
".",
"red",
"(",
"\"Error\"",
")",
"}",
"${",
"kleur",
".",
"yellow",
"(",
"\"kaba.js\"",
")",
"}",
"`",
")",
";",
"}",
"else",
"{",
"console",
".",
"log",
"(",
"kleur",
".",
"red",
"(",
"`",
"${",
"e",
".",
"message",
"}",
"`",
")",
")",
";",
"}",
"if",
"(",
"isVerbose",
")",
"{",
"console",
".",
"error",
"(",
"e",
")",
";",
"}",
"process",
".",
"exit",
"(",
"1",
")",
";",
"}",
"}"
] | Main kaba function
@param {CliConfigArguments} opts
@param {boolean} isVerbose | [
"Main",
"kaba",
"function"
] | 8862f48c576762d39536b29b674ae3d074a94b25 | https://github.com/Becklyn/kaba/blob/8862f48c576762d39536b29b674ae3d074a94b25/bin/run.js#L124-L189 | train |
emberjs/ember-states | addon/state-manager.js | sendRecursively | function sendRecursively(event, currentState, isUnhandledPass) {
var log = this.enableLogging,
eventName = isUnhandledPass ? 'unhandledEvent' : event,
action = currentState[eventName],
contexts, sendRecursiveArguments, actionArguments;
contexts = [].slice.call(arguments, 3);
// Test to see if the action is a method that
// can be invoked. Don't blindly check just for
// existence, because it is possible the state
// manager has a child state of the given name,
// and we should still raise an exception in that
// case.
if (typeof action === 'function') {
if (log) {
if (isUnhandledPass) {
Ember.Logger.log(`STATEMANAGER: Unhandled event '${event}' being sent to state ${currentState.get('path')}.`);
} else {
Ember.Logger.log(`STATEMANAGER: Sending event '${event}' to state ${currentState.get('path')}.`);
}
}
actionArguments = contexts;
if (isUnhandledPass) {
actionArguments.unshift(event);
}
actionArguments.unshift(this);
return action.apply(currentState, actionArguments);
} else {
var parentState = get(currentState, 'parentState');
if (parentState) {
sendRecursiveArguments = contexts;
sendRecursiveArguments.unshift(event, parentState, isUnhandledPass);
return sendRecursively.apply(this, sendRecursiveArguments);
} else if (!isUnhandledPass) {
return sendEvent.call(this, event, contexts, true);
}
}
} | javascript | function sendRecursively(event, currentState, isUnhandledPass) {
var log = this.enableLogging,
eventName = isUnhandledPass ? 'unhandledEvent' : event,
action = currentState[eventName],
contexts, sendRecursiveArguments, actionArguments;
contexts = [].slice.call(arguments, 3);
// Test to see if the action is a method that
// can be invoked. Don't blindly check just for
// existence, because it is possible the state
// manager has a child state of the given name,
// and we should still raise an exception in that
// case.
if (typeof action === 'function') {
if (log) {
if (isUnhandledPass) {
Ember.Logger.log(`STATEMANAGER: Unhandled event '${event}' being sent to state ${currentState.get('path')}.`);
} else {
Ember.Logger.log(`STATEMANAGER: Sending event '${event}' to state ${currentState.get('path')}.`);
}
}
actionArguments = contexts;
if (isUnhandledPass) {
actionArguments.unshift(event);
}
actionArguments.unshift(this);
return action.apply(currentState, actionArguments);
} else {
var parentState = get(currentState, 'parentState');
if (parentState) {
sendRecursiveArguments = contexts;
sendRecursiveArguments.unshift(event, parentState, isUnhandledPass);
return sendRecursively.apply(this, sendRecursiveArguments);
} else if (!isUnhandledPass) {
return sendEvent.call(this, event, contexts, true);
}
}
} | [
"function",
"sendRecursively",
"(",
"event",
",",
"currentState",
",",
"isUnhandledPass",
")",
"{",
"var",
"log",
"=",
"this",
".",
"enableLogging",
",",
"eventName",
"=",
"isUnhandledPass",
"?",
"'unhandledEvent'",
":",
"event",
",",
"action",
"=",
"currentState",
"[",
"eventName",
"]",
",",
"contexts",
",",
"sendRecursiveArguments",
",",
"actionArguments",
";",
"contexts",
"=",
"[",
"]",
".",
"slice",
".",
"call",
"(",
"arguments",
",",
"3",
")",
";",
"if",
"(",
"typeof",
"action",
"===",
"'function'",
")",
"{",
"if",
"(",
"log",
")",
"{",
"if",
"(",
"isUnhandledPass",
")",
"{",
"Ember",
".",
"Logger",
".",
"log",
"(",
"`",
"${",
"event",
"}",
"${",
"currentState",
".",
"get",
"(",
"'path'",
")",
"}",
"`",
")",
";",
"}",
"else",
"{",
"Ember",
".",
"Logger",
".",
"log",
"(",
"`",
"${",
"event",
"}",
"${",
"currentState",
".",
"get",
"(",
"'path'",
")",
"}",
"`",
")",
";",
"}",
"}",
"actionArguments",
"=",
"contexts",
";",
"if",
"(",
"isUnhandledPass",
")",
"{",
"actionArguments",
".",
"unshift",
"(",
"event",
")",
";",
"}",
"actionArguments",
".",
"unshift",
"(",
"this",
")",
";",
"return",
"action",
".",
"apply",
"(",
"currentState",
",",
"actionArguments",
")",
";",
"}",
"else",
"{",
"var",
"parentState",
"=",
"get",
"(",
"currentState",
",",
"'parentState'",
")",
";",
"if",
"(",
"parentState",
")",
"{",
"sendRecursiveArguments",
"=",
"contexts",
";",
"sendRecursiveArguments",
".",
"unshift",
"(",
"event",
",",
"parentState",
",",
"isUnhandledPass",
")",
";",
"return",
"sendRecursively",
".",
"apply",
"(",
"this",
",",
"sendRecursiveArguments",
")",
";",
"}",
"else",
"if",
"(",
"!",
"isUnhandledPass",
")",
"{",
"return",
"sendEvent",
".",
"call",
"(",
"this",
",",
"event",
",",
"contexts",
",",
"true",
")",
";",
"}",
"}",
"}"
] | Sends the event to the currentState, if the event is not handled this method
will proceed to call the parentState recursively until it encounters an
event handler or reaches the top or root of the state path hierarchy.
@method sendRecursively
@param event
@param currentState
@param isUnhandledPass | [
"Sends",
"the",
"event",
"to",
"the",
"currentState",
"if",
"the",
"event",
"is",
"not",
"handled",
"this",
"method",
"will",
"proceed",
"to",
"call",
"the",
"parentState",
"recursively",
"until",
"it",
"encounters",
"an",
"event",
"handler",
"or",
"reaches",
"the",
"top",
"or",
"root",
"of",
"the",
"state",
"path",
"hierarchy",
"."
] | d57b64154ac8ec2625a395d8798681130259c3c4 | https://github.com/emberjs/ember-states/blob/d57b64154ac8ec2625a395d8798681130259c3c4/addon/state-manager.js#L28-L70 | train |
emberjs/ember-states | addon/state-manager.js | sendEvent | function sendEvent(eventName, sendRecursiveArguments, isUnhandledPass) {
sendRecursiveArguments.unshift(eventName, this.get('currentState'), isUnhandledPass);
return sendRecursively.apply(this, sendRecursiveArguments);
} | javascript | function sendEvent(eventName, sendRecursiveArguments, isUnhandledPass) {
sendRecursiveArguments.unshift(eventName, this.get('currentState'), isUnhandledPass);
return sendRecursively.apply(this, sendRecursiveArguments);
} | [
"function",
"sendEvent",
"(",
"eventName",
",",
"sendRecursiveArguments",
",",
"isUnhandledPass",
")",
"{",
"sendRecursiveArguments",
".",
"unshift",
"(",
"eventName",
",",
"this",
".",
"get",
"(",
"'currentState'",
")",
",",
"isUnhandledPass",
")",
";",
"return",
"sendRecursively",
".",
"apply",
"(",
"this",
",",
"sendRecursiveArguments",
")",
";",
"}"
] | Send an event to the currentState.
@method sendEvent
@param eventName
@param sendRecursiveArguments
@param isUnhandledPass | [
"Send",
"an",
"event",
"to",
"the",
"currentState",
"."
] | d57b64154ac8ec2625a395d8798681130259c3c4 | https://github.com/emberjs/ember-states/blob/d57b64154ac8ec2625a395d8798681130259c3c4/addon/state-manager.js#L80-L83 | train |
ciena-blueplanet/bunsen-core | src/reducer.js | changeEntireFormValue | function changeEntireFormValue ({model, nextValue, prevValue}) {
return {
value: immutableOnce(recursiveClean(nextValue, model)),
valueChangeSet: getChangeSet(prevValue, nextValue)
}
} | javascript | function changeEntireFormValue ({model, nextValue, prevValue}) {
return {
value: immutableOnce(recursiveClean(nextValue, model)),
valueChangeSet: getChangeSet(prevValue, nextValue)
}
} | [
"function",
"changeEntireFormValue",
"(",
"{",
"model",
",",
"nextValue",
",",
"prevValue",
"}",
")",
"{",
"return",
"{",
"value",
":",
"immutableOnce",
"(",
"recursiveClean",
"(",
"nextValue",
",",
"model",
")",
")",
",",
"valueChangeSet",
":",
"getChangeSet",
"(",
"prevValue",
",",
"nextValue",
")",
"}",
"}"
] | Change value of entire form
@param {Object} prevValue - previous form value
@param {Object} nextValue - next form value
@param {BunsenModel} model - model
@returns {Object} new state with value and value changeset | [
"Change",
"value",
"of",
"entire",
"form"
] | 993c67e314e2b75003a1ff4c2f0cb667715562b2 | https://github.com/ciena-blueplanet/bunsen-core/blob/993c67e314e2b75003a1ff4c2f0cb667715562b2/src/reducer.js#L117-L122 | train |
ciena-blueplanet/bunsen-core | src/reducer.js | changeNestedFormValue | function changeNestedFormValue ({bunsenId, formValue, model, value}) {
const segments = bunsenId.split('.')
const lastSegment = segments.pop()
const isEmpty = _.isEmpty(value) && (Array.isArray(value) || _.isObject(value)) && !(value instanceof File)
// Make sure form value is immutable
formValue = immutableOnce(formValue)
if (isArrayItem(lastSegment)) {
return setProperty({bunsenId, formValue, value})
}
if (_.includes([null, undefined, ''], value) || isEmpty) {
return unsetProperty({bunsenId, formValue, value})
}
if (!_.isEqual(value, _.get(formValue, bunsenId))) {
return setProperty({bunsenId, formValue, value})
}
return {
value: formValue,
valueChangeSet: new Map()
}
} | javascript | function changeNestedFormValue ({bunsenId, formValue, model, value}) {
const segments = bunsenId.split('.')
const lastSegment = segments.pop()
const isEmpty = _.isEmpty(value) && (Array.isArray(value) || _.isObject(value)) && !(value instanceof File)
// Make sure form value is immutable
formValue = immutableOnce(formValue)
if (isArrayItem(lastSegment)) {
return setProperty({bunsenId, formValue, value})
}
if (_.includes([null, undefined, ''], value) || isEmpty) {
return unsetProperty({bunsenId, formValue, value})
}
if (!_.isEqual(value, _.get(formValue, bunsenId))) {
return setProperty({bunsenId, formValue, value})
}
return {
value: formValue,
valueChangeSet: new Map()
}
} | [
"function",
"changeNestedFormValue",
"(",
"{",
"bunsenId",
",",
"formValue",
",",
"model",
",",
"value",
"}",
")",
"{",
"const",
"segments",
"=",
"bunsenId",
".",
"split",
"(",
"'.'",
")",
"const",
"lastSegment",
"=",
"segments",
".",
"pop",
"(",
")",
"const",
"isEmpty",
"=",
"_",
".",
"isEmpty",
"(",
"value",
")",
"&&",
"(",
"Array",
".",
"isArray",
"(",
"value",
")",
"||",
"_",
".",
"isObject",
"(",
"value",
")",
")",
"&&",
"!",
"(",
"value",
"instanceof",
"File",
")",
"formValue",
"=",
"immutableOnce",
"(",
"formValue",
")",
"if",
"(",
"isArrayItem",
"(",
"lastSegment",
")",
")",
"{",
"return",
"setProperty",
"(",
"{",
"bunsenId",
",",
"formValue",
",",
"value",
"}",
")",
"}",
"if",
"(",
"_",
".",
"includes",
"(",
"[",
"null",
",",
"undefined",
",",
"''",
"]",
",",
"value",
")",
"||",
"isEmpty",
")",
"{",
"return",
"unsetProperty",
"(",
"{",
"bunsenId",
",",
"formValue",
",",
"value",
"}",
")",
"}",
"if",
"(",
"!",
"_",
".",
"isEqual",
"(",
"value",
",",
"_",
".",
"get",
"(",
"formValue",
",",
"bunsenId",
")",
")",
")",
"{",
"return",
"setProperty",
"(",
"{",
"bunsenId",
",",
"formValue",
",",
"value",
"}",
")",
"}",
"return",
"{",
"value",
":",
"formValue",
",",
"valueChangeSet",
":",
"new",
"Map",
"(",
")",
"}",
"}"
] | Change value of form at specified path
@param {String} bunsenId - path to part of form to change value of
@param {Object} formValue - current form value
@param {BunsenMOdel} model - model
@param {Object} value - new value for path
@returns {Object} new state with value and value changeset
/* eslint-disable complexity | [
"Change",
"value",
"of",
"form",
"at",
"specified",
"path"
] | 993c67e314e2b75003a1ff4c2f0cb667715562b2 | https://github.com/ciena-blueplanet/bunsen-core/blob/993c67e314e2b75003a1ff4c2f0cb667715562b2/src/reducer.js#L133-L157 | train |
ciena-blueplanet/bunsen-core | src/reducer.js | unsetProperty | function unsetProperty ({bunsenId, formValue, value}) {
const valueChangeSet = new Map()
valueChangeSet.set(bunsenId, {
value,
type: 'unset'
})
return {
value: unset(formValue, bunsenId),
valueChangeSet
}
} | javascript | function unsetProperty ({bunsenId, formValue, value}) {
const valueChangeSet = new Map()
valueChangeSet.set(bunsenId, {
value,
type: 'unset'
})
return {
value: unset(formValue, bunsenId),
valueChangeSet
}
} | [
"function",
"unsetProperty",
"(",
"{",
"bunsenId",
",",
"formValue",
",",
"value",
"}",
")",
"{",
"const",
"valueChangeSet",
"=",
"new",
"Map",
"(",
")",
"valueChangeSet",
".",
"set",
"(",
"bunsenId",
",",
"{",
"value",
",",
"type",
":",
"'unset'",
"}",
")",
"return",
"{",
"value",
":",
"unset",
"(",
"formValue",
",",
"bunsenId",
")",
",",
"valueChangeSet",
"}",
"}"
] | Unset a specific property in the form
@param {String} bunsenId - path to property to unset
@param {Object} formValue - current form value
@param {*} value - property value that triggered unset
@returns {Object} object containing new form value and changeset | [
"Unset",
"a",
"specific",
"property",
"in",
"the",
"form"
] | 993c67e314e2b75003a1ff4c2f0cb667715562b2 | https://github.com/ciena-blueplanet/bunsen-core/blob/993c67e314e2b75003a1ff4c2f0cb667715562b2/src/reducer.js#L188-L200 | train |
ciena-blueplanet/bunsen-core | src/reducer.js | function (state, action) {
// Apply coniditions to view cells
let normalized
let view
if (state.unnormalizedModel) {
normalized = normalizeModelAndView({
model: state.unnormalizedModel,
view: action.view
})
view = evaluateViewConditions(normalized.view, state.value)
} else {
view = evaluateViewConditions(state.baseView, state.value)
normalized = {
view,
model: state.model
}
}
const newState = {
baseView: normalized.view,
lastAction: CHANGE_VIEW,
unnormalizedView: action.view,
view
}
if (!_.isEqual(state.baseModel, normalized.model)) {
Object.assign(newState, {
baseModel: normalized.model,
model: evaluateConditions(normalized.model, state.value, undefined, state.value)
})
}
return _.defaults(newState, state)
} | javascript | function (state, action) {
// Apply coniditions to view cells
let normalized
let view
if (state.unnormalizedModel) {
normalized = normalizeModelAndView({
model: state.unnormalizedModel,
view: action.view
})
view = evaluateViewConditions(normalized.view, state.value)
} else {
view = evaluateViewConditions(state.baseView, state.value)
normalized = {
view,
model: state.model
}
}
const newState = {
baseView: normalized.view,
lastAction: CHANGE_VIEW,
unnormalizedView: action.view,
view
}
if (!_.isEqual(state.baseModel, normalized.model)) {
Object.assign(newState, {
baseModel: normalized.model,
model: evaluateConditions(normalized.model, state.value, undefined, state.value)
})
}
return _.defaults(newState, state)
} | [
"function",
"(",
"state",
",",
"action",
")",
"{",
"let",
"normalized",
"let",
"view",
"if",
"(",
"state",
".",
"unnormalizedModel",
")",
"{",
"normalized",
"=",
"normalizeModelAndView",
"(",
"{",
"model",
":",
"state",
".",
"unnormalizedModel",
",",
"view",
":",
"action",
".",
"view",
"}",
")",
"view",
"=",
"evaluateViewConditions",
"(",
"normalized",
".",
"view",
",",
"state",
".",
"value",
")",
"}",
"else",
"{",
"view",
"=",
"evaluateViewConditions",
"(",
"state",
".",
"baseView",
",",
"state",
".",
"value",
")",
"normalized",
"=",
"{",
"view",
",",
"model",
":",
"state",
".",
"model",
"}",
"}",
"const",
"newState",
"=",
"{",
"baseView",
":",
"normalized",
".",
"view",
",",
"lastAction",
":",
"CHANGE_VIEW",
",",
"unnormalizedView",
":",
"action",
".",
"view",
",",
"view",
"}",
"if",
"(",
"!",
"_",
".",
"isEqual",
"(",
"state",
".",
"baseModel",
",",
"normalized",
".",
"model",
")",
")",
"{",
"Object",
".",
"assign",
"(",
"newState",
",",
"{",
"baseModel",
":",
"normalized",
".",
"model",
",",
"model",
":",
"evaluateConditions",
"(",
"normalized",
".",
"model",
",",
"state",
".",
"value",
",",
"undefined",
",",
"state",
".",
"value",
")",
"}",
")",
"}",
"return",
"_",
".",
"defaults",
"(",
"newState",
",",
"state",
")",
"}"
] | Update the bunsen model
@param {State} state - state to update
@param {Action} action - action
@returns {State} - updated state | [
"Update",
"the",
"bunsen",
"model"
] | 993c67e314e2b75003a1ff4c2f0cb667715562b2 | https://github.com/ciena-blueplanet/bunsen-core/blob/993c67e314e2b75003a1ff4c2f0cb667715562b2/src/reducer.js#L270-L304 | train |