id
int32 0
58k
| 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
list | docstring
stringlengths 4
11.8k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 86
226
|
|---|---|---|---|---|---|---|---|---|---|---|---|
16,100
|
antonmedv/monkberry
|
monkberry.js
|
transformArray
|
function transformArray(array, keys, i, options) {
if (options) {
var t = {__index__: i};
t[options.value] = array[i];
if (options.key) {
t[options.key] = i;
}
return t;
} else {
return array[i];
}
}
|
javascript
|
function transformArray(array, keys, i, options) {
if (options) {
var t = {__index__: i};
t[options.value] = array[i];
if (options.key) {
t[options.key] = i;
}
return t;
} else {
return array[i];
}
}
|
[
"function",
"transformArray",
"(",
"array",
",",
"keys",
",",
"i",
",",
"options",
")",
"{",
"if",
"(",
"options",
")",
"{",
"var",
"t",
"=",
"{",
"__index__",
":",
"i",
"}",
";",
"t",
"[",
"options",
".",
"value",
"]",
"=",
"array",
"[",
"i",
"]",
";",
"if",
"(",
"options",
".",
"key",
")",
"{",
"t",
"[",
"options",
".",
"key",
"]",
"=",
"i",
";",
"}",
"return",
"t",
";",
"}",
"else",
"{",
"return",
"array",
"[",
"i",
"]",
";",
"}",
"}"
] |
Helper function for working with foreach loops data. Will transform data for "key, value of array" constructions.
|
[
"Helper",
"function",
"for",
"working",
"with",
"foreach",
"loops",
"data",
".",
"Will",
"transform",
"data",
"for",
"key",
"value",
"of",
"array",
"constructions",
"."
] |
f9590fe6cd31a1395f12bb3f4f8af50ab7e70e3e
|
https://github.com/antonmedv/monkberry/blob/f9590fe6cd31a1395f12bb3f4f8af50ab7e70e3e/monkberry.js#L357-L370
|
16,101
|
antonmedv/monkberry
|
src/compiler/unsafe.js
|
unsafe
|
function unsafe(root, nodes, html) {
var node, j, i = nodes.length, element = document.createElement('div');
element.innerHTML = html;
while (i --> 0)
nodes[i].parentNode.removeChild(nodes.pop());
for (i = j = element.childNodes.length - 1; j >= 0; j--)
nodes.push(element.childNodes[j]);
++i;
if (root.nodeType == 8)
if (root.parentNode)
while (i --> 0)
root.parentNode.insertBefore(nodes[i], root);
else
throw "Can not insert child view into parent node. You need append your view first and then update.";
else
while (i --> 0)
root.appendChild(nodes[i]);
}
|
javascript
|
function unsafe(root, nodes, html) {
var node, j, i = nodes.length, element = document.createElement('div');
element.innerHTML = html;
while (i --> 0)
nodes[i].parentNode.removeChild(nodes.pop());
for (i = j = element.childNodes.length - 1; j >= 0; j--)
nodes.push(element.childNodes[j]);
++i;
if (root.nodeType == 8)
if (root.parentNode)
while (i --> 0)
root.parentNode.insertBefore(nodes[i], root);
else
throw "Can not insert child view into parent node. You need append your view first and then update.";
else
while (i --> 0)
root.appendChild(nodes[i]);
}
|
[
"function",
"unsafe",
"(",
"root",
",",
"nodes",
",",
"html",
")",
"{",
"var",
"node",
",",
"j",
",",
"i",
"=",
"nodes",
".",
"length",
",",
"element",
"=",
"document",
".",
"createElement",
"(",
"'div'",
")",
";",
"element",
".",
"innerHTML",
"=",
"html",
";",
"while",
"(",
"i",
"--",
">",
"0",
")",
"nodes",
"[",
"i",
"]",
".",
"parentNode",
".",
"removeChild",
"(",
"nodes",
".",
"pop",
"(",
")",
")",
";",
"for",
"(",
"i",
"=",
"j",
"=",
"element",
".",
"childNodes",
".",
"length",
"-",
"1",
";",
"j",
">=",
"0",
";",
"j",
"--",
")",
"nodes",
".",
"push",
"(",
"element",
".",
"childNodes",
"[",
"j",
"]",
")",
";",
"++",
"i",
";",
"if",
"(",
"root",
".",
"nodeType",
"==",
"8",
")",
"if",
"(",
"root",
".",
"parentNode",
")",
"while",
"(",
"i",
"--",
">",
"0",
")",
"root",
".",
"parentNode",
".",
"insertBefore",
"(",
"nodes",
"[",
"i",
"]",
",",
"root",
")",
";",
"else",
"throw",
"\"Can not insert child view into parent node. You need append your view first and then update.\"",
";",
"else",
"while",
"(",
"i",
"--",
">",
"0",
")",
"root",
".",
"appendChild",
"(",
"nodes",
"[",
"i",
"]",
")",
";",
"}"
] |
This function is being used for unsafe `innerHTML` insertion of HTML into DOM.
Code looks strange. I know. But it is possible minimalistic implementation of.
@param root {Element} Node there to insert unsafe html.
@param nodes {Array} List of already inserted html nodes for remove.
@param html {string} Unsafe html to insert.
|
[
"This",
"function",
"is",
"being",
"used",
"for",
"unsafe",
"innerHTML",
"insertion",
"of",
"HTML",
"into",
"DOM",
".",
"Code",
"looks",
"strange",
".",
"I",
"know",
".",
"But",
"it",
"is",
"possible",
"minimalistic",
"implementation",
"of",
"."
] |
f9590fe6cd31a1395f12bb3f4f8af50ab7e70e3e
|
https://github.com/antonmedv/monkberry/blob/f9590fe6cd31a1395f12bb3f4f8af50ab7e70e3e/src/compiler/unsafe.js#L55-L77
|
16,102
|
macbre/phantomas
|
bin/phantomas.js
|
task
|
function task(callback) {
// spawn phantomas process
var child = phantomas(url, options, function(err, data, results) {
callback(
null, // pass null even in case of an error to continue async.series processing (issue #380)
[err, results]
);
});
child.on('progress', function(progress, inc) {
if (bar) {
bar.tick(inc);
}
});
// pipe --verbose messages to stderr
child.stderr.pipe(process.stderr);
}
|
javascript
|
function task(callback) {
// spawn phantomas process
var child = phantomas(url, options, function(err, data, results) {
callback(
null, // pass null even in case of an error to continue async.series processing (issue #380)
[err, results]
);
});
child.on('progress', function(progress, inc) {
if (bar) {
bar.tick(inc);
}
});
// pipe --verbose messages to stderr
child.stderr.pipe(process.stderr);
}
|
[
"function",
"task",
"(",
"callback",
")",
"{",
"// spawn phantomas process",
"var",
"child",
"=",
"phantomas",
"(",
"url",
",",
"options",
",",
"function",
"(",
"err",
",",
"data",
",",
"results",
")",
"{",
"callback",
"(",
"null",
",",
"// pass null even in case of an error to continue async.series processing (issue #380)",
"[",
"err",
",",
"results",
"]",
")",
";",
"}",
")",
";",
"child",
".",
"on",
"(",
"'progress'",
",",
"function",
"(",
"progress",
",",
"inc",
")",
"{",
"if",
"(",
"bar",
")",
"{",
"bar",
".",
"tick",
"(",
"inc",
")",
";",
"}",
"}",
")",
";",
"// pipe --verbose messages to stderr",
"child",
".",
"stderr",
".",
"pipe",
"(",
"process",
".",
"stderr",
")",
";",
"}"
] |
perform a single run
|
[
"perform",
"a",
"single",
"run"
] |
ce56cdacabba1ab0672389e4e4a83b4e5ead0582
|
https://github.com/macbre/phantomas/blob/ce56cdacabba1ab0672389e4e4a83b4e5ead0582/bin/phantomas.js#L146-L163
|
16,103
|
macbre/phantomas
|
core/scope.js
|
function(node, callback, depth) {
if (this.isSkipped(node)) {
return;
}
var childNode,
childNodes = node && node.childNodes || [];
depth = (depth || 1);
for (var n = 0, len = childNodes.length; n < len; n++) {
childNode = childNodes[n];
// callback can return false to stop recursive
if (callback(childNode, depth) !== false) {
this.walk(childNode, callback, depth + 1);
}
}
}
|
javascript
|
function(node, callback, depth) {
if (this.isSkipped(node)) {
return;
}
var childNode,
childNodes = node && node.childNodes || [];
depth = (depth || 1);
for (var n = 0, len = childNodes.length; n < len; n++) {
childNode = childNodes[n];
// callback can return false to stop recursive
if (callback(childNode, depth) !== false) {
this.walk(childNode, callback, depth + 1);
}
}
}
|
[
"function",
"(",
"node",
",",
"callback",
",",
"depth",
")",
"{",
"if",
"(",
"this",
".",
"isSkipped",
"(",
"node",
")",
")",
"{",
"return",
";",
"}",
"var",
"childNode",
",",
"childNodes",
"=",
"node",
"&&",
"node",
".",
"childNodes",
"||",
"[",
"]",
";",
"depth",
"=",
"(",
"depth",
"||",
"1",
")",
";",
"for",
"(",
"var",
"n",
"=",
"0",
",",
"len",
"=",
"childNodes",
".",
"length",
";",
"n",
"<",
"len",
";",
"n",
"++",
")",
"{",
"childNode",
"=",
"childNodes",
"[",
"n",
"]",
";",
"// callback can return false to stop recursive",
"if",
"(",
"callback",
"(",
"childNode",
",",
"depth",
")",
"!==",
"false",
")",
"{",
"this",
".",
"walk",
"(",
"childNode",
",",
"callback",
",",
"depth",
"+",
"1",
")",
";",
"}",
"}",
"}"
] |
call callback for each child of node
|
[
"call",
"callback",
"for",
"each",
"child",
"of",
"node"
] |
ce56cdacabba1ab0672389e4e4a83b4e5ead0582
|
https://github.com/macbre/phantomas/blob/ce56cdacabba1ab0672389e4e4a83b4e5ead0582/core/scope.js#L25-L43
|
|
16,104
|
macbre/phantomas
|
core/scope.js
|
spyGlobalVar
|
function spyGlobalVar(varName, callback) {
phantomas.log('spy: attaching to %s global variable', varName);
window.__defineSetter__(varName, function(val) {
phantomas.log('spy: %s global variable has been defined', varName);
spiedGlobals[varName] = val;
callback(val);
});
window.__defineGetter__(varName, function() {
return spiedGlobals[varName] || undefined;
});
}
|
javascript
|
function spyGlobalVar(varName, callback) {
phantomas.log('spy: attaching to %s global variable', varName);
window.__defineSetter__(varName, function(val) {
phantomas.log('spy: %s global variable has been defined', varName);
spiedGlobals[varName] = val;
callback(val);
});
window.__defineGetter__(varName, function() {
return spiedGlobals[varName] || undefined;
});
}
|
[
"function",
"spyGlobalVar",
"(",
"varName",
",",
"callback",
")",
"{",
"phantomas",
".",
"log",
"(",
"'spy: attaching to %s global variable'",
",",
"varName",
")",
";",
"window",
".",
"__defineSetter__",
"(",
"varName",
",",
"function",
"(",
"val",
")",
"{",
"phantomas",
".",
"log",
"(",
"'spy: %s global variable has been defined'",
",",
"varName",
")",
";",
"spiedGlobals",
"[",
"varName",
"]",
"=",
"val",
";",
"callback",
"(",
"val",
")",
";",
"}",
")",
";",
"window",
".",
"__defineGetter__",
"(",
"varName",
",",
"function",
"(",
")",
"{",
"return",
"spiedGlobals",
"[",
"varName",
"]",
"||",
"undefined",
";",
"}",
")",
";",
"}"
] |
call given callback when "varName" global variable is being defined used by jQuery module
|
[
"call",
"given",
"callback",
"when",
"varName",
"global",
"variable",
"is",
"being",
"defined",
"used",
"by",
"jQuery",
"module"
] |
ce56cdacabba1ab0672389e4e4a83b4e5ead0582
|
https://github.com/macbre/phantomas/blob/ce56cdacabba1ab0672389e4e4a83b4e5ead0582/core/scope.js#L220-L234
|
16,105
|
macbre/phantomas
|
modules/requestsStats/requestsStats.js
|
pushToStack
|
function pushToStack(type, entry, check) {
// no entry of given type
if (typeof stack[type] === 'undefined') {
stack[type] = entry;
}
// apply check function
else if (check(stack[type], entry) === true) {
stack[type] = entry;
}
}
|
javascript
|
function pushToStack(type, entry, check) {
// no entry of given type
if (typeof stack[type] === 'undefined') {
stack[type] = entry;
}
// apply check function
else if (check(stack[type], entry) === true) {
stack[type] = entry;
}
}
|
[
"function",
"pushToStack",
"(",
"type",
",",
"entry",
",",
"check",
")",
"{",
"// no entry of given type",
"if",
"(",
"typeof",
"stack",
"[",
"type",
"]",
"===",
"'undefined'",
")",
"{",
"stack",
"[",
"type",
"]",
"=",
"entry",
";",
"}",
"// apply check function",
"else",
"if",
"(",
"check",
"(",
"stack",
"[",
"type",
"]",
",",
"entry",
")",
"===",
"true",
")",
"{",
"stack",
"[",
"type",
"]",
"=",
"entry",
";",
"}",
"}"
] |
adds given entry under the "type" if given check function returns true
|
[
"adds",
"given",
"entry",
"under",
"the",
"type",
"if",
"given",
"check",
"function",
"returns",
"true"
] |
ce56cdacabba1ab0672389e4e4a83b4e5ead0582
|
https://github.com/macbre/phantomas/blob/ce56cdacabba1ab0672389e4e4a83b4e5ead0582/modules/requestsStats/requestsStats.js#L21-L30
|
16,106
|
macbre/phantomas
|
core/results.js
|
function(name, value) {
if (typeof metricsAvgStorage[name] === 'undefined') {
metricsAvgStorage[name] = [];
}
metricsAvgStorage[name].push(value);
this.setMetric(name, getAverage(metricsAvgStorage[name]));
}
|
javascript
|
function(name, value) {
if (typeof metricsAvgStorage[name] === 'undefined') {
metricsAvgStorage[name] = [];
}
metricsAvgStorage[name].push(value);
this.setMetric(name, getAverage(metricsAvgStorage[name]));
}
|
[
"function",
"(",
"name",
",",
"value",
")",
"{",
"if",
"(",
"typeof",
"metricsAvgStorage",
"[",
"name",
"]",
"===",
"'undefined'",
")",
"{",
"metricsAvgStorage",
"[",
"name",
"]",
"=",
"[",
"]",
";",
"}",
"metricsAvgStorage",
"[",
"name",
"]",
".",
"push",
"(",
"value",
")",
";",
"this",
".",
"setMetric",
"(",
"name",
",",
"getAverage",
"(",
"metricsAvgStorage",
"[",
"name",
"]",
")",
")",
";",
"}"
] |
push a value and update the metric if the current average value
|
[
"push",
"a",
"value",
"and",
"update",
"the",
"metric",
"if",
"the",
"current",
"average",
"value"
] |
ce56cdacabba1ab0672389e4e4a83b4e5ead0582
|
https://github.com/macbre/phantomas/blob/ce56cdacabba1ab0672389e4e4a83b4e5ead0582/core/results.js#L49-L57
|
|
16,107
|
macbre/phantomas
|
extensions/har/har.js
|
createHAR
|
function createHAR(page, creator) {
// @see: https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/HAR/Overview.html
var address = page.address;
var title = page.title;
var startTime = page.startTime;
var resources = page.resources;
var entries = [];
resources.forEach(function(resource) {
var request = resource.request;
var response = resource.response;
if (!request || !response) {
return;
}
// Exclude data URIs from the HAR because they aren't
// included in the spec.
if (request.url.substring(0, 5).toLowerCase() === 'data:') {
return;
}
entries.push({
cache: {},
pageref: address,
request: {
// Accurate bodySize blocked on https://github.com/ariya/phantomjs/pull/11484
bodySize: -1,
cookies: [],
headers: request.headers,
// Accurate headersSize blocked on https://github.com/ariya/phantomjs/pull/11484
headersSize: -1,
httpVersion: 'HTTP/1.1',
method: request.method,
queryString: [],
url: request.url,
},
response: {
bodySize: response.bodySize,
cookies: [],
headers: response.headers,
headersSize: response.headersSize,
httpVersion: 'HTTP/1.1',
redirectURL: '',
status: response.status,
statusText: response.statusText,
content: {
mimeType: response.contentType || '',
size: response.bodySize, // uncompressed
text: ''
}
},
startedDateTime: resource.startTime && resource.startTime.toISOString(),
time: response.timeToLastByte,
timings: {
blocked: 0,
dns: -1,
connect: -1,
send: 0,
wait: 0, // response.timeToFirstByte || 0,
receive: 0, // response.receiveTime,
ssl: -1
}
});
});
return {
log: {
creator: creator,
entries: entries,
pages: [
{
startedDateTime: startTime.toISOString(),
id: address,
title: title,
pageTimings: {
onLoad: page.onLoad || -1,
onContentLoad: page.onContentLoad || -1
}
}
],
version: '1.2',
}
};
}
|
javascript
|
function createHAR(page, creator) {
// @see: https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/HAR/Overview.html
var address = page.address;
var title = page.title;
var startTime = page.startTime;
var resources = page.resources;
var entries = [];
resources.forEach(function(resource) {
var request = resource.request;
var response = resource.response;
if (!request || !response) {
return;
}
// Exclude data URIs from the HAR because they aren't
// included in the spec.
if (request.url.substring(0, 5).toLowerCase() === 'data:') {
return;
}
entries.push({
cache: {},
pageref: address,
request: {
// Accurate bodySize blocked on https://github.com/ariya/phantomjs/pull/11484
bodySize: -1,
cookies: [],
headers: request.headers,
// Accurate headersSize blocked on https://github.com/ariya/phantomjs/pull/11484
headersSize: -1,
httpVersion: 'HTTP/1.1',
method: request.method,
queryString: [],
url: request.url,
},
response: {
bodySize: response.bodySize,
cookies: [],
headers: response.headers,
headersSize: response.headersSize,
httpVersion: 'HTTP/1.1',
redirectURL: '',
status: response.status,
statusText: response.statusText,
content: {
mimeType: response.contentType || '',
size: response.bodySize, // uncompressed
text: ''
}
},
startedDateTime: resource.startTime && resource.startTime.toISOString(),
time: response.timeToLastByte,
timings: {
blocked: 0,
dns: -1,
connect: -1,
send: 0,
wait: 0, // response.timeToFirstByte || 0,
receive: 0, // response.receiveTime,
ssl: -1
}
});
});
return {
log: {
creator: creator,
entries: entries,
pages: [
{
startedDateTime: startTime.toISOString(),
id: address,
title: title,
pageTimings: {
onLoad: page.onLoad || -1,
onContentLoad: page.onContentLoad || -1
}
}
],
version: '1.2',
}
};
}
|
[
"function",
"createHAR",
"(",
"page",
",",
"creator",
")",
"{",
"// @see: https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/HAR/Overview.html",
"var",
"address",
"=",
"page",
".",
"address",
";",
"var",
"title",
"=",
"page",
".",
"title",
";",
"var",
"startTime",
"=",
"page",
".",
"startTime",
";",
"var",
"resources",
"=",
"page",
".",
"resources",
";",
"var",
"entries",
"=",
"[",
"]",
";",
"resources",
".",
"forEach",
"(",
"function",
"(",
"resource",
")",
"{",
"var",
"request",
"=",
"resource",
".",
"request",
";",
"var",
"response",
"=",
"resource",
".",
"response",
";",
"if",
"(",
"!",
"request",
"||",
"!",
"response",
")",
"{",
"return",
";",
"}",
"// Exclude data URIs from the HAR because they aren't",
"// included in the spec.",
"if",
"(",
"request",
".",
"url",
".",
"substring",
"(",
"0",
",",
"5",
")",
".",
"toLowerCase",
"(",
")",
"===",
"'data:'",
")",
"{",
"return",
";",
"}",
"entries",
".",
"push",
"(",
"{",
"cache",
":",
"{",
"}",
",",
"pageref",
":",
"address",
",",
"request",
":",
"{",
"// Accurate bodySize blocked on https://github.com/ariya/phantomjs/pull/11484",
"bodySize",
":",
"-",
"1",
",",
"cookies",
":",
"[",
"]",
",",
"headers",
":",
"request",
".",
"headers",
",",
"// Accurate headersSize blocked on https://github.com/ariya/phantomjs/pull/11484",
"headersSize",
":",
"-",
"1",
",",
"httpVersion",
":",
"'HTTP/1.1'",
",",
"method",
":",
"request",
".",
"method",
",",
"queryString",
":",
"[",
"]",
",",
"url",
":",
"request",
".",
"url",
",",
"}",
",",
"response",
":",
"{",
"bodySize",
":",
"response",
".",
"bodySize",
",",
"cookies",
":",
"[",
"]",
",",
"headers",
":",
"response",
".",
"headers",
",",
"headersSize",
":",
"response",
".",
"headersSize",
",",
"httpVersion",
":",
"'HTTP/1.1'",
",",
"redirectURL",
":",
"''",
",",
"status",
":",
"response",
".",
"status",
",",
"statusText",
":",
"response",
".",
"statusText",
",",
"content",
":",
"{",
"mimeType",
":",
"response",
".",
"contentType",
"||",
"''",
",",
"size",
":",
"response",
".",
"bodySize",
",",
"// uncompressed",
"text",
":",
"''",
"}",
"}",
",",
"startedDateTime",
":",
"resource",
".",
"startTime",
"&&",
"resource",
".",
"startTime",
".",
"toISOString",
"(",
")",
",",
"time",
":",
"response",
".",
"timeToLastByte",
",",
"timings",
":",
"{",
"blocked",
":",
"0",
",",
"dns",
":",
"-",
"1",
",",
"connect",
":",
"-",
"1",
",",
"send",
":",
"0",
",",
"wait",
":",
"0",
",",
"// response.timeToFirstByte || 0,",
"receive",
":",
"0",
",",
"// response.receiveTime,",
"ssl",
":",
"-",
"1",
"}",
"}",
")",
";",
"}",
")",
";",
"return",
"{",
"log",
":",
"{",
"creator",
":",
"creator",
",",
"entries",
":",
"entries",
",",
"pages",
":",
"[",
"{",
"startedDateTime",
":",
"startTime",
".",
"toISOString",
"(",
")",
",",
"id",
":",
"address",
",",
"title",
":",
"title",
",",
"pageTimings",
":",
"{",
"onLoad",
":",
"page",
".",
"onLoad",
"||",
"-",
"1",
",",
"onContentLoad",
":",
"page",
".",
"onContentLoad",
"||",
"-",
"1",
"}",
"}",
"]",
",",
"version",
":",
"'1.2'",
",",
"}",
"}",
";",
"}"
] |
Inspired by phantomHAR
@author: Christopher Van (@cvan)
@homepage: https://github.com/cvan/phantomHAR
@original: https://github.com/cvan/phantomHAR/blob/master/phantomhar.js
|
[
"Inspired",
"by",
"phantomHAR"
] |
ce56cdacabba1ab0672389e4e4a83b4e5ead0582
|
https://github.com/macbre/phantomas/blob/ce56cdacabba1ab0672389e4e4a83b4e5ead0582/extensions/har/har.js#L17-L102
|
16,108
|
macbre/phantomas
|
core/modules/requestsMonitor/requestsMonitor.js
|
lowerCaseHeaders
|
function lowerCaseHeaders(headers) {
var res = {};
Object.keys(headers).forEach(headerName => {
res[headerName.toLowerCase()] = headers[headerName];
});
return res;
}
|
javascript
|
function lowerCaseHeaders(headers) {
var res = {};
Object.keys(headers).forEach(headerName => {
res[headerName.toLowerCase()] = headers[headerName];
});
return res;
}
|
[
"function",
"lowerCaseHeaders",
"(",
"headers",
")",
"{",
"var",
"res",
"=",
"{",
"}",
";",
"Object",
".",
"keys",
"(",
"headers",
")",
".",
"forEach",
"(",
"headerName",
"=>",
"{",
"res",
"[",
"headerName",
".",
"toLowerCase",
"(",
")",
"]",
"=",
"headers",
"[",
"headerName",
"]",
";",
"}",
")",
";",
"return",
"res",
";",
"}"
] |
Given key-value set of HTTP headers returns the set with lowercased header names
@param {object} headers
@returns {object}
|
[
"Given",
"key",
"-",
"value",
"set",
"of",
"HTTP",
"headers",
"returns",
"the",
"set",
"with",
"lowercased",
"header",
"names"
] |
ce56cdacabba1ab0672389e4e4a83b4e5ead0582
|
https://github.com/macbre/phantomas/blob/ce56cdacabba1ab0672389e4e4a83b4e5ead0582/core/modules/requestsMonitor/requestsMonitor.js#L15-L23
|
16,109
|
macbre/phantomas
|
core/modules/requestsMonitor/requestsMonitor.js
|
parseEntryUrl
|
function parseEntryUrl(entry) {
const parseUrl = require('url').parse;
var parsed;
// asset type
entry.type = 'other';
if (entry.url.indexOf('data:') !== 0) {
// @see http://nodejs.org/api/url.html#url_url
parsed = parseUrl(entry.url) || {};
entry.protocol = parsed.protocol.replace(':', '');
entry.domain = parsed.hostname;
entry.query = parsed.query;
if (entry.protocol === 'https') {
entry.isSSL = true;
}
}
else {
// base64 encoded data
entry.domain = false;
entry.protocol = false;
entry.isBase64 = true;
}
return entry;
}
|
javascript
|
function parseEntryUrl(entry) {
const parseUrl = require('url').parse;
var parsed;
// asset type
entry.type = 'other';
if (entry.url.indexOf('data:') !== 0) {
// @see http://nodejs.org/api/url.html#url_url
parsed = parseUrl(entry.url) || {};
entry.protocol = parsed.protocol.replace(':', '');
entry.domain = parsed.hostname;
entry.query = parsed.query;
if (entry.protocol === 'https') {
entry.isSSL = true;
}
}
else {
// base64 encoded data
entry.domain = false;
entry.protocol = false;
entry.isBase64 = true;
}
return entry;
}
|
[
"function",
"parseEntryUrl",
"(",
"entry",
")",
"{",
"const",
"parseUrl",
"=",
"require",
"(",
"'url'",
")",
".",
"parse",
";",
"var",
"parsed",
";",
"// asset type",
"entry",
".",
"type",
"=",
"'other'",
";",
"if",
"(",
"entry",
".",
"url",
".",
"indexOf",
"(",
"'data:'",
")",
"!==",
"0",
")",
"{",
"// @see http://nodejs.org/api/url.html#url_url",
"parsed",
"=",
"parseUrl",
"(",
"entry",
".",
"url",
")",
"||",
"{",
"}",
";",
"entry",
".",
"protocol",
"=",
"parsed",
".",
"protocol",
".",
"replace",
"(",
"':'",
",",
"''",
")",
";",
"entry",
".",
"domain",
"=",
"parsed",
".",
"hostname",
";",
"entry",
".",
"query",
"=",
"parsed",
".",
"query",
";",
"if",
"(",
"entry",
".",
"protocol",
"===",
"'https'",
")",
"{",
"entry",
".",
"isSSL",
"=",
"true",
";",
"}",
"}",
"else",
"{",
"// base64 encoded data",
"entry",
".",
"domain",
"=",
"false",
";",
"entry",
".",
"protocol",
"=",
"false",
";",
"entry",
".",
"isBase64",
"=",
"true",
";",
"}",
"return",
"entry",
";",
"}"
] |
parse given URL to get protocol and domain
|
[
"parse",
"given",
"URL",
"to",
"get",
"protocol",
"and",
"domain"
] |
ce56cdacabba1ab0672389e4e4a83b4e5ead0582
|
https://github.com/macbre/phantomas/blob/ce56cdacabba1ab0672389e4e4a83b4e5ead0582/core/modules/requestsMonitor/requestsMonitor.js#L26-L53
|
16,110
|
macbre/phantomas
|
core/modules/requestsMonitor/requestsMonitor.js
|
addContentType
|
function addContentType(headerValue, entry) {
var value = headerValue.split(';').shift().toLowerCase();
entry.contentType = value;
switch(value) {
case 'text/html':
entry.type = 'html';
entry.isHTML = true;
break;
case 'text/xml':
entry.type = 'xml';
entry.isXML = true;
break;
case 'text/css':
entry.type = 'css';
entry.isCSS = true;
break;
case 'application/x-javascript':
case 'application/javascript':
case 'text/javascript':
entry.type = 'js';
entry.isJS = true;
break;
case 'application/json':
entry.type = 'json';
entry.isJSON = true;
break;
case 'image/png':
case 'image/jpeg':
case 'image/gif':
case 'image/svg+xml':
case 'image/webp':
entry.type = 'image';
entry.isImage = true;
if (value === 'image/svg+xml') {
entry.isSVG = true;
}
break;
case 'video/webm':
entry.type = 'video';
entry.isVideo = true;
break;
// @see http://stackoverflow.com/questions/2871655/proper-mime-type-for-fonts
case 'application/font-wof':
case 'application/font-woff':
case 'application/vnd.ms-fontobject':
case 'application/x-font-opentype':
case 'application/x-font-truetype':
case 'application/x-font-ttf':
case 'application/x-font-woff':
case 'font/opentype':
case 'font/ttf':
case 'font/woff':
entry.type = 'webfont';
entry.isWebFont = true;
if (/ttf|truetype$/.test(value)) {
entry.isTTF = true;
}
break;
case 'application/octet-stream':
var ext = (entry.url || '').split('.').pop();
switch(ext) {
// @see http://stackoverflow.com/questions/2871655/proper-mime-type-for-fonts#comment-8077637
case 'otf':
entry.type = 'webfont';
entry.isWebFont = true;
break;
}
break;
case 'image/x-icon':
case 'image/vnd.microsoft.icon':
entry.type = 'favicon';
entry.isFavicon = true;
break;
default:
debug('Unknown content type found: ' + value + ' for <' + entry.url + '>');
}
return entry;
}
|
javascript
|
function addContentType(headerValue, entry) {
var value = headerValue.split(';').shift().toLowerCase();
entry.contentType = value;
switch(value) {
case 'text/html':
entry.type = 'html';
entry.isHTML = true;
break;
case 'text/xml':
entry.type = 'xml';
entry.isXML = true;
break;
case 'text/css':
entry.type = 'css';
entry.isCSS = true;
break;
case 'application/x-javascript':
case 'application/javascript':
case 'text/javascript':
entry.type = 'js';
entry.isJS = true;
break;
case 'application/json':
entry.type = 'json';
entry.isJSON = true;
break;
case 'image/png':
case 'image/jpeg':
case 'image/gif':
case 'image/svg+xml':
case 'image/webp':
entry.type = 'image';
entry.isImage = true;
if (value === 'image/svg+xml') {
entry.isSVG = true;
}
break;
case 'video/webm':
entry.type = 'video';
entry.isVideo = true;
break;
// @see http://stackoverflow.com/questions/2871655/proper-mime-type-for-fonts
case 'application/font-wof':
case 'application/font-woff':
case 'application/vnd.ms-fontobject':
case 'application/x-font-opentype':
case 'application/x-font-truetype':
case 'application/x-font-ttf':
case 'application/x-font-woff':
case 'font/opentype':
case 'font/ttf':
case 'font/woff':
entry.type = 'webfont';
entry.isWebFont = true;
if (/ttf|truetype$/.test(value)) {
entry.isTTF = true;
}
break;
case 'application/octet-stream':
var ext = (entry.url || '').split('.').pop();
switch(ext) {
// @see http://stackoverflow.com/questions/2871655/proper-mime-type-for-fonts#comment-8077637
case 'otf':
entry.type = 'webfont';
entry.isWebFont = true;
break;
}
break;
case 'image/x-icon':
case 'image/vnd.microsoft.icon':
entry.type = 'favicon';
entry.isFavicon = true;
break;
default:
debug('Unknown content type found: ' + value + ' for <' + entry.url + '>');
}
return entry;
}
|
[
"function",
"addContentType",
"(",
"headerValue",
",",
"entry",
")",
"{",
"var",
"value",
"=",
"headerValue",
".",
"split",
"(",
"';'",
")",
".",
"shift",
"(",
")",
".",
"toLowerCase",
"(",
")",
";",
"entry",
".",
"contentType",
"=",
"value",
";",
"switch",
"(",
"value",
")",
"{",
"case",
"'text/html'",
":",
"entry",
".",
"type",
"=",
"'html'",
";",
"entry",
".",
"isHTML",
"=",
"true",
";",
"break",
";",
"case",
"'text/xml'",
":",
"entry",
".",
"type",
"=",
"'xml'",
";",
"entry",
".",
"isXML",
"=",
"true",
";",
"break",
";",
"case",
"'text/css'",
":",
"entry",
".",
"type",
"=",
"'css'",
";",
"entry",
".",
"isCSS",
"=",
"true",
";",
"break",
";",
"case",
"'application/x-javascript'",
":",
"case",
"'application/javascript'",
":",
"case",
"'text/javascript'",
":",
"entry",
".",
"type",
"=",
"'js'",
";",
"entry",
".",
"isJS",
"=",
"true",
";",
"break",
";",
"case",
"'application/json'",
":",
"entry",
".",
"type",
"=",
"'json'",
";",
"entry",
".",
"isJSON",
"=",
"true",
";",
"break",
";",
"case",
"'image/png'",
":",
"case",
"'image/jpeg'",
":",
"case",
"'image/gif'",
":",
"case",
"'image/svg+xml'",
":",
"case",
"'image/webp'",
":",
"entry",
".",
"type",
"=",
"'image'",
";",
"entry",
".",
"isImage",
"=",
"true",
";",
"if",
"(",
"value",
"===",
"'image/svg+xml'",
")",
"{",
"entry",
".",
"isSVG",
"=",
"true",
";",
"}",
"break",
";",
"case",
"'video/webm'",
":",
"entry",
".",
"type",
"=",
"'video'",
";",
"entry",
".",
"isVideo",
"=",
"true",
";",
"break",
";",
"// @see http://stackoverflow.com/questions/2871655/proper-mime-type-for-fonts",
"case",
"'application/font-wof'",
":",
"case",
"'application/font-woff'",
":",
"case",
"'application/vnd.ms-fontobject'",
":",
"case",
"'application/x-font-opentype'",
":",
"case",
"'application/x-font-truetype'",
":",
"case",
"'application/x-font-ttf'",
":",
"case",
"'application/x-font-woff'",
":",
"case",
"'font/opentype'",
":",
"case",
"'font/ttf'",
":",
"case",
"'font/woff'",
":",
"entry",
".",
"type",
"=",
"'webfont'",
";",
"entry",
".",
"isWebFont",
"=",
"true",
";",
"if",
"(",
"/",
"ttf|truetype$",
"/",
".",
"test",
"(",
"value",
")",
")",
"{",
"entry",
".",
"isTTF",
"=",
"true",
";",
"}",
"break",
";",
"case",
"'application/octet-stream'",
":",
"var",
"ext",
"=",
"(",
"entry",
".",
"url",
"||",
"''",
")",
".",
"split",
"(",
"'.'",
")",
".",
"pop",
"(",
")",
";",
"switch",
"(",
"ext",
")",
"{",
"// @see http://stackoverflow.com/questions/2871655/proper-mime-type-for-fonts#comment-8077637",
"case",
"'otf'",
":",
"entry",
".",
"type",
"=",
"'webfont'",
";",
"entry",
".",
"isWebFont",
"=",
"true",
";",
"break",
";",
"}",
"break",
";",
"case",
"'image/x-icon'",
":",
"case",
"'image/vnd.microsoft.icon'",
":",
"entry",
".",
"type",
"=",
"'favicon'",
";",
"entry",
".",
"isFavicon",
"=",
"true",
";",
"break",
";",
"default",
":",
"debug",
"(",
"'Unknown content type found: '",
"+",
"value",
"+",
"' for <'",
"+",
"entry",
".",
"url",
"+",
"'>'",
")",
";",
"}",
"return",
"entry",
";",
"}"
] |
Detect response content type using "Content-Type header value"
@param {string} headerValue
@param {object} entry
|
[
"Detect",
"response",
"content",
"type",
"using",
"Content",
"-",
"Type",
"header",
"value"
] |
ce56cdacabba1ab0672389e4e4a83b4e5ead0582
|
https://github.com/macbre/phantomas/blob/ce56cdacabba1ab0672389e4e4a83b4e5ead0582/core/modules/requestsMonitor/requestsMonitor.js#L61-L153
|
16,111
|
elderfo/react-native-storybook-loader
|
src/paths/multiResolver.js
|
hasConfigSetting
|
function hasConfigSetting(pkg, setting) {
return pkg.config && pkg.config[appName] && pkg.config[appName][setting];
}
|
javascript
|
function hasConfigSetting(pkg, setting) {
return pkg.config && pkg.config[appName] && pkg.config[appName][setting];
}
|
[
"function",
"hasConfigSetting",
"(",
"pkg",
",",
"setting",
")",
"{",
"return",
"pkg",
".",
"config",
"&&",
"pkg",
".",
"config",
"[",
"appName",
"]",
"&&",
"pkg",
".",
"config",
"[",
"appName",
"]",
"[",
"setting",
"]",
";",
"}"
] |
Verifies if the specified setting exists. Returns true if the setting exists, otherwise false.
@param {object} pkg the contents of the package.json in object form.
@param {string} setting Name of the setting to look for
|
[
"Verifies",
"if",
"the",
"specified",
"setting",
"exists",
".",
"Returns",
"true",
"if",
"the",
"setting",
"exists",
"otherwise",
"false",
"."
] |
206d632682098ba5cbfa9c45fd0e2c20580e980b
|
https://github.com/elderfo/react-native-storybook-loader/blob/206d632682098ba5cbfa9c45fd0e2c20580e980b/src/paths/multiResolver.js#L29-L31
|
16,112
|
elderfo/react-native-storybook-loader
|
src/paths/multiResolver.js
|
getConfigSetting
|
function getConfigSetting(pkg, setting, ensureArray) {
if (!hasConfigSetting(pkg, setting)) {
return null;
}
const value = pkg.config[appName][setting];
if (ensureArray && !Array.isArray(value)) {
return [value];
}
return value;
}
|
javascript
|
function getConfigSetting(pkg, setting, ensureArray) {
if (!hasConfigSetting(pkg, setting)) {
return null;
}
const value = pkg.config[appName][setting];
if (ensureArray && !Array.isArray(value)) {
return [value];
}
return value;
}
|
[
"function",
"getConfigSetting",
"(",
"pkg",
",",
"setting",
",",
"ensureArray",
")",
"{",
"if",
"(",
"!",
"hasConfigSetting",
"(",
"pkg",
",",
"setting",
")",
")",
"{",
"return",
"null",
";",
"}",
"const",
"value",
"=",
"pkg",
".",
"config",
"[",
"appName",
"]",
"[",
"setting",
"]",
";",
"if",
"(",
"ensureArray",
"&&",
"!",
"Array",
".",
"isArray",
"(",
"value",
")",
")",
"{",
"return",
"[",
"value",
"]",
";",
"}",
"return",
"value",
";",
"}"
] |
Gets the value for the specified setting if the setting exists, otherwise null
@param {object} pkg pkg the contents of the package.json in object form.
@param {string} setting setting Name of the setting to look for
@param {bool} ensureArray flag denoting whether to ensure the setting is an array
|
[
"Gets",
"the",
"value",
"for",
"the",
"specified",
"setting",
"if",
"the",
"setting",
"exists",
"otherwise",
"null"
] |
206d632682098ba5cbfa9c45fd0e2c20580e980b
|
https://github.com/elderfo/react-native-storybook-loader/blob/206d632682098ba5cbfa9c45fd0e2c20580e980b/src/paths/multiResolver.js#L39-L50
|
16,113
|
elderfo/react-native-storybook-loader
|
src/paths/multiResolver.js
|
getConfigSettings
|
function getConfigSettings(packageJsonFile) {
// Locate and read package.json
const pkg = JSON.parse(fs.readFileSync(packageJsonFile));
return {
searchDir:
getConfigSetting(pkg, 'searchDir', true) || getDefaultValue('searchDir'),
outputFile:
getConfigSetting(pkg, 'outputFile') || getDefaultValue('outputFile'),
pattern: getConfigSetting(pkg, 'pattern') || getDefaultValue('pattern'),
};
}
|
javascript
|
function getConfigSettings(packageJsonFile) {
// Locate and read package.json
const pkg = JSON.parse(fs.readFileSync(packageJsonFile));
return {
searchDir:
getConfigSetting(pkg, 'searchDir', true) || getDefaultValue('searchDir'),
outputFile:
getConfigSetting(pkg, 'outputFile') || getDefaultValue('outputFile'),
pattern: getConfigSetting(pkg, 'pattern') || getDefaultValue('pattern'),
};
}
|
[
"function",
"getConfigSettings",
"(",
"packageJsonFile",
")",
"{",
"// Locate and read package.json",
"const",
"pkg",
"=",
"JSON",
".",
"parse",
"(",
"fs",
".",
"readFileSync",
"(",
"packageJsonFile",
")",
")",
";",
"return",
"{",
"searchDir",
":",
"getConfigSetting",
"(",
"pkg",
",",
"'searchDir'",
",",
"true",
")",
"||",
"getDefaultValue",
"(",
"'searchDir'",
")",
",",
"outputFile",
":",
"getConfigSetting",
"(",
"pkg",
",",
"'outputFile'",
")",
"||",
"getDefaultValue",
"(",
"'outputFile'",
")",
",",
"pattern",
":",
"getConfigSetting",
"(",
"pkg",
",",
"'pattern'",
")",
"||",
"getDefaultValue",
"(",
"'pattern'",
")",
",",
"}",
";",
"}"
] |
Parses the package.json file and returns a config object
@param {string} packageJsonFile Path to the package.json file
|
[
"Parses",
"the",
"package",
".",
"json",
"file",
"and",
"returns",
"a",
"config",
"object"
] |
206d632682098ba5cbfa9c45fd0e2c20580e980b
|
https://github.com/elderfo/react-native-storybook-loader/blob/206d632682098ba5cbfa9c45fd0e2c20580e980b/src/paths/multiResolver.js#L56-L67
|
16,114
|
dwmkerr/angular-modal-service
|
src/angular-modal-service.js
|
function (template, templateUrl) {
var deferred = $q.defer();
if (template) {
deferred.resolve(template);
} else if (templateUrl) {
$templateRequest(templateUrl, true)
.then(function (template) {
deferred.resolve(template);
}, function (error) {
deferred.reject(error);
});
} else {
deferred.reject("No template or templateUrl has been specified.");
}
return deferred.promise;
}
|
javascript
|
function (template, templateUrl) {
var deferred = $q.defer();
if (template) {
deferred.resolve(template);
} else if (templateUrl) {
$templateRequest(templateUrl, true)
.then(function (template) {
deferred.resolve(template);
}, function (error) {
deferred.reject(error);
});
} else {
deferred.reject("No template or templateUrl has been specified.");
}
return deferred.promise;
}
|
[
"function",
"(",
"template",
",",
"templateUrl",
")",
"{",
"var",
"deferred",
"=",
"$q",
".",
"defer",
"(",
")",
";",
"if",
"(",
"template",
")",
"{",
"deferred",
".",
"resolve",
"(",
"template",
")",
";",
"}",
"else",
"if",
"(",
"templateUrl",
")",
"{",
"$templateRequest",
"(",
"templateUrl",
",",
"true",
")",
".",
"then",
"(",
"function",
"(",
"template",
")",
"{",
"deferred",
".",
"resolve",
"(",
"template",
")",
";",
"}",
",",
"function",
"(",
"error",
")",
"{",
"deferred",
".",
"reject",
"(",
"error",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"deferred",
".",
"reject",
"(",
"\"No template or templateUrl has been specified.\"",
")",
";",
"}",
"return",
"deferred",
".",
"promise",
";",
"}"
] |
Returns a promise which gets the template, either from the template parameter or via a request to the template url parameter.
|
[
"Returns",
"a",
"promise",
"which",
"gets",
"the",
"template",
"either",
"from",
"the",
"template",
"parameter",
"or",
"via",
"a",
"request",
"to",
"the",
"template",
"url",
"parameter",
"."
] |
4c2a146514c37d43c73f8454ebcba60368ae89c0
|
https://github.com/dwmkerr/angular-modal-service/blob/4c2a146514c37d43c73f8454ebcba60368ae89c0/src/angular-modal-service.js#L29-L44
|
|
16,115
|
springernature/boomcatch
|
client/boomerang-rt.js
|
function(ev) {
if (!ev) { ev = w.event; }
if (!ev) { ev = { name: "load" }; }
if(impl.onloadfired) {
return this;
}
impl.fireEvent("page_ready", ev);
impl.onloadfired = true;
return this;
}
|
javascript
|
function(ev) {
if (!ev) { ev = w.event; }
if (!ev) { ev = { name: "load" }; }
if(impl.onloadfired) {
return this;
}
impl.fireEvent("page_ready", ev);
impl.onloadfired = true;
return this;
}
|
[
"function",
"(",
"ev",
")",
"{",
"if",
"(",
"!",
"ev",
")",
"{",
"ev",
"=",
"w",
".",
"event",
";",
"}",
"if",
"(",
"!",
"ev",
")",
"{",
"ev",
"=",
"{",
"name",
":",
"\"load\"",
"}",
";",
"}",
"if",
"(",
"impl",
".",
"onloadfired",
")",
"{",
"return",
"this",
";",
"}",
"impl",
".",
"fireEvent",
"(",
"\"page_ready\"",
",",
"ev",
")",
";",
"impl",
".",
"onloadfired",
"=",
"true",
";",
"return",
"this",
";",
"}"
] |
The page dev calls this method when they determine the page is usable. Only call this if autorun is explicitly set to false
|
[
"The",
"page",
"dev",
"calls",
"this",
"method",
"when",
"they",
"determine",
"the",
"page",
"is",
"usable",
".",
"Only",
"call",
"this",
"if",
"autorun",
"is",
"explicitly",
"set",
"to",
"false"
] |
5653b382c01de7cdf22553738e87a492343f9ac4
|
https://github.com/springernature/boomcatch/blob/5653b382c01de7cdf22553738e87a492343f9ac4/client/boomerang-rt.js#L816-L825
|
|
16,116
|
springernature/boomcatch
|
client/boomerang-rt.js
|
function() {
var res, k, urls, url, startTime, data;
function trimTiming(time, st) {
// strip from microseconds to milliseconds only
var timeMs = Math.round(time ? time : 0),
startTimeMs = Math.round(st ? st : 0);
timeMs = (timeMs === 0 ? 0 : (timeMs - startTimeMs));
return timeMs ? timeMs : "";
}
if(BOOMR.t_start) {
// How long does it take Boomerang to load up and execute (fb to lb)?
BOOMR.plugins.RT.startTimer("boomerang", BOOMR.t_start);
BOOMR.plugins.RT.endTimer("boomerang", BOOMR.t_end); // t_end === null defaults to current time
// How long did it take from page request to boomerang fb?
BOOMR.plugins.RT.endTimer("boomr_fb", BOOMR.t_start);
if(BOOMR.t_lstart) {
// when did the boomerang loader start loading boomerang on the page?
BOOMR.plugins.RT.endTimer("boomr_ld", BOOMR.t_lstart);
// What was the network latency for boomerang (request to first byte)?
BOOMR.plugins.RT.setTimer("boomr_lat", BOOMR.t_start - BOOMR.t_lstart);
}
}
// use window and not w because we want the inner iframe
try
{
if (window.performance && window.performance.getEntriesByName) {
urls = { "rt.bmr": BOOMR.url };
for(url in urls) {
if(urls.hasOwnProperty(url) && urls[url]) {
res = window.performance.getEntriesByName(urls[url]);
if(!res || res.length === 0) {
continue;
}
res = res[0];
startTime = trimTiming(res.startTime, 0);
data = [
startTime,
trimTiming(res.responseEnd, startTime),
trimTiming(res.responseStart, startTime),
trimTiming(res.requestStart, startTime),
trimTiming(res.connectEnd, startTime),
trimTiming(res.secureConnectionStart, startTime),
trimTiming(res.connectStart, startTime),
trimTiming(res.domainLookupEnd, startTime),
trimTiming(res.domainLookupStart, startTime),
trimTiming(res.redirectEnd, startTime),
trimTiming(res.redirectStart, startTime)
].join(",").replace(/,+$/, "");
BOOMR.addVar(url, data);
impl.addedVars.push(url);
}
}
}
}
catch(e)
{
BOOMR.addError(e, "rt.getBoomerangTimings");
}
}
|
javascript
|
function() {
var res, k, urls, url, startTime, data;
function trimTiming(time, st) {
// strip from microseconds to milliseconds only
var timeMs = Math.round(time ? time : 0),
startTimeMs = Math.round(st ? st : 0);
timeMs = (timeMs === 0 ? 0 : (timeMs - startTimeMs));
return timeMs ? timeMs : "";
}
if(BOOMR.t_start) {
// How long does it take Boomerang to load up and execute (fb to lb)?
BOOMR.plugins.RT.startTimer("boomerang", BOOMR.t_start);
BOOMR.plugins.RT.endTimer("boomerang", BOOMR.t_end); // t_end === null defaults to current time
// How long did it take from page request to boomerang fb?
BOOMR.plugins.RT.endTimer("boomr_fb", BOOMR.t_start);
if(BOOMR.t_lstart) {
// when did the boomerang loader start loading boomerang on the page?
BOOMR.plugins.RT.endTimer("boomr_ld", BOOMR.t_lstart);
// What was the network latency for boomerang (request to first byte)?
BOOMR.plugins.RT.setTimer("boomr_lat", BOOMR.t_start - BOOMR.t_lstart);
}
}
// use window and not w because we want the inner iframe
try
{
if (window.performance && window.performance.getEntriesByName) {
urls = { "rt.bmr": BOOMR.url };
for(url in urls) {
if(urls.hasOwnProperty(url) && urls[url]) {
res = window.performance.getEntriesByName(urls[url]);
if(!res || res.length === 0) {
continue;
}
res = res[0];
startTime = trimTiming(res.startTime, 0);
data = [
startTime,
trimTiming(res.responseEnd, startTime),
trimTiming(res.responseStart, startTime),
trimTiming(res.requestStart, startTime),
trimTiming(res.connectEnd, startTime),
trimTiming(res.secureConnectionStart, startTime),
trimTiming(res.connectStart, startTime),
trimTiming(res.domainLookupEnd, startTime),
trimTiming(res.domainLookupStart, startTime),
trimTiming(res.redirectEnd, startTime),
trimTiming(res.redirectStart, startTime)
].join(",").replace(/,+$/, "");
BOOMR.addVar(url, data);
impl.addedVars.push(url);
}
}
}
}
catch(e)
{
BOOMR.addError(e, "rt.getBoomerangTimings");
}
}
|
[
"function",
"(",
")",
"{",
"var",
"res",
",",
"k",
",",
"urls",
",",
"url",
",",
"startTime",
",",
"data",
";",
"function",
"trimTiming",
"(",
"time",
",",
"st",
")",
"{",
"// strip from microseconds to milliseconds only",
"var",
"timeMs",
"=",
"Math",
".",
"round",
"(",
"time",
"?",
"time",
":",
"0",
")",
",",
"startTimeMs",
"=",
"Math",
".",
"round",
"(",
"st",
"?",
"st",
":",
"0",
")",
";",
"timeMs",
"=",
"(",
"timeMs",
"===",
"0",
"?",
"0",
":",
"(",
"timeMs",
"-",
"startTimeMs",
")",
")",
";",
"return",
"timeMs",
"?",
"timeMs",
":",
"\"\"",
";",
"}",
"if",
"(",
"BOOMR",
".",
"t_start",
")",
"{",
"// How long does it take Boomerang to load up and execute (fb to lb)?",
"BOOMR",
".",
"plugins",
".",
"RT",
".",
"startTimer",
"(",
"\"boomerang\"",
",",
"BOOMR",
".",
"t_start",
")",
";",
"BOOMR",
".",
"plugins",
".",
"RT",
".",
"endTimer",
"(",
"\"boomerang\"",
",",
"BOOMR",
".",
"t_end",
")",
";",
"// t_end === null defaults to current time",
"// How long did it take from page request to boomerang fb?",
"BOOMR",
".",
"plugins",
".",
"RT",
".",
"endTimer",
"(",
"\"boomr_fb\"",
",",
"BOOMR",
".",
"t_start",
")",
";",
"if",
"(",
"BOOMR",
".",
"t_lstart",
")",
"{",
"// when did the boomerang loader start loading boomerang on the page?",
"BOOMR",
".",
"plugins",
".",
"RT",
".",
"endTimer",
"(",
"\"boomr_ld\"",
",",
"BOOMR",
".",
"t_lstart",
")",
";",
"// What was the network latency for boomerang (request to first byte)?",
"BOOMR",
".",
"plugins",
".",
"RT",
".",
"setTimer",
"(",
"\"boomr_lat\"",
",",
"BOOMR",
".",
"t_start",
"-",
"BOOMR",
".",
"t_lstart",
")",
";",
"}",
"}",
"// use window and not w because we want the inner iframe",
"try",
"{",
"if",
"(",
"window",
".",
"performance",
"&&",
"window",
".",
"performance",
".",
"getEntriesByName",
")",
"{",
"urls",
"=",
"{",
"\"rt.bmr\"",
":",
"BOOMR",
".",
"url",
"}",
";",
"for",
"(",
"url",
"in",
"urls",
")",
"{",
"if",
"(",
"urls",
".",
"hasOwnProperty",
"(",
"url",
")",
"&&",
"urls",
"[",
"url",
"]",
")",
"{",
"res",
"=",
"window",
".",
"performance",
".",
"getEntriesByName",
"(",
"urls",
"[",
"url",
"]",
")",
";",
"if",
"(",
"!",
"res",
"||",
"res",
".",
"length",
"===",
"0",
")",
"{",
"continue",
";",
"}",
"res",
"=",
"res",
"[",
"0",
"]",
";",
"startTime",
"=",
"trimTiming",
"(",
"res",
".",
"startTime",
",",
"0",
")",
";",
"data",
"=",
"[",
"startTime",
",",
"trimTiming",
"(",
"res",
".",
"responseEnd",
",",
"startTime",
")",
",",
"trimTiming",
"(",
"res",
".",
"responseStart",
",",
"startTime",
")",
",",
"trimTiming",
"(",
"res",
".",
"requestStart",
",",
"startTime",
")",
",",
"trimTiming",
"(",
"res",
".",
"connectEnd",
",",
"startTime",
")",
",",
"trimTiming",
"(",
"res",
".",
"secureConnectionStart",
",",
"startTime",
")",
",",
"trimTiming",
"(",
"res",
".",
"connectStart",
",",
"startTime",
")",
",",
"trimTiming",
"(",
"res",
".",
"domainLookupEnd",
",",
"startTime",
")",
",",
"trimTiming",
"(",
"res",
".",
"domainLookupStart",
",",
"startTime",
")",
",",
"trimTiming",
"(",
"res",
".",
"redirectEnd",
",",
"startTime",
")",
",",
"trimTiming",
"(",
"res",
".",
"redirectStart",
",",
"startTime",
")",
"]",
".",
"join",
"(",
"\",\"",
")",
".",
"replace",
"(",
"/",
",+$",
"/",
",",
"\"\"",
")",
";",
"BOOMR",
".",
"addVar",
"(",
"url",
",",
"data",
")",
";",
"impl",
".",
"addedVars",
".",
"push",
"(",
"url",
")",
";",
"}",
"}",
"}",
"}",
"catch",
"(",
"e",
")",
"{",
"BOOMR",
".",
"addError",
"(",
"e",
",",
"\"rt.getBoomerangTimings\"",
")",
";",
"}",
"}"
] |
Figure out how long boomerang and config.js took to load using resource timing if available, or built in timestamps
|
[
"Figure",
"out",
"how",
"long",
"boomerang",
"and",
"config",
".",
"js",
"took",
"to",
"load",
"using",
"resource",
"timing",
"if",
"available",
"or",
"built",
"in",
"timestamps"
] |
5653b382c01de7cdf22553738e87a492343f9ac4
|
https://github.com/springernature/boomcatch/blob/5653b382c01de7cdf22553738e87a492343f9ac4/client/boomerang-rt.js#L1341-L1409
|
|
16,117
|
springernature/boomcatch
|
client/boomerang-rt.js
|
function() {
var ti, p, source;
if(this.navigationStart) {
return;
}
// Get start time from WebTiming API see:
// https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/NavigationTiming/Overview.html
// http://blogs.msdn.com/b/ie/archive/2010/06/28/measuring-web-page-performance.aspx
// http://blog.chromium.org/2010/07/do-you-know-how-slow-your-web-page-is.html
p = w.performance || w.msPerformance || w.webkitPerformance || w.mozPerformance;
if(p && p.navigation) {
this.navigationType = p.navigation.type;
}
if(p && p.timing) {
ti = p.timing;
}
else if(w.chrome && w.chrome.csi && w.chrome.csi().startE) {
// Older versions of chrome also have a timing API that's sort of documented here:
// http://ecmanaut.blogspot.com/2010/06/google-bom-feature-ms-since-pageload.html
// source here:
// http://src.chromium.org/viewvc/chrome/trunk/src/chrome/renderer/loadtimes_extension_bindings.cc?view=markup
ti = {
navigationStart: w.chrome.csi().startE
};
source = "csi";
}
else if(w.gtbExternal && w.gtbExternal.startE()) {
// The Google Toolbar exposes navigation start time similar to old versions of chrome
// This would work for any browser that has the google toolbar installed
ti = {
navigationStart: w.gtbExternal.startE()
};
source = "gtb";
}
if(ti) {
// Always use navigationStart since it falls back to fetchStart (not with redirects)
// If not set, we leave t_start alone so that timers that depend
// on it don't get sent back. Never use requestStart since if
// the first request fails and the browser retries, it will contain
// the value for the new request.
BOOMR.addVar("rt.start", source || "navigation");
this.navigationStart = ti.navigationStart || ti.fetchStart || undefined;
this.responseStart = ti.responseStart || undefined;
// bug in Firefox 7 & 8 https://bugzilla.mozilla.org/show_bug.cgi?id=691547
if(navigator.userAgent.match(/Firefox\/[78]\./)) {
this.navigationStart = ti.unloadEventStart || ti.fetchStart || undefined;
}
}
else {
BOOMR.warn("This browser doesn't support the WebTiming API", "rt");
}
return;
}
|
javascript
|
function() {
var ti, p, source;
if(this.navigationStart) {
return;
}
// Get start time from WebTiming API see:
// https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/NavigationTiming/Overview.html
// http://blogs.msdn.com/b/ie/archive/2010/06/28/measuring-web-page-performance.aspx
// http://blog.chromium.org/2010/07/do-you-know-how-slow-your-web-page-is.html
p = w.performance || w.msPerformance || w.webkitPerformance || w.mozPerformance;
if(p && p.navigation) {
this.navigationType = p.navigation.type;
}
if(p && p.timing) {
ti = p.timing;
}
else if(w.chrome && w.chrome.csi && w.chrome.csi().startE) {
// Older versions of chrome also have a timing API that's sort of documented here:
// http://ecmanaut.blogspot.com/2010/06/google-bom-feature-ms-since-pageload.html
// source here:
// http://src.chromium.org/viewvc/chrome/trunk/src/chrome/renderer/loadtimes_extension_bindings.cc?view=markup
ti = {
navigationStart: w.chrome.csi().startE
};
source = "csi";
}
else if(w.gtbExternal && w.gtbExternal.startE()) {
// The Google Toolbar exposes navigation start time similar to old versions of chrome
// This would work for any browser that has the google toolbar installed
ti = {
navigationStart: w.gtbExternal.startE()
};
source = "gtb";
}
if(ti) {
// Always use navigationStart since it falls back to fetchStart (not with redirects)
// If not set, we leave t_start alone so that timers that depend
// on it don't get sent back. Never use requestStart since if
// the first request fails and the browser retries, it will contain
// the value for the new request.
BOOMR.addVar("rt.start", source || "navigation");
this.navigationStart = ti.navigationStart || ti.fetchStart || undefined;
this.responseStart = ti.responseStart || undefined;
// bug in Firefox 7 & 8 https://bugzilla.mozilla.org/show_bug.cgi?id=691547
if(navigator.userAgent.match(/Firefox\/[78]\./)) {
this.navigationStart = ti.unloadEventStart || ti.fetchStart || undefined;
}
}
else {
BOOMR.warn("This browser doesn't support the WebTiming API", "rt");
}
return;
}
|
[
"function",
"(",
")",
"{",
"var",
"ti",
",",
"p",
",",
"source",
";",
"if",
"(",
"this",
".",
"navigationStart",
")",
"{",
"return",
";",
"}",
"// Get start time from WebTiming API see:",
"// https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/NavigationTiming/Overview.html",
"// http://blogs.msdn.com/b/ie/archive/2010/06/28/measuring-web-page-performance.aspx",
"// http://blog.chromium.org/2010/07/do-you-know-how-slow-your-web-page-is.html",
"p",
"=",
"w",
".",
"performance",
"||",
"w",
".",
"msPerformance",
"||",
"w",
".",
"webkitPerformance",
"||",
"w",
".",
"mozPerformance",
";",
"if",
"(",
"p",
"&&",
"p",
".",
"navigation",
")",
"{",
"this",
".",
"navigationType",
"=",
"p",
".",
"navigation",
".",
"type",
";",
"}",
"if",
"(",
"p",
"&&",
"p",
".",
"timing",
")",
"{",
"ti",
"=",
"p",
".",
"timing",
";",
"}",
"else",
"if",
"(",
"w",
".",
"chrome",
"&&",
"w",
".",
"chrome",
".",
"csi",
"&&",
"w",
".",
"chrome",
".",
"csi",
"(",
")",
".",
"startE",
")",
"{",
"// Older versions of chrome also have a timing API that's sort of documented here:",
"// http://ecmanaut.blogspot.com/2010/06/google-bom-feature-ms-since-pageload.html",
"// source here:",
"// http://src.chromium.org/viewvc/chrome/trunk/src/chrome/renderer/loadtimes_extension_bindings.cc?view=markup",
"ti",
"=",
"{",
"navigationStart",
":",
"w",
".",
"chrome",
".",
"csi",
"(",
")",
".",
"startE",
"}",
";",
"source",
"=",
"\"csi\"",
";",
"}",
"else",
"if",
"(",
"w",
".",
"gtbExternal",
"&&",
"w",
".",
"gtbExternal",
".",
"startE",
"(",
")",
")",
"{",
"// The Google Toolbar exposes navigation start time similar to old versions of chrome",
"// This would work for any browser that has the google toolbar installed",
"ti",
"=",
"{",
"navigationStart",
":",
"w",
".",
"gtbExternal",
".",
"startE",
"(",
")",
"}",
";",
"source",
"=",
"\"gtb\"",
";",
"}",
"if",
"(",
"ti",
")",
"{",
"// Always use navigationStart since it falls back to fetchStart (not with redirects)",
"// If not set, we leave t_start alone so that timers that depend",
"// on it don't get sent back. Never use requestStart since if",
"// the first request fails and the browser retries, it will contain",
"// the value for the new request.",
"BOOMR",
".",
"addVar",
"(",
"\"rt.start\"",
",",
"source",
"||",
"\"navigation\"",
")",
";",
"this",
".",
"navigationStart",
"=",
"ti",
".",
"navigationStart",
"||",
"ti",
".",
"fetchStart",
"||",
"undefined",
";",
"this",
".",
"responseStart",
"=",
"ti",
".",
"responseStart",
"||",
"undefined",
";",
"// bug in Firefox 7 & 8 https://bugzilla.mozilla.org/show_bug.cgi?id=691547",
"if",
"(",
"navigator",
".",
"userAgent",
".",
"match",
"(",
"/",
"Firefox\\/[78]\\.",
"/",
")",
")",
"{",
"this",
".",
"navigationStart",
"=",
"ti",
".",
"unloadEventStart",
"||",
"ti",
".",
"fetchStart",
"||",
"undefined",
";",
"}",
"}",
"else",
"{",
"BOOMR",
".",
"warn",
"(",
"\"This browser doesn't support the WebTiming API\"",
",",
"\"rt\"",
")",
";",
"}",
"return",
";",
"}"
] |
Initialise timers from the NavigationTiming API. This method looks at various sources for
Navigation Timing, and also patches around bugs in various browser implementations.
It sets the beacon parameter `rt.start` to the source of the timer
|
[
"Initialise",
"timers",
"from",
"the",
"NavigationTiming",
"API",
".",
"This",
"method",
"looks",
"at",
"various",
"sources",
"for",
"Navigation",
"Timing",
"and",
"also",
"patches",
"around",
"bugs",
"in",
"various",
"browser",
"implementations",
".",
"It",
"sets",
"the",
"beacon",
"parameter",
"rt",
".",
"start",
"to",
"the",
"source",
"of",
"the",
"timer"
] |
5653b382c01de7cdf22553738e87a492343f9ac4
|
https://github.com/springernature/boomcatch/blob/5653b382c01de7cdf22553738e87a492343f9ac4/client/boomerang-rt.js#L1447-L1506
|
|
16,118
|
springernature/boomcatch
|
client/boomerang-rt.js
|
function(t_now, data) {
var t_done = t_now;
// xhr beacon with detailed timing information
if (data && data.timing && data.timing.loadEventEnd) {
t_done = data.timing.loadEventEnd;
}
// Boomerang loaded late and...
else if (BOOMR.loadedLate) {
// We have navigation timing,
if(w.performance && w.performance.timing) {
// and boomerang loaded after onload fired
if(w.performance.timing.loadEventStart && w.performance.timing.loadEventStart < BOOMR.t_end) {
t_done = w.performance.timing.loadEventStart;
}
}
// We don't have navigation timing,
else {
// So we'll just use the time when boomerang was added to the page
// Assuming that this means boomerang was added in onload
t_done = BOOMR.t_lstart || BOOMR.t_start || t_now;
}
}
return t_done;
}
|
javascript
|
function(t_now, data) {
var t_done = t_now;
// xhr beacon with detailed timing information
if (data && data.timing && data.timing.loadEventEnd) {
t_done = data.timing.loadEventEnd;
}
// Boomerang loaded late and...
else if (BOOMR.loadedLate) {
// We have navigation timing,
if(w.performance && w.performance.timing) {
// and boomerang loaded after onload fired
if(w.performance.timing.loadEventStart && w.performance.timing.loadEventStart < BOOMR.t_end) {
t_done = w.performance.timing.loadEventStart;
}
}
// We don't have navigation timing,
else {
// So we'll just use the time when boomerang was added to the page
// Assuming that this means boomerang was added in onload
t_done = BOOMR.t_lstart || BOOMR.t_start || t_now;
}
}
return t_done;
}
|
[
"function",
"(",
"t_now",
",",
"data",
")",
"{",
"var",
"t_done",
"=",
"t_now",
";",
"// xhr beacon with detailed timing information",
"if",
"(",
"data",
"&&",
"data",
".",
"timing",
"&&",
"data",
".",
"timing",
".",
"loadEventEnd",
")",
"{",
"t_done",
"=",
"data",
".",
"timing",
".",
"loadEventEnd",
";",
"}",
"// Boomerang loaded late and...",
"else",
"if",
"(",
"BOOMR",
".",
"loadedLate",
")",
"{",
"// We have navigation timing,",
"if",
"(",
"w",
".",
"performance",
"&&",
"w",
".",
"performance",
".",
"timing",
")",
"{",
"// and boomerang loaded after onload fired",
"if",
"(",
"w",
".",
"performance",
".",
"timing",
".",
"loadEventStart",
"&&",
"w",
".",
"performance",
".",
"timing",
".",
"loadEventStart",
"<",
"BOOMR",
".",
"t_end",
")",
"{",
"t_done",
"=",
"w",
".",
"performance",
".",
"timing",
".",
"loadEventStart",
";",
"}",
"}",
"// We don't have navigation timing,",
"else",
"{",
"// So we'll just use the time when boomerang was added to the page",
"// Assuming that this means boomerang was added in onload",
"t_done",
"=",
"BOOMR",
".",
"t_lstart",
"||",
"BOOMR",
".",
"t_start",
"||",
"t_now",
";",
"}",
"}",
"return",
"t_done",
";",
"}"
] |
Validate that the time we think is the load time is correct. This can be wrong if boomerang was loaded
after onload, so in that case, if navigation timing is available, we use that instead.
|
[
"Validate",
"that",
"the",
"time",
"we",
"think",
"is",
"the",
"load",
"time",
"is",
"correct",
".",
"This",
"can",
"be",
"wrong",
"if",
"boomerang",
"was",
"loaded",
"after",
"onload",
"so",
"in",
"that",
"case",
"if",
"navigation",
"timing",
"is",
"available",
"we",
"use",
"that",
"instead",
"."
] |
5653b382c01de7cdf22553738e87a492343f9ac4
|
https://github.com/springernature/boomcatch/blob/5653b382c01de7cdf22553738e87a492343f9ac4/client/boomerang-rt.js#L1512-L1537
|
|
16,119
|
springernature/boomcatch
|
client/boomerang-rt.js
|
function(ename, data) {
var t_start;
if(ename==="xhr") {
if(data && data.name && impl.timers[data.name]) {
// For xhr timers, t_start is stored in impl.timers.xhr_{page group name}
// and xhr.pg is set to {page group name}
t_start = impl.timers[data.name].start;
}
else if(data && data.timing && data.timing.requestStart) {
// For automatically instrumented xhr timers, we have detailed timing information
t_start = data.timing.requestStart;
}
BOOMR.addVar("rt.start", "manual");
}
else if(impl.navigationStart) {
t_start = impl.navigationStart;
}
else if(impl.t_start && impl.navigationType !== 2) {
t_start = impl.t_start; // 2 is TYPE_BACK_FORWARD but the constant may not be defined across browsers
BOOMR.addVar("rt.start", "cookie"); // if the user hit the back button, referrer will match, and cookie will match
} // but will have time of previous page start, so t_done will be wrong
else if(impl.cached_t_start) {
t_start = impl.cached_t_start;
}
else {
BOOMR.addVar("rt.start", "none");
t_start = undefined; // force all timers to NaN state
}
BOOMR.debug("Got start time: " + t_start, "rt");
impl.cached_t_start = t_start;
return t_start;
}
|
javascript
|
function(ename, data) {
var t_start;
if(ename==="xhr") {
if(data && data.name && impl.timers[data.name]) {
// For xhr timers, t_start is stored in impl.timers.xhr_{page group name}
// and xhr.pg is set to {page group name}
t_start = impl.timers[data.name].start;
}
else if(data && data.timing && data.timing.requestStart) {
// For automatically instrumented xhr timers, we have detailed timing information
t_start = data.timing.requestStart;
}
BOOMR.addVar("rt.start", "manual");
}
else if(impl.navigationStart) {
t_start = impl.navigationStart;
}
else if(impl.t_start && impl.navigationType !== 2) {
t_start = impl.t_start; // 2 is TYPE_BACK_FORWARD but the constant may not be defined across browsers
BOOMR.addVar("rt.start", "cookie"); // if the user hit the back button, referrer will match, and cookie will match
} // but will have time of previous page start, so t_done will be wrong
else if(impl.cached_t_start) {
t_start = impl.cached_t_start;
}
else {
BOOMR.addVar("rt.start", "none");
t_start = undefined; // force all timers to NaN state
}
BOOMR.debug("Got start time: " + t_start, "rt");
impl.cached_t_start = t_start;
return t_start;
}
|
[
"function",
"(",
"ename",
",",
"data",
")",
"{",
"var",
"t_start",
";",
"if",
"(",
"ename",
"===",
"\"xhr\"",
")",
"{",
"if",
"(",
"data",
"&&",
"data",
".",
"name",
"&&",
"impl",
".",
"timers",
"[",
"data",
".",
"name",
"]",
")",
"{",
"// For xhr timers, t_start is stored in impl.timers.xhr_{page group name}",
"// and xhr.pg is set to {page group name}",
"t_start",
"=",
"impl",
".",
"timers",
"[",
"data",
".",
"name",
"]",
".",
"start",
";",
"}",
"else",
"if",
"(",
"data",
"&&",
"data",
".",
"timing",
"&&",
"data",
".",
"timing",
".",
"requestStart",
")",
"{",
"// For automatically instrumented xhr timers, we have detailed timing information",
"t_start",
"=",
"data",
".",
"timing",
".",
"requestStart",
";",
"}",
"BOOMR",
".",
"addVar",
"(",
"\"rt.start\"",
",",
"\"manual\"",
")",
";",
"}",
"else",
"if",
"(",
"impl",
".",
"navigationStart",
")",
"{",
"t_start",
"=",
"impl",
".",
"navigationStart",
";",
"}",
"else",
"if",
"(",
"impl",
".",
"t_start",
"&&",
"impl",
".",
"navigationType",
"!==",
"2",
")",
"{",
"t_start",
"=",
"impl",
".",
"t_start",
";",
"// 2 is TYPE_BACK_FORWARD but the constant may not be defined across browsers",
"BOOMR",
".",
"addVar",
"(",
"\"rt.start\"",
",",
"\"cookie\"",
")",
";",
"// if the user hit the back button, referrer will match, and cookie will match",
"}",
"// but will have time of previous page start, so t_done will be wrong",
"else",
"if",
"(",
"impl",
".",
"cached_t_start",
")",
"{",
"t_start",
"=",
"impl",
".",
"cached_t_start",
";",
"}",
"else",
"{",
"BOOMR",
".",
"addVar",
"(",
"\"rt.start\"",
",",
"\"none\"",
")",
";",
"t_start",
"=",
"undefined",
";",
"// force all timers to NaN state",
"}",
"BOOMR",
".",
"debug",
"(",
"\"Got start time: \"",
"+",
"t_start",
",",
"\"rt\"",
")",
";",
"impl",
".",
"cached_t_start",
"=",
"t_start",
";",
"return",
"t_start",
";",
"}"
] |
Determines the best value to use for t_start.
If called from an xhr call, then use the start time for that call
Else, If we have navigation timing, use that
Else, If we have a cookie time, and this isn't the result of a BACK button, use the cookie time
Else, if we have a cached timestamp from an earlier call, use that
Else, give up
@param ename The event name that resulted in this call. Special consideration for "xhr"
@param data Data passed in from the event caller. If the event name is "xhr",
this should contain the page group name for the xhr call in an attribute called `name`
and optionally, detailed timing information in a sub-object called `timing`
and resource information in a sub-object called `resource`
@returns the determined value of t_start or undefined if unknown
|
[
"Determines",
"the",
"best",
"value",
"to",
"use",
"for",
"t_start",
".",
"If",
"called",
"from",
"an",
"xhr",
"call",
"then",
"use",
"the",
"start",
"time",
"for",
"that",
"call",
"Else",
"If",
"we",
"have",
"navigation",
"timing",
"use",
"that",
"Else",
"If",
"we",
"have",
"a",
"cookie",
"time",
"and",
"this",
"isn",
"t",
"the",
"result",
"of",
"a",
"BACK",
"button",
"use",
"the",
"cookie",
"time",
"Else",
"if",
"we",
"have",
"a",
"cached",
"timestamp",
"from",
"an",
"earlier",
"call",
"use",
"that",
"Else",
"give",
"up"
] |
5653b382c01de7cdf22553738e87a492343f9ac4
|
https://github.com/springernature/boomcatch/blob/5653b382c01de7cdf22553738e87a492343f9ac4/client/boomerang-rt.js#L1645-L1678
|
|
16,120
|
ember-animation/liquid-fire
|
addon/constraints.js
|
intersection
|
function intersection(sets) {
let source = sets[0];
let rest = sets.slice(1);
let keys = Object.keys(source);
let keysLength = keys.length;
let restLength = rest.length;
let result = [];
for (let keyIndex = 0; keyIndex < keysLength; keyIndex++) {
let key = keys[keyIndex];
let matched = true;
for (let restIndex = 0; restIndex < restLength; restIndex++) {
if (!rest[restIndex].hasOwnProperty(key)) {
matched = false;
break;
}
}
if (matched) {
result.push(source[key]);
}
}
return result;
}
|
javascript
|
function intersection(sets) {
let source = sets[0];
let rest = sets.slice(1);
let keys = Object.keys(source);
let keysLength = keys.length;
let restLength = rest.length;
let result = [];
for (let keyIndex = 0; keyIndex < keysLength; keyIndex++) {
let key = keys[keyIndex];
let matched = true;
for (let restIndex = 0; restIndex < restLength; restIndex++) {
if (!rest[restIndex].hasOwnProperty(key)) {
matched = false;
break;
}
}
if (matched) {
result.push(source[key]);
}
}
return result;
}
|
[
"function",
"intersection",
"(",
"sets",
")",
"{",
"let",
"source",
"=",
"sets",
"[",
"0",
"]",
";",
"let",
"rest",
"=",
"sets",
".",
"slice",
"(",
"1",
")",
";",
"let",
"keys",
"=",
"Object",
".",
"keys",
"(",
"source",
")",
";",
"let",
"keysLength",
"=",
"keys",
".",
"length",
";",
"let",
"restLength",
"=",
"rest",
".",
"length",
";",
"let",
"result",
"=",
"[",
"]",
";",
"for",
"(",
"let",
"keyIndex",
"=",
"0",
";",
"keyIndex",
"<",
"keysLength",
";",
"keyIndex",
"++",
")",
"{",
"let",
"key",
"=",
"keys",
"[",
"keyIndex",
"]",
";",
"let",
"matched",
"=",
"true",
";",
"for",
"(",
"let",
"restIndex",
"=",
"0",
";",
"restIndex",
"<",
"restLength",
";",
"restIndex",
"++",
")",
"{",
"if",
"(",
"!",
"rest",
"[",
"restIndex",
"]",
".",
"hasOwnProperty",
"(",
"key",
")",
")",
"{",
"matched",
"=",
"false",
";",
"break",
";",
"}",
"}",
"if",
"(",
"matched",
")",
"{",
"result",
".",
"push",
"(",
"source",
"[",
"key",
"]",
")",
";",
"}",
"}",
"return",
"result",
";",
"}"
] |
Returns a list of property values from source whose keys also appear in all of the rest objects.
|
[
"Returns",
"a",
"list",
"of",
"property",
"values",
"from",
"source",
"whose",
"keys",
"also",
"appear",
"in",
"all",
"of",
"the",
"rest",
"objects",
"."
] |
ab0ce05b6db2bd96dedaa1917b68460cf4f71a57
|
https://github.com/ember-animation/liquid-fire/blob/ab0ce05b6db2bd96dedaa1917b68460cf4f71a57/addon/constraints.js#L187-L208
|
16,121
|
ember-animation/liquid-fire
|
addon/running-transition.js
|
publicAnimationContext
|
function publicAnimationContext(rt, versions) {
let c = {};
addPublicVersion(c, 'new', versions[0]);
if (versions[1]) {
addPublicVersion(c, 'old', versions[1]);
}
c.older = versions.slice(2).map((v) => {
let context = {};
addPublicVersion(context, null, v);
return context;
});
// Animations are allowed to look each other up.
c.lookup = function(name) {
return rt.transitionMap.lookup(name);
};
return c;
}
|
javascript
|
function publicAnimationContext(rt, versions) {
let c = {};
addPublicVersion(c, 'new', versions[0]);
if (versions[1]) {
addPublicVersion(c, 'old', versions[1]);
}
c.older = versions.slice(2).map((v) => {
let context = {};
addPublicVersion(context, null, v);
return context;
});
// Animations are allowed to look each other up.
c.lookup = function(name) {
return rt.transitionMap.lookup(name);
};
return c;
}
|
[
"function",
"publicAnimationContext",
"(",
"rt",
",",
"versions",
")",
"{",
"let",
"c",
"=",
"{",
"}",
";",
"addPublicVersion",
"(",
"c",
",",
"'new'",
",",
"versions",
"[",
"0",
"]",
")",
";",
"if",
"(",
"versions",
"[",
"1",
"]",
")",
"{",
"addPublicVersion",
"(",
"c",
",",
"'old'",
",",
"versions",
"[",
"1",
"]",
")",
";",
"}",
"c",
".",
"older",
"=",
"versions",
".",
"slice",
"(",
"2",
")",
".",
"map",
"(",
"(",
"v",
")",
"=>",
"{",
"let",
"context",
"=",
"{",
"}",
";",
"addPublicVersion",
"(",
"context",
",",
"null",
",",
"v",
")",
";",
"return",
"context",
";",
"}",
")",
";",
"// Animations are allowed to look each other up.",
"c",
".",
"lookup",
"=",
"function",
"(",
"name",
")",
"{",
"return",
"rt",
".",
"transitionMap",
".",
"lookup",
"(",
"name",
")",
";",
"}",
";",
"return",
"c",
";",
"}"
] |
This defines the public set of things that user's transition implementations can access as `this`.
|
[
"This",
"defines",
"the",
"public",
"set",
"of",
"things",
"that",
"user",
"s",
"transition",
"implementations",
"can",
"access",
"as",
"this",
"."
] |
ab0ce05b6db2bd96dedaa1917b68460cf4f71a57
|
https://github.com/ember-animation/liquid-fire/blob/ab0ce05b6db2bd96dedaa1917b68460cf4f71a57/addon/running-transition.js#L45-L63
|
16,122
|
chuckfairy/node-webcam
|
src/Webcam.js
|
function( index, callback ) {
var scope = this;
var shot = scope.shots[ index|0 ];
if( ! shot ) {
throw new Error(
"Shot number " + index + " not found"
);
return;
}
return shot;
}
|
javascript
|
function( index, callback ) {
var scope = this;
var shot = scope.shots[ index|0 ];
if( ! shot ) {
throw new Error(
"Shot number " + index + " not found"
);
return;
}
return shot;
}
|
[
"function",
"(",
"index",
",",
"callback",
")",
"{",
"var",
"scope",
"=",
"this",
";",
"var",
"shot",
"=",
"scope",
".",
"shots",
"[",
"index",
"|",
"0",
"]",
";",
"if",
"(",
"!",
"shot",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"Shot number \"",
"+",
"index",
"+",
"\" not found\"",
")",
";",
"return",
";",
"}",
"return",
"shot",
";",
"}"
] |
Get shot instances from cache index
@method getShot
@param {Number} shot Index of shots called
@param {Function} callback Returns a call from FS.readFile data
@throws Error if shot at index not found
@return {Boolean}
|
[
"Get",
"shot",
"instances",
"from",
"cache",
"index"
] |
263d66bbab6ccdfd79e31245ca7aefa8f4ee530c
|
https://github.com/chuckfairy/node-webcam/blob/263d66bbab6ccdfd79e31245ca7aefa8f4ee530c/src/Webcam.js#L281-L299
|
|
16,123
|
chuckfairy/node-webcam
|
src/Webcam.js
|
function( shot, callback ) {
var scope = this;
if( typeof( shot ) === "number" ) {
shot = scope.getShot( shot );
}
if( shot.location ) {
FS.readFile( shot.location, function( err, data ) {
callback( err, data );
});
} else if( ! shot.data ) {
callback(
new Error( "Shot not valid" )
);
} else {
callback( null, shot.data );
}
}
|
javascript
|
function( shot, callback ) {
var scope = this;
if( typeof( shot ) === "number" ) {
shot = scope.getShot( shot );
}
if( shot.location ) {
FS.readFile( shot.location, function( err, data ) {
callback( err, data );
});
} else if( ! shot.data ) {
callback(
new Error( "Shot not valid" )
);
} else {
callback( null, shot.data );
}
}
|
[
"function",
"(",
"shot",
",",
"callback",
")",
"{",
"var",
"scope",
"=",
"this",
";",
"if",
"(",
"typeof",
"(",
"shot",
")",
"===",
"\"number\"",
")",
"{",
"shot",
"=",
"scope",
".",
"getShot",
"(",
"shot",
")",
";",
"}",
"if",
"(",
"shot",
".",
"location",
")",
"{",
"FS",
".",
"readFile",
"(",
"shot",
".",
"location",
",",
"function",
"(",
"err",
",",
"data",
")",
"{",
"callback",
"(",
"err",
",",
"data",
")",
";",
"}",
")",
";",
"}",
"else",
"if",
"(",
"!",
"shot",
".",
"data",
")",
"{",
"callback",
"(",
"new",
"Error",
"(",
"\"Shot not valid\"",
")",
")",
";",
"}",
"else",
"{",
"callback",
"(",
"null",
",",
"shot",
".",
"data",
")",
";",
"}",
"}"
] |
Get shot buffer from location
0 indexed
@method getShotBuffer
@param {Number} shot Index of shots called
@param {Function} callback Returns a call from FS.readFile data
@return {Boolean}
|
[
"Get",
"shot",
"buffer",
"from",
"location",
"0",
"indexed"
] |
263d66bbab6ccdfd79e31245ca7aefa8f4ee530c
|
https://github.com/chuckfairy/node-webcam/blob/263d66bbab6ccdfd79e31245ca7aefa8f4ee530c/src/Webcam.js#L342-L372
|
|
16,124
|
chuckfairy/node-webcam
|
src/Webcam.js
|
function( shot, callback ) {
var scope = this;
scope.getShotBuffer( shot, function( err, data ) {
if( err ) {
callback( err );
return;
}
var base64 = scope.getBase64FromBuffer( data );
callback( null, base64 );
});
}
|
javascript
|
function( shot, callback ) {
var scope = this;
scope.getShotBuffer( shot, function( err, data ) {
if( err ) {
callback( err );
return;
}
var base64 = scope.getBase64FromBuffer( data );
callback( null, base64 );
});
}
|
[
"function",
"(",
"shot",
",",
"callback",
")",
"{",
"var",
"scope",
"=",
"this",
";",
"scope",
".",
"getShotBuffer",
"(",
"shot",
",",
"function",
"(",
"err",
",",
"data",
")",
"{",
"if",
"(",
"err",
")",
"{",
"callback",
"(",
"err",
")",
";",
"return",
";",
"}",
"var",
"base64",
"=",
"scope",
".",
"getBase64FromBuffer",
"(",
"data",
")",
";",
"callback",
"(",
"null",
",",
"base64",
")",
";",
"}",
")",
";",
"}"
] |
Get shot base64 as image
if passed Number will return a base 64 in the callback
@method getBase64
@param {Number|FS.readFile} shot To be converted
@param {Function( Error|null, Mixed )} callback Returns base64 string
@return {String} Dont use
|
[
"Get",
"shot",
"base64",
"as",
"image",
"if",
"passed",
"Number",
"will",
"return",
"a",
"base",
"64",
"in",
"the",
"callback"
] |
263d66bbab6ccdfd79e31245ca7aefa8f4ee530c
|
https://github.com/chuckfairy/node-webcam/blob/263d66bbab6ccdfd79e31245ca7aefa8f4ee530c/src/Webcam.js#L410-L430
|
|
16,125
|
chuckfairy/node-webcam
|
src/Webcam.js
|
function( shotBuffer ) {
var scope = this;
var image = "data:image/"
+ scope.opts.output
+ ";base64,"
+ new Buffer( shotBuffer ).toString( "base64" );
return image;
}
|
javascript
|
function( shotBuffer ) {
var scope = this;
var image = "data:image/"
+ scope.opts.output
+ ";base64,"
+ new Buffer( shotBuffer ).toString( "base64" );
return image;
}
|
[
"function",
"(",
"shotBuffer",
")",
"{",
"var",
"scope",
"=",
"this",
";",
"var",
"image",
"=",
"\"data:image/\"",
"+",
"scope",
".",
"opts",
".",
"output",
"+",
"\";base64,\"",
"+",
"new",
"Buffer",
"(",
"shotBuffer",
")",
".",
"toString",
"(",
"\"base64\"",
")",
";",
"return",
"image",
";",
"}"
] |
Get base64 string from bufer
@method getBase64
@param {Number|FS.readFile} shot To be converted
@param {Function( Error|null, Mixed )} callback Returns base64 string
@return {String} Dont use
|
[
"Get",
"base64",
"string",
"from",
"bufer"
] |
263d66bbab6ccdfd79e31245ca7aefa8f4ee530c
|
https://github.com/chuckfairy/node-webcam/blob/263d66bbab6ccdfd79e31245ca7aefa8f4ee530c/src/Webcam.js#L445-L456
|
|
16,126
|
chuckfairy/node-webcam
|
src/Webcam.js
|
function( callback ) {
var scope = this;
if( ! scope.shots.length ) {
callback && callback( new Error( "Camera has no last shot" ) );
}
scope.getBase64( scope.shots.length - 1, callback );
}
|
javascript
|
function( callback ) {
var scope = this;
if( ! scope.shots.length ) {
callback && callback( new Error( "Camera has no last shot" ) );
}
scope.getBase64( scope.shots.length - 1, callback );
}
|
[
"function",
"(",
"callback",
")",
"{",
"var",
"scope",
"=",
"this",
";",
"if",
"(",
"!",
"scope",
".",
"shots",
".",
"length",
")",
"{",
"callback",
"&&",
"callback",
"(",
"new",
"Error",
"(",
"\"Camera has no last shot\"",
")",
")",
";",
"}",
"scope",
".",
"getBase64",
"(",
"scope",
".",
"shots",
".",
"length",
"-",
"1",
",",
"callback",
")",
";",
"}"
] |
Get last shot taken base 64 string
@method getLastShot64
@param {Function} callback
|
[
"Get",
"last",
"shot",
"taken",
"base",
"64",
"string"
] |
263d66bbab6ccdfd79e31245ca7aefa8f4ee530c
|
https://github.com/chuckfairy/node-webcam/blob/263d66bbab6ccdfd79e31245ca7aefa8f4ee530c/src/Webcam.js#L468-L480
|
|
16,127
|
ruipgil/scraperjs
|
src/ScraperPromise.js
|
function(code, callback) {
if (typeof code == 'function') {
callback = code;
this.promises.push(function onGenericStatusCode(done, utils) {
done(null, callback(this.scraper.getStatusCode(), utils));
});
} else {
this.promises.push(function onStatusCode(done, utils) {
if (code === this.scraper.getStatusCode()) {
done(null, callback(utils));
} else {
done(null, utils.lastReturn);
}
});
}
return this;
}
|
javascript
|
function(code, callback) {
if (typeof code == 'function') {
callback = code;
this.promises.push(function onGenericStatusCode(done, utils) {
done(null, callback(this.scraper.getStatusCode(), utils));
});
} else {
this.promises.push(function onStatusCode(done, utils) {
if (code === this.scraper.getStatusCode()) {
done(null, callback(utils));
} else {
done(null, utils.lastReturn);
}
});
}
return this;
}
|
[
"function",
"(",
"code",
",",
"callback",
")",
"{",
"if",
"(",
"typeof",
"code",
"==",
"'function'",
")",
"{",
"callback",
"=",
"code",
";",
"this",
".",
"promises",
".",
"push",
"(",
"function",
"onGenericStatusCode",
"(",
"done",
",",
"utils",
")",
"{",
"done",
"(",
"null",
",",
"callback",
"(",
"this",
".",
"scraper",
".",
"getStatusCode",
"(",
")",
",",
"utils",
")",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"this",
".",
"promises",
".",
"push",
"(",
"function",
"onStatusCode",
"(",
"done",
",",
"utils",
")",
"{",
"if",
"(",
"code",
"===",
"this",
".",
"scraper",
".",
"getStatusCode",
"(",
")",
")",
"{",
"done",
"(",
"null",
",",
"callback",
"(",
"utils",
")",
")",
";",
"}",
"else",
"{",
"done",
"(",
"null",
",",
"utils",
".",
"lastReturn",
")",
";",
"}",
"}",
")",
";",
"}",
"return",
"this",
";",
"}"
] |
Sets a promise for a status code, of a response of a request.
@param {!(number|function(number))} code Status code to
dispatch the message. Or a callback function, in this case
the function's first parameter is the status code, as a
number.
@param {!function()} callback Callback function for the case
where the status code is provided.
@return {!ScraperPromise} This object, so that new promises can
be made.
@public
|
[
"Sets",
"a",
"promise",
"for",
"a",
"status",
"code",
"of",
"a",
"response",
"of",
"a",
"request",
"."
] |
4ae680b84ffb40bc0b5ee70b00a955ea5368bc18
|
https://github.com/ruipgil/scraperjs/blob/4ae680b84ffb40bc0b5ee70b00a955ea5368bc18/src/ScraperPromise.js#L65-L82
|
|
16,128
|
ruipgil/scraperjs
|
src/ScraperPromise.js
|
function(scrapeFn, callback) {
var stackTrace = new Error().stack;
var extraArguments = Array.prototype.slice.call(arguments, 2);
callback = callback || function(result) {
return result;
};
this.promises.push(function scrape(done, utils) {
this.scraper.scrape(scrapeFn, function(err, result) {
if (err) {
done(err, undefined);
} else {
done(null, callback(result, utils));
}
}, extraArguments, stackTrace);
});
return this;
}
|
javascript
|
function(scrapeFn, callback) {
var stackTrace = new Error().stack;
var extraArguments = Array.prototype.slice.call(arguments, 2);
callback = callback || function(result) {
return result;
};
this.promises.push(function scrape(done, utils) {
this.scraper.scrape(scrapeFn, function(err, result) {
if (err) {
done(err, undefined);
} else {
done(null, callback(result, utils));
}
}, extraArguments, stackTrace);
});
return this;
}
|
[
"function",
"(",
"scrapeFn",
",",
"callback",
")",
"{",
"var",
"stackTrace",
"=",
"new",
"Error",
"(",
")",
".",
"stack",
";",
"var",
"extraArguments",
"=",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
",",
"2",
")",
";",
"callback",
"=",
"callback",
"||",
"function",
"(",
"result",
")",
"{",
"return",
"result",
";",
"}",
";",
"this",
".",
"promises",
".",
"push",
"(",
"function",
"scrape",
"(",
"done",
",",
"utils",
")",
"{",
"this",
".",
"scraper",
".",
"scrape",
"(",
"scrapeFn",
",",
"function",
"(",
"err",
",",
"result",
")",
"{",
"if",
"(",
"err",
")",
"{",
"done",
"(",
"err",
",",
"undefined",
")",
";",
"}",
"else",
"{",
"done",
"(",
"null",
",",
"callback",
"(",
"result",
",",
"utils",
")",
")",
";",
"}",
"}",
",",
"extraArguments",
",",
"stackTrace",
")",
";",
"}",
")",
";",
"return",
"this",
";",
"}"
] |
Sets a promise to scrape the retrieved webpage.
@param {!function(?, ?)} scrapeFn Function to scrape the
webpage. The parameters depend on what kind of scraper.
@param {!function(?)=} callback Callback function with the
result of the scraping function. If none is provided, the
result can be accessed in the next promise with
<code>utils.lastReturn</code>.
@param {...?} var_args Optional arguments to pass as
parameters to the scraping function.
@return {!ScraperPromise} This object, so that new promises can
be made.
@public
|
[
"Sets",
"a",
"promise",
"to",
"scrape",
"the",
"retrieved",
"webpage",
"."
] |
4ae680b84ffb40bc0b5ee70b00a955ea5368bc18
|
https://github.com/ruipgil/scraperjs/blob/4ae680b84ffb40bc0b5ee70b00a955ea5368bc18/src/ScraperPromise.js#L98-L115
|
|
16,129
|
ruipgil/scraperjs
|
src/ScraperPromise.js
|
function(time, callback) {
callback = callback || function() {};
this.promises.push(function delay(done, utils) {
setTimeout(function() {
done(null, callback(utils));
}, time);
});
return this;
}
|
javascript
|
function(time, callback) {
callback = callback || function() {};
this.promises.push(function delay(done, utils) {
setTimeout(function() {
done(null, callback(utils));
}, time);
});
return this;
}
|
[
"function",
"(",
"time",
",",
"callback",
")",
"{",
"callback",
"=",
"callback",
"||",
"function",
"(",
")",
"{",
"}",
";",
"this",
".",
"promises",
".",
"push",
"(",
"function",
"delay",
"(",
"done",
",",
"utils",
")",
"{",
"setTimeout",
"(",
"function",
"(",
")",
"{",
"done",
"(",
"null",
",",
"callback",
"(",
"utils",
")",
")",
";",
"}",
",",
"time",
")",
";",
"}",
")",
";",
"return",
"this",
";",
"}"
] |
Sets a promise to delay the execution of the promises.
@param {!number} time Time in milliseconds to delay the
execution.
@param {!function()=} callback Function to call after the
delay.
@return {!ScraperPromise} This object, so that new promises can
be made.
@public
|
[
"Sets",
"a",
"promise",
"to",
"delay",
"the",
"execution",
"of",
"the",
"promises",
"."
] |
4ae680b84ffb40bc0b5ee70b00a955ea5368bc18
|
https://github.com/ruipgil/scraperjs/blob/4ae680b84ffb40bc0b5ee70b00a955ea5368bc18/src/ScraperPromise.js#L127-L135
|
|
16,130
|
ruipgil/scraperjs
|
src/ScraperPromise.js
|
function(callback) {
this.promises.push(function then(done, utils) {
done(null, callback(utils.lastReturn, utils));
});
return this;
}
|
javascript
|
function(callback) {
this.promises.push(function then(done, utils) {
done(null, callback(utils.lastReturn, utils));
});
return this;
}
|
[
"function",
"(",
"callback",
")",
"{",
"this",
".",
"promises",
".",
"push",
"(",
"function",
"then",
"(",
"done",
",",
"utils",
")",
"{",
"done",
"(",
"null",
",",
"callback",
"(",
"utils",
".",
"lastReturn",
",",
"utils",
")",
")",
";",
"}",
")",
";",
"return",
"this",
";",
"}"
] |
Sets a generic promise.
@param {!function()} callback Callback.
@return {!ScraperPromise} This object, so that new promises can
be made.
@public
|
[
"Sets",
"a",
"generic",
"promise",
"."
] |
4ae680b84ffb40bc0b5ee70b00a955ea5368bc18
|
https://github.com/ruipgil/scraperjs/blob/4ae680b84ffb40bc0b5ee70b00a955ea5368bc18/src/ScraperPromise.js#L178-L183
|
|
16,131
|
ruipgil/scraperjs
|
src/ScraperPromise.js
|
function(callback) {
this.promises.push(function async(done, utils) {
callback(utils.lastReturn, done, utils);
});
return this;
}
|
javascript
|
function(callback) {
this.promises.push(function async(done, utils) {
callback(utils.lastReturn, done, utils);
});
return this;
}
|
[
"function",
"(",
"callback",
")",
"{",
"this",
".",
"promises",
".",
"push",
"(",
"function",
"async",
"(",
"done",
",",
"utils",
")",
"{",
"callback",
"(",
"utils",
".",
"lastReturn",
",",
"done",
",",
"utils",
")",
";",
"}",
")",
";",
"return",
"this",
";",
"}"
] |
Stops the promise chain and resumes it after a callback
function.
@param {!function(!function, !Object)} callback Callback.
@return {!ScraperPromise} This object, so that new promises can
be made.
@public
|
[
"Stops",
"the",
"promise",
"chain",
"and",
"resumes",
"it",
"after",
"a",
"callback",
"function",
"."
] |
4ae680b84ffb40bc0b5ee70b00a955ea5368bc18
|
https://github.com/ruipgil/scraperjs/blob/4ae680b84ffb40bc0b5ee70b00a955ea5368bc18/src/ScraperPromise.js#L193-L198
|
|
16,132
|
ruipgil/scraperjs
|
src/ScraperPromise.js
|
function(error) {
var that = this,
param = this.chainParameter,
stopPointer = {},
utils = {
stop: null,
url: this.scraper.url,
scraper: this,
params: param,
lastReturn: undefined
},
keep = true;
this.chainParameter = null;
if (error) {
this.errorCallback(error, utils);
this.doneCallback(utils);
return;
}
async.eachSeries(this.promises, function dispatcher(fn, callback) {
var done = function(err, lastReturn) {
utils.lastReturn = lastReturn;
if (err === stopPointer) {
keep = false;
callback(err);
} else if (err) {
callback(err);
} else if (keep) {
callback();
}
};
utils.stop = function() {
done(stopPointer, null);
};
try {
fn.call(that, done, utils);
} catch (err) {
done(err, null);
}
}, function(err) {
utils.stop = null;
if (err && err !== stopPointer) {
that.errorCallback(err, utils);
}
that.doneCallback(utils.lastReturn, utils);
that.scraper.close();
});
}
|
javascript
|
function(error) {
var that = this,
param = this.chainParameter,
stopPointer = {},
utils = {
stop: null,
url: this.scraper.url,
scraper: this,
params: param,
lastReturn: undefined
},
keep = true;
this.chainParameter = null;
if (error) {
this.errorCallback(error, utils);
this.doneCallback(utils);
return;
}
async.eachSeries(this.promises, function dispatcher(fn, callback) {
var done = function(err, lastReturn) {
utils.lastReturn = lastReturn;
if (err === stopPointer) {
keep = false;
callback(err);
} else if (err) {
callback(err);
} else if (keep) {
callback();
}
};
utils.stop = function() {
done(stopPointer, null);
};
try {
fn.call(that, done, utils);
} catch (err) {
done(err, null);
}
}, function(err) {
utils.stop = null;
if (err && err !== stopPointer) {
that.errorCallback(err, utils);
}
that.doneCallback(utils.lastReturn, utils);
that.scraper.close();
});
}
|
[
"function",
"(",
"error",
")",
"{",
"var",
"that",
"=",
"this",
",",
"param",
"=",
"this",
".",
"chainParameter",
",",
"stopPointer",
"=",
"{",
"}",
",",
"utils",
"=",
"{",
"stop",
":",
"null",
",",
"url",
":",
"this",
".",
"scraper",
".",
"url",
",",
"scraper",
":",
"this",
",",
"params",
":",
"param",
",",
"lastReturn",
":",
"undefined",
"}",
",",
"keep",
"=",
"true",
";",
"this",
".",
"chainParameter",
"=",
"null",
";",
"if",
"(",
"error",
")",
"{",
"this",
".",
"errorCallback",
"(",
"error",
",",
"utils",
")",
";",
"this",
".",
"doneCallback",
"(",
"utils",
")",
";",
"return",
";",
"}",
"async",
".",
"eachSeries",
"(",
"this",
".",
"promises",
",",
"function",
"dispatcher",
"(",
"fn",
",",
"callback",
")",
"{",
"var",
"done",
"=",
"function",
"(",
"err",
",",
"lastReturn",
")",
"{",
"utils",
".",
"lastReturn",
"=",
"lastReturn",
";",
"if",
"(",
"err",
"===",
"stopPointer",
")",
"{",
"keep",
"=",
"false",
";",
"callback",
"(",
"err",
")",
";",
"}",
"else",
"if",
"(",
"err",
")",
"{",
"callback",
"(",
"err",
")",
";",
"}",
"else",
"if",
"(",
"keep",
")",
"{",
"callback",
"(",
")",
";",
"}",
"}",
";",
"utils",
".",
"stop",
"=",
"function",
"(",
")",
"{",
"done",
"(",
"stopPointer",
",",
"null",
")",
";",
"}",
";",
"try",
"{",
"fn",
".",
"call",
"(",
"that",
",",
"done",
",",
"utils",
")",
";",
"}",
"catch",
"(",
"err",
")",
"{",
"done",
"(",
"err",
",",
"null",
")",
";",
"}",
"}",
",",
"function",
"(",
"err",
")",
"{",
"utils",
".",
"stop",
"=",
"null",
";",
"if",
"(",
"err",
"&&",
"err",
"!==",
"stopPointer",
")",
"{",
"that",
".",
"errorCallback",
"(",
"err",
",",
"utils",
")",
";",
"}",
"that",
".",
"doneCallback",
"(",
"utils",
".",
"lastReturn",
",",
"utils",
")",
";",
"that",
".",
"scraper",
".",
"close",
"(",
")",
";",
"}",
")",
";",
"}"
] |
Starts the promise chain.
@param {?} error Error object, to fire the error callback,
from an error that happened before.
@param {!Scraper} scraper Scraper to use in the promise chain.
@protected
|
[
"Starts",
"the",
"promise",
"chain",
"."
] |
4ae680b84ffb40bc0b5ee70b00a955ea5368bc18
|
https://github.com/ruipgil/scraperjs/blob/4ae680b84ffb40bc0b5ee70b00a955ea5368bc18/src/ScraperPromise.js#L270-L319
|
|
16,133
|
ruipgil/scraperjs
|
src/ScraperPromise.js
|
function() {
var instance = this.scraper.clone(),
promise = new ScraperPromise(instance);
promise._setPromises(this.promises);
promise.done(this.doneCallback);
promise.catch(this.errorCallback);
return promise;
}
|
javascript
|
function() {
var instance = this.scraper.clone(),
promise = new ScraperPromise(instance);
promise._setPromises(this.promises);
promise.done(this.doneCallback);
promise.catch(this.errorCallback);
return promise;
}
|
[
"function",
"(",
")",
"{",
"var",
"instance",
"=",
"this",
".",
"scraper",
".",
"clone",
"(",
")",
",",
"promise",
"=",
"new",
"ScraperPromise",
"(",
"instance",
")",
";",
"promise",
".",
"_setPromises",
"(",
"this",
".",
"promises",
")",
";",
"promise",
".",
"done",
"(",
"this",
".",
"doneCallback",
")",
";",
"promise",
".",
"catch",
"(",
"this",
".",
"errorCallback",
")",
";",
"return",
"promise",
";",
"}"
] |
Clones the promise and the scraper.
@return {!ScraperPromise} Scraper promise with an empty scraper
clone.
@public
|
[
"Clones",
"the",
"promise",
"and",
"the",
"scraper",
"."
] |
4ae680b84ffb40bc0b5ee70b00a955ea5368bc18
|
https://github.com/ruipgil/scraperjs/blob/4ae680b84ffb40bc0b5ee70b00a955ea5368bc18/src/ScraperPromise.js#L336-L343
|
|
16,134
|
ruipgil/scraperjs
|
src/Router.js
|
function(path) {
var callback;
if (typeof path === 'function') {
callback = path;
}
this.promises.push({
callback: callback ? function(url) {
return callback(url);
} : Router.pathMatcher(path),
scraper: null,
rqMethod: null
});
return this.get();
}
|
javascript
|
function(path) {
var callback;
if (typeof path === 'function') {
callback = path;
}
this.promises.push({
callback: callback ? function(url) {
return callback(url);
} : Router.pathMatcher(path),
scraper: null,
rqMethod: null
});
return this.get();
}
|
[
"function",
"(",
"path",
")",
"{",
"var",
"callback",
";",
"if",
"(",
"typeof",
"path",
"===",
"'function'",
")",
"{",
"callback",
"=",
"path",
";",
"}",
"this",
".",
"promises",
".",
"push",
"(",
"{",
"callback",
":",
"callback",
"?",
"function",
"(",
"url",
")",
"{",
"return",
"callback",
"(",
"url",
")",
";",
"}",
":",
"Router",
".",
"pathMatcher",
"(",
"path",
")",
",",
"scraper",
":",
"null",
",",
"rqMethod",
":",
"null",
"}",
")",
";",
"return",
"this",
".",
"get",
"(",
")",
";",
"}"
] |
Promise to url match. It's promise will fire only if the path
matches with and url being routed.
@param {!(string|RegExp|function(string):?)} path The
path or regular expression to match an url.
Alternatively a function that receives the url to be matched
can be passed. If the result is false, or any
!!result===false), the path is considered valid and the
scraping should be done. If ,in case of a valid path, an Object is returned, it will be associated with the params of this
route/path.
For more information on the path matching refer to {@link https://github.com/aaronblohowiak/routes.js/blob/76bc517037a0321507c4d84a0cdaca6db31ebaa4/README.md#path-formats}
@return {!Router} This router.
@public
|
[
"Promise",
"to",
"url",
"match",
".",
"It",
"s",
"promise",
"will",
"fire",
"only",
"if",
"the",
"path",
"matches",
"with",
"and",
"url",
"being",
"routed",
"."
] |
4ae680b84ffb40bc0b5ee70b00a955ea5368bc18
|
https://github.com/ruipgil/scraperjs/blob/4ae680b84ffb40bc0b5ee70b00a955ea5368bc18/src/Router.js#L85-L99
|
|
16,135
|
ruipgil/scraperjs
|
src/Router.js
|
function(url, callback) {
var that = this,
atLeastOne = false,
stopFlag = {},
lastReturn;
callback = callback || function() {};
async.eachSeries(this.promises, function(promiseObj, done) {
var matcher = promiseObj.callback,
scraper,
reqMethod = promiseObj.rqMethod;
var result = matcher(url);
if (!!result) {
scraper = promiseObj.scraper.clone();
atLeastOne = true;
scraper._setChainParameter(result);
scraper.done(function(lr, utils) {
lastReturn = lr;
done(that.firstMatchStop ? stopFlag : undefined);
});
reqMethod(scraper, url);
} else {
done();
}
}, function() {
if (!atLeastOne) {
that.otherwiseFn(url);
}
callback(atLeastOne, lastReturn);
});
return this;
}
|
javascript
|
function(url, callback) {
var that = this,
atLeastOne = false,
stopFlag = {},
lastReturn;
callback = callback || function() {};
async.eachSeries(this.promises, function(promiseObj, done) {
var matcher = promiseObj.callback,
scraper,
reqMethod = promiseObj.rqMethod;
var result = matcher(url);
if (!!result) {
scraper = promiseObj.scraper.clone();
atLeastOne = true;
scraper._setChainParameter(result);
scraper.done(function(lr, utils) {
lastReturn = lr;
done(that.firstMatchStop ? stopFlag : undefined);
});
reqMethod(scraper, url);
} else {
done();
}
}, function() {
if (!atLeastOne) {
that.otherwiseFn(url);
}
callback(atLeastOne, lastReturn);
});
return this;
}
|
[
"function",
"(",
"url",
",",
"callback",
")",
"{",
"var",
"that",
"=",
"this",
",",
"atLeastOne",
"=",
"false",
",",
"stopFlag",
"=",
"{",
"}",
",",
"lastReturn",
";",
"callback",
"=",
"callback",
"||",
"function",
"(",
")",
"{",
"}",
";",
"async",
".",
"eachSeries",
"(",
"this",
".",
"promises",
",",
"function",
"(",
"promiseObj",
",",
"done",
")",
"{",
"var",
"matcher",
"=",
"promiseObj",
".",
"callback",
",",
"scraper",
",",
"reqMethod",
"=",
"promiseObj",
".",
"rqMethod",
";",
"var",
"result",
"=",
"matcher",
"(",
"url",
")",
";",
"if",
"(",
"!",
"!",
"result",
")",
"{",
"scraper",
"=",
"promiseObj",
".",
"scraper",
".",
"clone",
"(",
")",
";",
"atLeastOne",
"=",
"true",
";",
"scraper",
".",
"_setChainParameter",
"(",
"result",
")",
";",
"scraper",
".",
"done",
"(",
"function",
"(",
"lr",
",",
"utils",
")",
"{",
"lastReturn",
"=",
"lr",
";",
"done",
"(",
"that",
".",
"firstMatchStop",
"?",
"stopFlag",
":",
"undefined",
")",
";",
"}",
")",
";",
"reqMethod",
"(",
"scraper",
",",
"url",
")",
";",
"}",
"else",
"{",
"done",
"(",
")",
";",
"}",
"}",
",",
"function",
"(",
")",
"{",
"if",
"(",
"!",
"atLeastOne",
")",
"{",
"that",
".",
"otherwiseFn",
"(",
"url",
")",
";",
"}",
"callback",
"(",
"atLeastOne",
",",
"lastReturn",
")",
";",
"}",
")",
";",
"return",
"this",
";",
"}"
] |
Routes a url through every path that matches it.
@param {!string} url The url to route.
@param {!function(boolean)} callback Function to call when the
routing is complete. If any of the paths was found the
parameter is true, false otherwise.
@return {!Router} This router.
@public
|
[
"Routes",
"a",
"url",
"through",
"every",
"path",
"that",
"matches",
"it",
"."
] |
4ae680b84ffb40bc0b5ee70b00a955ea5368bc18
|
https://github.com/ruipgil/scraperjs/blob/4ae680b84ffb40bc0b5ee70b00a955ea5368bc18/src/Router.js#L221-L253
|
|
16,136
|
ruipgil/scraperjs
|
src/PhantomPoll.js
|
function() {
/**
* The real PhantomJS instance.
*
* @type {?}
* @private
*/
this.instance = null;
/**
* The PhantomJS instance is being created.
*
* @type {!boolean}
* @private
*/
this.creating = false;
/**
* PhantomJS flags.
*
* @type {!string}
* @private
*/
this.flags = '';
/**
* PhantomJS options.
*
* @type {!Object}
* @private
*/
this.options = {
onStdout: function() {},
onStderr: function() {}
};
/**
* List of functions waiting to be called after the PhantomJS
* instance is created.
*
* @type {!Array.<!function(?)>}
* @private
*/
this.waiting = [];
this._createInstance();
}
|
javascript
|
function() {
/**
* The real PhantomJS instance.
*
* @type {?}
* @private
*/
this.instance = null;
/**
* The PhantomJS instance is being created.
*
* @type {!boolean}
* @private
*/
this.creating = false;
/**
* PhantomJS flags.
*
* @type {!string}
* @private
*/
this.flags = '';
/**
* PhantomJS options.
*
* @type {!Object}
* @private
*/
this.options = {
onStdout: function() {},
onStderr: function() {}
};
/**
* List of functions waiting to be called after the PhantomJS
* instance is created.
*
* @type {!Array.<!function(?)>}
* @private
*/
this.waiting = [];
this._createInstance();
}
|
[
"function",
"(",
")",
"{",
"/**\n\t * The real PhantomJS instance.\n\t *\n\t * @type {?}\n\t * @private\n\t */",
"this",
".",
"instance",
"=",
"null",
";",
"/**\n\t * The PhantomJS instance is being created.\n\t *\n\t * @type {!boolean}\n\t * @private\n\t */",
"this",
".",
"creating",
"=",
"false",
";",
"/**\n\t * PhantomJS flags.\n\t *\n\t * @type {!string}\n\t * @private\n\t */",
"this",
".",
"flags",
"=",
"''",
";",
"/**\n\t * PhantomJS options.\n\t *\n\t * @type {!Object}\n\t * @private\n\t */",
"this",
".",
"options",
"=",
"{",
"onStdout",
":",
"function",
"(",
")",
"{",
"}",
",",
"onStderr",
":",
"function",
"(",
")",
"{",
"}",
"}",
";",
"/**\n\t * List of functions waiting to be called after the PhantomJS\n\t * instance is created.\n\t *\n\t * @type {!Array.<!function(?)>}\n\t * @private\n\t */",
"this",
".",
"waiting",
"=",
"[",
"]",
";",
"this",
".",
"_createInstance",
"(",
")",
";",
"}"
] |
This maintains only one PhantomJS instance. It works like a proxy
between the phantom package, and should expose the methods same
methods. An additional call to close the phantomJS instance
properly is needed.
@constructor
|
[
"This",
"maintains",
"only",
"one",
"PhantomJS",
"instance",
".",
"It",
"works",
"like",
"a",
"proxy",
"between",
"the",
"phantom",
"package",
"and",
"should",
"expose",
"the",
"methods",
"same",
"methods",
".",
"An",
"additional",
"call",
"to",
"close",
"the",
"phantomJS",
"instance",
"properly",
"is",
"needed",
"."
] |
4ae680b84ffb40bc0b5ee70b00a955ea5368bc18
|
https://github.com/ruipgil/scraperjs/blob/4ae680b84ffb40bc0b5ee70b00a955ea5368bc18/src/PhantomPoll.js#L11-L52
|
|
16,137
|
ruipgil/scraperjs
|
src/PhantomPoll.js
|
function(callback) {
if (this.instance) {
this.instance.createPage(function(page) {
callback(page);
});
} else {
var that = this;
this._createInstance(function() {
that.createPage(callback);
});
}
}
|
javascript
|
function(callback) {
if (this.instance) {
this.instance.createPage(function(page) {
callback(page);
});
} else {
var that = this;
this._createInstance(function() {
that.createPage(callback);
});
}
}
|
[
"function",
"(",
"callback",
")",
"{",
"if",
"(",
"this",
".",
"instance",
")",
"{",
"this",
".",
"instance",
".",
"createPage",
"(",
"function",
"(",
"page",
")",
"{",
"callback",
"(",
"page",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"var",
"that",
"=",
"this",
";",
"this",
".",
"_createInstance",
"(",
"function",
"(",
")",
"{",
"that",
".",
"createPage",
"(",
"callback",
")",
";",
"}",
")",
";",
"}",
"}"
] |
Creates a PhantomJS page, to be called with a callback, which
will receive the page.
@param {!function(?)} callback Function to be called after the
page is created, it receives the page object.
@public
|
[
"Creates",
"a",
"PhantomJS",
"page",
"to",
"be",
"called",
"with",
"a",
"callback",
"which",
"will",
"receive",
"the",
"page",
"."
] |
4ae680b84ffb40bc0b5ee70b00a955ea5368bc18
|
https://github.com/ruipgil/scraperjs/blob/4ae680b84ffb40bc0b5ee70b00a955ea5368bc18/src/PhantomPoll.js#L63-L74
|
|
16,138
|
ruipgil/scraperjs
|
src/PhantomPoll.js
|
function(callback) {
if (this.creating && callback) {
this.waiting.push(callback);
} else {
var that = this;
this.creating = true;
phantom.create(this.flags, this.options, function(ph) {
that.instance = ph;
that.creating = false;
that.waiting.forEach(function(callback) {
callback(ph);
});
that.waiting = [];
});
}
}
|
javascript
|
function(callback) {
if (this.creating && callback) {
this.waiting.push(callback);
} else {
var that = this;
this.creating = true;
phantom.create(this.flags, this.options, function(ph) {
that.instance = ph;
that.creating = false;
that.waiting.forEach(function(callback) {
callback(ph);
});
that.waiting = [];
});
}
}
|
[
"function",
"(",
"callback",
")",
"{",
"if",
"(",
"this",
".",
"creating",
"&&",
"callback",
")",
"{",
"this",
".",
"waiting",
".",
"push",
"(",
"callback",
")",
";",
"}",
"else",
"{",
"var",
"that",
"=",
"this",
";",
"this",
".",
"creating",
"=",
"true",
";",
"phantom",
".",
"create",
"(",
"this",
".",
"flags",
",",
"this",
".",
"options",
",",
"function",
"(",
"ph",
")",
"{",
"that",
".",
"instance",
"=",
"ph",
";",
"that",
".",
"creating",
"=",
"false",
";",
"that",
".",
"waiting",
".",
"forEach",
"(",
"function",
"(",
"callback",
")",
"{",
"callback",
"(",
"ph",
")",
";",
"}",
")",
";",
"that",
".",
"waiting",
"=",
"[",
"]",
";",
"}",
")",
";",
"}",
"}"
] |
Creates PhantomJS instance if needed be, and when it's done
triggers all the callbacks.
@param {!function(?)} callback Function to be called when the
instance is created, if a phantom instance is waiting to be
created the callback will be added to a waiting list.
@private
|
[
"Creates",
"PhantomJS",
"instance",
"if",
"needed",
"be",
"and",
"when",
"it",
"s",
"done",
"triggers",
"all",
"the",
"callbacks",
"."
] |
4ae680b84ffb40bc0b5ee70b00a955ea5368bc18
|
https://github.com/ruipgil/scraperjs/blob/4ae680b84ffb40bc0b5ee70b00a955ea5368bc18/src/PhantomPoll.js#L99-L114
|
|
16,139
|
mapbox/dyno
|
lib/requests.js
|
sendAll
|
function sendAll(requests, fnName, concurrency, callback) {
if (typeof concurrency === 'function') {
callback = concurrency;
concurrency = 1;
}
var q = queue(concurrency);
requests.forEach(function(req) {
q.defer(function(next) {
if (!req) return next();
req.on('complete', function(response) {
next(null, response);
}).send();
});
});
q.awaitAll(function(err, responses) {
if (err) return callback(err);
var errors = [];
var data = [];
var unprocessed = [];
responses.forEach(function(response) {
if (!response) response = { error: null, data: null };
errors.push(response.error);
data.push(response.data);
if (!response.data) return unprocessed.push(null);
var newParams = {
RequestItems: response.data.UnprocessedItems || response.data.UnprocessedKeys
};
if (newParams.RequestItems && !Object.keys(newParams.RequestItems).length)
return unprocessed.push(null);
unprocessed.push(newParams.RequestItems ? newParams : null);
});
unprocessed = unprocessed.map(function(params) {
if (params) return client[fnName].bind(client)(params);
else return null;
});
var unprocessedCount = unprocessed.filter(function(req) { return !!req; }).length;
if (unprocessedCount) unprocessed.sendAll = sendAll.bind(null, unprocessed, fnName);
var errorCount = errors.filter(function(err) { return !!err; }).length;
callback(
errorCount ? errors : null,
data,
unprocessedCount ? unprocessed : null
);
});
}
|
javascript
|
function sendAll(requests, fnName, concurrency, callback) {
if (typeof concurrency === 'function') {
callback = concurrency;
concurrency = 1;
}
var q = queue(concurrency);
requests.forEach(function(req) {
q.defer(function(next) {
if (!req) return next();
req.on('complete', function(response) {
next(null, response);
}).send();
});
});
q.awaitAll(function(err, responses) {
if (err) return callback(err);
var errors = [];
var data = [];
var unprocessed = [];
responses.forEach(function(response) {
if (!response) response = { error: null, data: null };
errors.push(response.error);
data.push(response.data);
if (!response.data) return unprocessed.push(null);
var newParams = {
RequestItems: response.data.UnprocessedItems || response.data.UnprocessedKeys
};
if (newParams.RequestItems && !Object.keys(newParams.RequestItems).length)
return unprocessed.push(null);
unprocessed.push(newParams.RequestItems ? newParams : null);
});
unprocessed = unprocessed.map(function(params) {
if (params) return client[fnName].bind(client)(params);
else return null;
});
var unprocessedCount = unprocessed.filter(function(req) { return !!req; }).length;
if (unprocessedCount) unprocessed.sendAll = sendAll.bind(null, unprocessed, fnName);
var errorCount = errors.filter(function(err) { return !!err; }).length;
callback(
errorCount ? errors : null,
data,
unprocessedCount ? unprocessed : null
);
});
}
|
[
"function",
"sendAll",
"(",
"requests",
",",
"fnName",
",",
"concurrency",
",",
"callback",
")",
"{",
"if",
"(",
"typeof",
"concurrency",
"===",
"'function'",
")",
"{",
"callback",
"=",
"concurrency",
";",
"concurrency",
"=",
"1",
";",
"}",
"var",
"q",
"=",
"queue",
"(",
"concurrency",
")",
";",
"requests",
".",
"forEach",
"(",
"function",
"(",
"req",
")",
"{",
"q",
".",
"defer",
"(",
"function",
"(",
"next",
")",
"{",
"if",
"(",
"!",
"req",
")",
"return",
"next",
"(",
")",
";",
"req",
".",
"on",
"(",
"'complete'",
",",
"function",
"(",
"response",
")",
"{",
"next",
"(",
"null",
",",
"response",
")",
";",
"}",
")",
".",
"send",
"(",
")",
";",
"}",
")",
";",
"}",
")",
";",
"q",
".",
"awaitAll",
"(",
"function",
"(",
"err",
",",
"responses",
")",
"{",
"if",
"(",
"err",
")",
"return",
"callback",
"(",
"err",
")",
";",
"var",
"errors",
"=",
"[",
"]",
";",
"var",
"data",
"=",
"[",
"]",
";",
"var",
"unprocessed",
"=",
"[",
"]",
";",
"responses",
".",
"forEach",
"(",
"function",
"(",
"response",
")",
"{",
"if",
"(",
"!",
"response",
")",
"response",
"=",
"{",
"error",
":",
"null",
",",
"data",
":",
"null",
"}",
";",
"errors",
".",
"push",
"(",
"response",
".",
"error",
")",
";",
"data",
".",
"push",
"(",
"response",
".",
"data",
")",
";",
"if",
"(",
"!",
"response",
".",
"data",
")",
"return",
"unprocessed",
".",
"push",
"(",
"null",
")",
";",
"var",
"newParams",
"=",
"{",
"RequestItems",
":",
"response",
".",
"data",
".",
"UnprocessedItems",
"||",
"response",
".",
"data",
".",
"UnprocessedKeys",
"}",
";",
"if",
"(",
"newParams",
".",
"RequestItems",
"&&",
"!",
"Object",
".",
"keys",
"(",
"newParams",
".",
"RequestItems",
")",
".",
"length",
")",
"return",
"unprocessed",
".",
"push",
"(",
"null",
")",
";",
"unprocessed",
".",
"push",
"(",
"newParams",
".",
"RequestItems",
"?",
"newParams",
":",
"null",
")",
";",
"}",
")",
";",
"unprocessed",
"=",
"unprocessed",
".",
"map",
"(",
"function",
"(",
"params",
")",
"{",
"if",
"(",
"params",
")",
"return",
"client",
"[",
"fnName",
"]",
".",
"bind",
"(",
"client",
")",
"(",
"params",
")",
";",
"else",
"return",
"null",
";",
"}",
")",
";",
"var",
"unprocessedCount",
"=",
"unprocessed",
".",
"filter",
"(",
"function",
"(",
"req",
")",
"{",
"return",
"!",
"!",
"req",
";",
"}",
")",
".",
"length",
";",
"if",
"(",
"unprocessedCount",
")",
"unprocessed",
".",
"sendAll",
"=",
"sendAll",
".",
"bind",
"(",
"null",
",",
"unprocessed",
",",
"fnName",
")",
";",
"var",
"errorCount",
"=",
"errors",
".",
"filter",
"(",
"function",
"(",
"err",
")",
"{",
"return",
"!",
"!",
"err",
";",
"}",
")",
".",
"length",
";",
"callback",
"(",
"errorCount",
"?",
"errors",
":",
"null",
",",
"data",
",",
"unprocessedCount",
"?",
"unprocessed",
":",
"null",
")",
";",
"}",
")",
";",
"}"
] |
Given a set of requests, this function sends them all at specified concurrency.
Generally, this function is not called directly, but is bound to an array of
requests with the first two parameters wired to specific values.
@private
@param {RequestSet} requests - an array of AWS.Request objects
@param {string} fnName - the name of the aws-sdk client function that will
be used to construct new requests should an unprocessed items be detected
@param {number} concurrency - the concurrency with which batch requests
will be made
@param {function} callback - a function to handle the response
|
[
"Given",
"a",
"set",
"of",
"requests",
"this",
"function",
"sends",
"them",
"all",
"at",
"specified",
"concurrency",
".",
"Generally",
"this",
"function",
"is",
"not",
"called",
"directly",
"but",
"is",
"bound",
"to",
"an",
"array",
"of",
"requests",
"with",
"the",
"first",
"two",
"parameters",
"wired",
"to",
"specific",
"values",
"."
] |
5f5ae2692b165e480c2ae61d11978ad97a40e3aa
|
https://github.com/mapbox/dyno/blob/5f5ae2692b165e480c2ae61d11978ad97a40e3aa/lib/requests.js#L22-L80
|
16,140
|
mapbox/dyno
|
bin/cli.js
|
Stringifier
|
function Stringifier() {
var stringifier = new stream.Transform({ highWaterMark: 100 });
stringifier._writableState.objectMode = true;
stringifier._readableState.objectMode = false;
stringifier._transform = function(record, enc, callback) {
var str = Dyno.serialize(record);
this.push(str + '\n');
setImmediate(callback);
};
return stringifier;
}
|
javascript
|
function Stringifier() {
var stringifier = new stream.Transform({ highWaterMark: 100 });
stringifier._writableState.objectMode = true;
stringifier._readableState.objectMode = false;
stringifier._transform = function(record, enc, callback) {
var str = Dyno.serialize(record);
this.push(str + '\n');
setImmediate(callback);
};
return stringifier;
}
|
[
"function",
"Stringifier",
"(",
")",
"{",
"var",
"stringifier",
"=",
"new",
"stream",
".",
"Transform",
"(",
"{",
"highWaterMark",
":",
"100",
"}",
")",
";",
"stringifier",
".",
"_writableState",
".",
"objectMode",
"=",
"true",
";",
"stringifier",
".",
"_readableState",
".",
"objectMode",
"=",
"false",
";",
"stringifier",
".",
"_transform",
"=",
"function",
"(",
"record",
",",
"enc",
",",
"callback",
")",
"{",
"var",
"str",
"=",
"Dyno",
".",
"serialize",
"(",
"record",
")",
";",
"this",
".",
"push",
"(",
"str",
"+",
"'\\n'",
")",
";",
"setImmediate",
"(",
"callback",
")",
";",
"}",
";",
"return",
"stringifier",
";",
"}"
] |
Transform stream to stringifies JSON objects and base64 encodes buffers
|
[
"Transform",
"stream",
"to",
"stringifies",
"JSON",
"objects",
"and",
"base64",
"encodes",
"buffers"
] |
5f5ae2692b165e480c2ae61d11978ad97a40e3aa
|
https://github.com/mapbox/dyno/blob/5f5ae2692b165e480c2ae61d11978ad97a40e3aa/bin/cli.js#L66-L79
|
16,141
|
mapbox/dyno
|
bin/cli.js
|
Parser
|
function Parser() {
var parser = new stream.Transform({ highWaterMark: 100 });
parser._writableState.objectMode = false;
parser._readableState.objectMode = true;
var firstline = true;
parser._transform = function(record, enc, callback) {
if (!record || record.length === 0) return;
if (firstline) {
firstline = false;
var parsed = Dyno.deserialize(record);
if (!Object.keys(parsed).every(function(key) {
return !!parsed[key];
})) return this.push(JSON.parse(record.toString()));
}
record = Dyno.deserialize(record);
this.push(record);
setImmediate(callback);
};
return parser;
}
|
javascript
|
function Parser() {
var parser = new stream.Transform({ highWaterMark: 100 });
parser._writableState.objectMode = false;
parser._readableState.objectMode = true;
var firstline = true;
parser._transform = function(record, enc, callback) {
if (!record || record.length === 0) return;
if (firstline) {
firstline = false;
var parsed = Dyno.deserialize(record);
if (!Object.keys(parsed).every(function(key) {
return !!parsed[key];
})) return this.push(JSON.parse(record.toString()));
}
record = Dyno.deserialize(record);
this.push(record);
setImmediate(callback);
};
return parser;
}
|
[
"function",
"Parser",
"(",
")",
"{",
"var",
"parser",
"=",
"new",
"stream",
".",
"Transform",
"(",
"{",
"highWaterMark",
":",
"100",
"}",
")",
";",
"parser",
".",
"_writableState",
".",
"objectMode",
"=",
"false",
";",
"parser",
".",
"_readableState",
".",
"objectMode",
"=",
"true",
";",
"var",
"firstline",
"=",
"true",
";",
"parser",
".",
"_transform",
"=",
"function",
"(",
"record",
",",
"enc",
",",
"callback",
")",
"{",
"if",
"(",
"!",
"record",
"||",
"record",
".",
"length",
"===",
"0",
")",
"return",
";",
"if",
"(",
"firstline",
")",
"{",
"firstline",
"=",
"false",
";",
"var",
"parsed",
"=",
"Dyno",
".",
"deserialize",
"(",
"record",
")",
";",
"if",
"(",
"!",
"Object",
".",
"keys",
"(",
"parsed",
")",
".",
"every",
"(",
"function",
"(",
"key",
")",
"{",
"return",
"!",
"!",
"parsed",
"[",
"key",
"]",
";",
"}",
")",
")",
"return",
"this",
".",
"push",
"(",
"JSON",
".",
"parse",
"(",
"record",
".",
"toString",
"(",
")",
")",
")",
";",
"}",
"record",
"=",
"Dyno",
".",
"deserialize",
"(",
"record",
")",
";",
"this",
".",
"push",
"(",
"record",
")",
";",
"setImmediate",
"(",
"callback",
")",
";",
"}",
";",
"return",
"parser",
";",
"}"
] |
Transform stream parses JSON strings and base64 decodes into buffers
|
[
"Transform",
"stream",
"parses",
"JSON",
"strings",
"and",
"base64",
"decodes",
"into",
"buffers"
] |
5f5ae2692b165e480c2ae61d11978ad97a40e3aa
|
https://github.com/mapbox/dyno/blob/5f5ae2692b165e480c2ae61d11978ad97a40e3aa/bin/cli.js#L82-L107
|
16,142
|
mapbox/dyno
|
bin/cli.js
|
cleanDescription
|
function cleanDescription(desc) {
var deleteAttributes = [
'CreationDateTime',
'IndexSizeBytes',
'IndexStatus',
'ItemCount',
'NumberOfDecreasesToday',
'TableSizeBytes',
'TableStatus',
'LastDecreaseDateTime',
'LastIncreaseDateTime'
];
return JSON.stringify(desc.Table, function(key, value) {
if (deleteAttributes.indexOf(key) !== -1) {
return undefined;
}
return value;
});
}
|
javascript
|
function cleanDescription(desc) {
var deleteAttributes = [
'CreationDateTime',
'IndexSizeBytes',
'IndexStatus',
'ItemCount',
'NumberOfDecreasesToday',
'TableSizeBytes',
'TableStatus',
'LastDecreaseDateTime',
'LastIncreaseDateTime'
];
return JSON.stringify(desc.Table, function(key, value) {
if (deleteAttributes.indexOf(key) !== -1) {
return undefined;
}
return value;
});
}
|
[
"function",
"cleanDescription",
"(",
"desc",
")",
"{",
"var",
"deleteAttributes",
"=",
"[",
"'CreationDateTime'",
",",
"'IndexSizeBytes'",
",",
"'IndexStatus'",
",",
"'ItemCount'",
",",
"'NumberOfDecreasesToday'",
",",
"'TableSizeBytes'",
",",
"'TableStatus'",
",",
"'LastDecreaseDateTime'",
",",
"'LastIncreaseDateTime'",
"]",
";",
"return",
"JSON",
".",
"stringify",
"(",
"desc",
".",
"Table",
",",
"function",
"(",
"key",
",",
"value",
")",
"{",
"if",
"(",
"deleteAttributes",
".",
"indexOf",
"(",
"key",
")",
"!==",
"-",
"1",
")",
"{",
"return",
"undefined",
";",
"}",
"return",
"value",
";",
"}",
")",
";",
"}"
] |
Remove unimportant table metadata from the description
|
[
"Remove",
"unimportant",
"table",
"metadata",
"from",
"the",
"description"
] |
5f5ae2692b165e480c2ae61d11978ad97a40e3aa
|
https://github.com/mapbox/dyno/blob/5f5ae2692b165e480c2ae61d11978ad97a40e3aa/bin/cli.js#L110-L129
|
16,143
|
mapbox/dyno
|
bin/cli.js
|
Aggregator
|
function Aggregator(withTable) {
var firstline = !!withTable;
var aggregator = new stream.Transform({ objectMode: true, highWaterMark: 100 });
aggregator.records = [];
aggregator._transform = function(record, enc, callback) {
if (!record) return;
if (firstline) {
firstline = false;
this.push(record);
} else if (aggregator.records.length === 25) {
this.push(aggregator.records);
aggregator.records = [record];
} else {
aggregator.records.push(record);
}
callback();
};
aggregator._flush = function(callback) {
if (aggregator.records.length) this.push(aggregator.records);
callback();
};
return aggregator;
}
|
javascript
|
function Aggregator(withTable) {
var firstline = !!withTable;
var aggregator = new stream.Transform({ objectMode: true, highWaterMark: 100 });
aggregator.records = [];
aggregator._transform = function(record, enc, callback) {
if (!record) return;
if (firstline) {
firstline = false;
this.push(record);
} else if (aggregator.records.length === 25) {
this.push(aggregator.records);
aggregator.records = [record];
} else {
aggregator.records.push(record);
}
callback();
};
aggregator._flush = function(callback) {
if (aggregator.records.length) this.push(aggregator.records);
callback();
};
return aggregator;
}
|
[
"function",
"Aggregator",
"(",
"withTable",
")",
"{",
"var",
"firstline",
"=",
"!",
"!",
"withTable",
";",
"var",
"aggregator",
"=",
"new",
"stream",
".",
"Transform",
"(",
"{",
"objectMode",
":",
"true",
",",
"highWaterMark",
":",
"100",
"}",
")",
";",
"aggregator",
".",
"records",
"=",
"[",
"]",
";",
"aggregator",
".",
"_transform",
"=",
"function",
"(",
"record",
",",
"enc",
",",
"callback",
")",
"{",
"if",
"(",
"!",
"record",
")",
"return",
";",
"if",
"(",
"firstline",
")",
"{",
"firstline",
"=",
"false",
";",
"this",
".",
"push",
"(",
"record",
")",
";",
"}",
"else",
"if",
"(",
"aggregator",
".",
"records",
".",
"length",
"===",
"25",
")",
"{",
"this",
".",
"push",
"(",
"aggregator",
".",
"records",
")",
";",
"aggregator",
".",
"records",
"=",
"[",
"record",
"]",
";",
"}",
"else",
"{",
"aggregator",
".",
"records",
".",
"push",
"(",
"record",
")",
";",
"}",
"callback",
"(",
")",
";",
"}",
";",
"aggregator",
".",
"_flush",
"=",
"function",
"(",
"callback",
")",
"{",
"if",
"(",
"aggregator",
".",
"records",
".",
"length",
")",
"this",
".",
"push",
"(",
"aggregator",
".",
"records",
")",
";",
"callback",
"(",
")",
";",
"}",
";",
"return",
"aggregator",
";",
"}"
] |
Transform stream that aggregates into sets of 25 objects
|
[
"Transform",
"stream",
"that",
"aggregates",
"into",
"sets",
"of",
"25",
"objects"
] |
5f5ae2692b165e480c2ae61d11978ad97a40e3aa
|
https://github.com/mapbox/dyno/blob/5f5ae2692b165e480c2ae61d11978ad97a40e3aa/bin/cli.js#L142-L168
|
16,144
|
hobbyquaker/homematic-manager
|
www/js/homematic-manager.js
|
rpcDialogShift
|
function rpcDialogShift() {
if (rpcDialogQueue.length === 0) {
$dialogRpc.dialog('close');
return;
}
rpcDialogPending = true;
const {daemon, cmd, params, callback} = rpcDialogQueue.shift();
const paramText = JSON.stringify(JSON.parse(JSON.stringify(params).replace(/{"explicitDouble":([0-9.]+)}/g, '$1')), null, ' ');
$('#rpc-command').html(cmd + ' ' + paramText);
$('#rpc-message').html('');
$dialogRpc.dialog('open');
$('#rpc-progress').show();
ipcRpc.send('rpc', [daemon, cmd, params], (err, res) => {
$('#rpc-progress').hide();
if (err) {
$dialogRpc.parent().children().children('.ui-dialog-titlebar-close').show();
$('#rpc-message').html('<span style="color: red; font-weight: bold;">' + (err.faultString ? err.faultString : JSON.stringify(err)) + '</span>');
} else if (res && res.faultCode) {
$dialogRpc.parent().children().children('.ui-dialog-titlebar-close').show();
$('#rpc-message').html('<span style="color: orange; font-weight: bold;">' + res.faultString + ' (' + res.faultCode + ')</span>');
} else {
$dialogRpc.parent().children().children('.ui-dialog-titlebar-close').hide();
const resText = res ? ('<br>' + (typeof res === 'string' ? res : JSON.stringify(res, null, ' '))) : '';
$('#rpc-message').html('<span style="color: green;">success</span><br>' + resText);
}
setTimeout(() => {
rpcDialogPending = false;
rpcDialogShift();
if (typeof callback === 'function') {
callback(err, res);
}
}, config.rpcDelay);
});
}
|
javascript
|
function rpcDialogShift() {
if (rpcDialogQueue.length === 0) {
$dialogRpc.dialog('close');
return;
}
rpcDialogPending = true;
const {daemon, cmd, params, callback} = rpcDialogQueue.shift();
const paramText = JSON.stringify(JSON.parse(JSON.stringify(params).replace(/{"explicitDouble":([0-9.]+)}/g, '$1')), null, ' ');
$('#rpc-command').html(cmd + ' ' + paramText);
$('#rpc-message').html('');
$dialogRpc.dialog('open');
$('#rpc-progress').show();
ipcRpc.send('rpc', [daemon, cmd, params], (err, res) => {
$('#rpc-progress').hide();
if (err) {
$dialogRpc.parent().children().children('.ui-dialog-titlebar-close').show();
$('#rpc-message').html('<span style="color: red; font-weight: bold;">' + (err.faultString ? err.faultString : JSON.stringify(err)) + '</span>');
} else if (res && res.faultCode) {
$dialogRpc.parent().children().children('.ui-dialog-titlebar-close').show();
$('#rpc-message').html('<span style="color: orange; font-weight: bold;">' + res.faultString + ' (' + res.faultCode + ')</span>');
} else {
$dialogRpc.parent().children().children('.ui-dialog-titlebar-close').hide();
const resText = res ? ('<br>' + (typeof res === 'string' ? res : JSON.stringify(res, null, ' '))) : '';
$('#rpc-message').html('<span style="color: green;">success</span><br>' + resText);
}
setTimeout(() => {
rpcDialogPending = false;
rpcDialogShift();
if (typeof callback === 'function') {
callback(err, res);
}
}, config.rpcDelay);
});
}
|
[
"function",
"rpcDialogShift",
"(",
")",
"{",
"if",
"(",
"rpcDialogQueue",
".",
"length",
"===",
"0",
")",
"{",
"$dialogRpc",
".",
"dialog",
"(",
"'close'",
")",
";",
"return",
";",
"}",
"rpcDialogPending",
"=",
"true",
";",
"const",
"{",
"daemon",
",",
"cmd",
",",
"params",
",",
"callback",
"}",
"=",
"rpcDialogQueue",
".",
"shift",
"(",
")",
";",
"const",
"paramText",
"=",
"JSON",
".",
"stringify",
"(",
"JSON",
".",
"parse",
"(",
"JSON",
".",
"stringify",
"(",
"params",
")",
".",
"replace",
"(",
"/",
"{\"explicitDouble\":([0-9.]+)}",
"/",
"g",
",",
"'$1'",
")",
")",
",",
"null",
",",
"' '",
")",
";",
"$",
"(",
"'#rpc-command'",
")",
".",
"html",
"(",
"cmd",
"+",
"' '",
"+",
"paramText",
")",
";",
"$",
"(",
"'#rpc-message'",
")",
".",
"html",
"(",
"''",
")",
";",
"$dialogRpc",
".",
"dialog",
"(",
"'open'",
")",
";",
"$",
"(",
"'#rpc-progress'",
")",
".",
"show",
"(",
")",
";",
"ipcRpc",
".",
"send",
"(",
"'rpc'",
",",
"[",
"daemon",
",",
"cmd",
",",
"params",
"]",
",",
"(",
"err",
",",
"res",
")",
"=>",
"{",
"$",
"(",
"'#rpc-progress'",
")",
".",
"hide",
"(",
")",
";",
"if",
"(",
"err",
")",
"{",
"$dialogRpc",
".",
"parent",
"(",
")",
".",
"children",
"(",
")",
".",
"children",
"(",
"'.ui-dialog-titlebar-close'",
")",
".",
"show",
"(",
")",
";",
"$",
"(",
"'#rpc-message'",
")",
".",
"html",
"(",
"'<span style=\"color: red; font-weight: bold;\">'",
"+",
"(",
"err",
".",
"faultString",
"?",
"err",
".",
"faultString",
":",
"JSON",
".",
"stringify",
"(",
"err",
")",
")",
"+",
"'</span>'",
")",
";",
"}",
"else",
"if",
"(",
"res",
"&&",
"res",
".",
"faultCode",
")",
"{",
"$dialogRpc",
".",
"parent",
"(",
")",
".",
"children",
"(",
")",
".",
"children",
"(",
"'.ui-dialog-titlebar-close'",
")",
".",
"show",
"(",
")",
";",
"$",
"(",
"'#rpc-message'",
")",
".",
"html",
"(",
"'<span style=\"color: orange; font-weight: bold;\">'",
"+",
"res",
".",
"faultString",
"+",
"' ('",
"+",
"res",
".",
"faultCode",
"+",
"')</span>'",
")",
";",
"}",
"else",
"{",
"$dialogRpc",
".",
"parent",
"(",
")",
".",
"children",
"(",
")",
".",
"children",
"(",
"'.ui-dialog-titlebar-close'",
")",
".",
"hide",
"(",
")",
";",
"const",
"resText",
"=",
"res",
"?",
"(",
"'<br>'",
"+",
"(",
"typeof",
"res",
"===",
"'string'",
"?",
"res",
":",
"JSON",
".",
"stringify",
"(",
"res",
",",
"null",
",",
"' '",
")",
")",
")",
":",
"''",
";",
"$",
"(",
"'#rpc-message'",
")",
".",
"html",
"(",
"'<span style=\"color: green;\">success</span><br>'",
"+",
"resText",
")",
";",
"}",
"setTimeout",
"(",
"(",
")",
"=>",
"{",
"rpcDialogPending",
"=",
"false",
";",
"rpcDialogShift",
"(",
")",
";",
"if",
"(",
"typeof",
"callback",
"===",
"'function'",
")",
"{",
"callback",
"(",
"err",
",",
"res",
")",
";",
"}",
"}",
",",
"config",
".",
"rpcDelay",
")",
";",
"}",
")",
";",
"}"
] |
RPC execution Wrappers
|
[
"RPC",
"execution",
"Wrappers"
] |
14903c5718006ba4c38b7790b5c9171e0f67bb66
|
https://github.com/hobbyquaker/homematic-manager/blob/14903c5718006ba4c38b7790b5c9171e0f67bb66/www/js/homematic-manager.js#L4467-L4504
|
16,145
|
catamphetamine/universal-webpack
|
source/client configuration.js
|
create_extract_css_plugin
|
function create_extract_css_plugin(css_bundle_filename, useMiniCssExtractPlugin)
{
if (useMiniCssExtractPlugin)
{
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
return new MiniCssExtractPlugin
({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename : css_bundle_filename
})
}
const ExtractTextPlugin = require('extract-text-webpack-plugin')
// "allChunks: true" option means that the styles from all chunks
// (think "entry points") will be extracted into a single big CSS file.
//
return new ExtractTextPlugin
({
filename : css_bundle_filename,
allChunks : true
})
}
|
javascript
|
function create_extract_css_plugin(css_bundle_filename, useMiniCssExtractPlugin)
{
if (useMiniCssExtractPlugin)
{
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
return new MiniCssExtractPlugin
({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename : css_bundle_filename
})
}
const ExtractTextPlugin = require('extract-text-webpack-plugin')
// "allChunks: true" option means that the styles from all chunks
// (think "entry points") will be extracted into a single big CSS file.
//
return new ExtractTextPlugin
({
filename : css_bundle_filename,
allChunks : true
})
}
|
[
"function",
"create_extract_css_plugin",
"(",
"css_bundle_filename",
",",
"useMiniCssExtractPlugin",
")",
"{",
"if",
"(",
"useMiniCssExtractPlugin",
")",
"{",
"const",
"MiniCssExtractPlugin",
"=",
"require",
"(",
"'mini-css-extract-plugin'",
")",
"return",
"new",
"MiniCssExtractPlugin",
"(",
"{",
"// Options similar to the same options in webpackOptions.output",
"// both options are optional",
"filename",
":",
"css_bundle_filename",
"}",
")",
"}",
"const",
"ExtractTextPlugin",
"=",
"require",
"(",
"'extract-text-webpack-plugin'",
")",
"// \"allChunks: true\" option means that the styles from all chunks",
"// (think \"entry points\") will be extracted into a single big CSS file.",
"//",
"return",
"new",
"ExtractTextPlugin",
"(",
"{",
"filename",
":",
"css_bundle_filename",
",",
"allChunks",
":",
"true",
"}",
")",
"}"
] |
Creates an instance of plugin for extracting styles in a file.
Either `extract-text-webpack-plugin` or `mini-css-extract-plugin`.
|
[
"Creates",
"an",
"instance",
"of",
"plugin",
"for",
"extracting",
"styles",
"in",
"a",
"file",
".",
"Either",
"extract",
"-",
"text",
"-",
"webpack",
"-",
"plugin",
"or",
"mini",
"-",
"css",
"-",
"extract",
"-",
"plugin",
"."
] |
3b022b50ed211a135525dcca9fe469a480abec69
|
https://github.com/catamphetamine/universal-webpack/blob/3b022b50ed211a135525dcca9fe469a480abec69/source/client configuration.js#L146-L170
|
16,146
|
catamphetamine/universal-webpack
|
source/client configuration.js
|
generate_extract_css_loaders
|
function generate_extract_css_loaders(after_style_loader, development, extract_css_plugin, useMiniCssExtractPlugin)
{
let extract_css_loaders
if (useMiniCssExtractPlugin)
{
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
return [{
loader: MiniCssExtractPlugin.loader
},
...after_style_loader]
}
// The first argument to the .extract() function is the name of the loader
// ("style-loader" in this case) to be applied to non-top-level-chunks in case of "allChunks: false" option.
// since in this configuration "allChunks: true" option is used, this first argument is irrelevant.
//
// `remove: false` ensures that the styles being extracted
// aren't erased from the chunk javascript file.
//
const extract_css_loader = extract_css_plugin.extract
({
remove : development ? false : true,
// `fallback` option is not really being used
// because `allChunks: true` option is used.
// fallback : before_style_loader,
use : after_style_loader
})
// Workaround for an old bug, may be obsolete now.
// https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/368
if (Array.isArray(extract_css_loader))
{
extract_css_loaders = extract_css_loader
}
else
{
extract_css_loaders =
[{
loader: extract_css_loader
}]
}
// I'm also prepending another `style-loader` here
// to re-enable adding these styles to the <head/> of the page on-the-fly.
if (development)
{
return [{
loader: 'style-loader'
},
...extract_css_loaders]
}
return extract_css_loaders
}
|
javascript
|
function generate_extract_css_loaders(after_style_loader, development, extract_css_plugin, useMiniCssExtractPlugin)
{
let extract_css_loaders
if (useMiniCssExtractPlugin)
{
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
return [{
loader: MiniCssExtractPlugin.loader
},
...after_style_loader]
}
// The first argument to the .extract() function is the name of the loader
// ("style-loader" in this case) to be applied to non-top-level-chunks in case of "allChunks: false" option.
// since in this configuration "allChunks: true" option is used, this first argument is irrelevant.
//
// `remove: false` ensures that the styles being extracted
// aren't erased from the chunk javascript file.
//
const extract_css_loader = extract_css_plugin.extract
({
remove : development ? false : true,
// `fallback` option is not really being used
// because `allChunks: true` option is used.
// fallback : before_style_loader,
use : after_style_loader
})
// Workaround for an old bug, may be obsolete now.
// https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/368
if (Array.isArray(extract_css_loader))
{
extract_css_loaders = extract_css_loader
}
else
{
extract_css_loaders =
[{
loader: extract_css_loader
}]
}
// I'm also prepending another `style-loader` here
// to re-enable adding these styles to the <head/> of the page on-the-fly.
if (development)
{
return [{
loader: 'style-loader'
},
...extract_css_loaders]
}
return extract_css_loaders
}
|
[
"function",
"generate_extract_css_loaders",
"(",
"after_style_loader",
",",
"development",
",",
"extract_css_plugin",
",",
"useMiniCssExtractPlugin",
")",
"{",
"let",
"extract_css_loaders",
"if",
"(",
"useMiniCssExtractPlugin",
")",
"{",
"const",
"MiniCssExtractPlugin",
"=",
"require",
"(",
"'mini-css-extract-plugin'",
")",
"return",
"[",
"{",
"loader",
":",
"MiniCssExtractPlugin",
".",
"loader",
"}",
",",
"...",
"after_style_loader",
"]",
"}",
"// The first argument to the .extract() function is the name of the loader",
"// (\"style-loader\" in this case) to be applied to non-top-level-chunks in case of \"allChunks: false\" option.",
"// since in this configuration \"allChunks: true\" option is used, this first argument is irrelevant.",
"//",
"// `remove: false` ensures that the styles being extracted",
"// aren't erased from the chunk javascript file.",
"//",
"const",
"extract_css_loader",
"=",
"extract_css_plugin",
".",
"extract",
"(",
"{",
"remove",
":",
"development",
"?",
"false",
":",
"true",
",",
"// `fallback` option is not really being used",
"// because `allChunks: true` option is used.",
"// fallback : before_style_loader,",
"use",
":",
"after_style_loader",
"}",
")",
"// Workaround for an old bug, may be obsolete now.",
"// https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/368",
"if",
"(",
"Array",
".",
"isArray",
"(",
"extract_css_loader",
")",
")",
"{",
"extract_css_loaders",
"=",
"extract_css_loader",
"}",
"else",
"{",
"extract_css_loaders",
"=",
"[",
"{",
"loader",
":",
"extract_css_loader",
"}",
"]",
"}",
"// I'm also prepending another `style-loader` here",
"// to re-enable adding these styles to the <head/> of the page on-the-fly.",
"if",
"(",
"development",
")",
"{",
"return",
"[",
"{",
"loader",
":",
"'style-loader'",
"}",
",",
"...",
"extract_css_loaders",
"]",
"}",
"return",
"extract_css_loaders",
"}"
] |
Generates rule.use loaders for extracting styles in a file.
Either for `extract-text-webpack-plugin` or `mini-css-extract-plugin`.
|
[
"Generates",
"rule",
".",
"use",
"loaders",
"for",
"extracting",
"styles",
"in",
"a",
"file",
".",
"Either",
"for",
"extract",
"-",
"text",
"-",
"webpack",
"-",
"plugin",
"or",
"mini",
"-",
"css",
"-",
"extract",
"-",
"plugin",
"."
] |
3b022b50ed211a135525dcca9fe469a480abec69
|
https://github.com/catamphetamine/universal-webpack/blob/3b022b50ed211a135525dcca9fe469a480abec69/source/client configuration.js#L176-L231
|
16,147
|
nnajm/orb
|
src/js/orb.axe.js
|
fill
|
function fill() {
if (self.pgrid.filteredDataSource != null && self.dimensionsCount > 0) {
var datasource = self.pgrid.filteredDataSource;
if (datasource != null && utils.isArray(datasource) && datasource.length > 0) {
for (var rowIndex = 0, dataLength = datasource.length; rowIndex < dataLength; rowIndex++) {
var row = datasource[rowIndex];
var dim = self.root;
for (var findex = 0; findex < self.dimensionsCount; findex++) {
var depth = self.dimensionsCount - findex;
var subfield = self.fields[findex];
var subvalue = row[subfield.name];
var subdimvals = dim.subdimvals;
if (subdimvals[subvalue] !== undefined) {
dim = subdimvals[subvalue];
} else {
dim.values.push(subvalue);
dim = new Dimension(++dimid, dim, subvalue, subfield, depth, false, findex == self.dimensionsCount - 1);
subdimvals[subvalue] = dim;
dim.rowIndexes = [];
self.dimensionsByDepth[depth].push(dim);
}
dim.rowIndexes.push(rowIndex);
}
}
}
}
}
|
javascript
|
function fill() {
if (self.pgrid.filteredDataSource != null && self.dimensionsCount > 0) {
var datasource = self.pgrid.filteredDataSource;
if (datasource != null && utils.isArray(datasource) && datasource.length > 0) {
for (var rowIndex = 0, dataLength = datasource.length; rowIndex < dataLength; rowIndex++) {
var row = datasource[rowIndex];
var dim = self.root;
for (var findex = 0; findex < self.dimensionsCount; findex++) {
var depth = self.dimensionsCount - findex;
var subfield = self.fields[findex];
var subvalue = row[subfield.name];
var subdimvals = dim.subdimvals;
if (subdimvals[subvalue] !== undefined) {
dim = subdimvals[subvalue];
} else {
dim.values.push(subvalue);
dim = new Dimension(++dimid, dim, subvalue, subfield, depth, false, findex == self.dimensionsCount - 1);
subdimvals[subvalue] = dim;
dim.rowIndexes = [];
self.dimensionsByDepth[depth].push(dim);
}
dim.rowIndexes.push(rowIndex);
}
}
}
}
}
|
[
"function",
"fill",
"(",
")",
"{",
"if",
"(",
"self",
".",
"pgrid",
".",
"filteredDataSource",
"!=",
"null",
"&&",
"self",
".",
"dimensionsCount",
">",
"0",
")",
"{",
"var",
"datasource",
"=",
"self",
".",
"pgrid",
".",
"filteredDataSource",
";",
"if",
"(",
"datasource",
"!=",
"null",
"&&",
"utils",
".",
"isArray",
"(",
"datasource",
")",
"&&",
"datasource",
".",
"length",
">",
"0",
")",
"{",
"for",
"(",
"var",
"rowIndex",
"=",
"0",
",",
"dataLength",
"=",
"datasource",
".",
"length",
";",
"rowIndex",
"<",
"dataLength",
";",
"rowIndex",
"++",
")",
"{",
"var",
"row",
"=",
"datasource",
"[",
"rowIndex",
"]",
";",
"var",
"dim",
"=",
"self",
".",
"root",
";",
"for",
"(",
"var",
"findex",
"=",
"0",
";",
"findex",
"<",
"self",
".",
"dimensionsCount",
";",
"findex",
"++",
")",
"{",
"var",
"depth",
"=",
"self",
".",
"dimensionsCount",
"-",
"findex",
";",
"var",
"subfield",
"=",
"self",
".",
"fields",
"[",
"findex",
"]",
";",
"var",
"subvalue",
"=",
"row",
"[",
"subfield",
".",
"name",
"]",
";",
"var",
"subdimvals",
"=",
"dim",
".",
"subdimvals",
";",
"if",
"(",
"subdimvals",
"[",
"subvalue",
"]",
"!==",
"undefined",
")",
"{",
"dim",
"=",
"subdimvals",
"[",
"subvalue",
"]",
";",
"}",
"else",
"{",
"dim",
".",
"values",
".",
"push",
"(",
"subvalue",
")",
";",
"dim",
"=",
"new",
"Dimension",
"(",
"++",
"dimid",
",",
"dim",
",",
"subvalue",
",",
"subfield",
",",
"depth",
",",
"false",
",",
"findex",
"==",
"self",
".",
"dimensionsCount",
"-",
"1",
")",
";",
"subdimvals",
"[",
"subvalue",
"]",
"=",
"dim",
";",
"dim",
".",
"rowIndexes",
"=",
"[",
"]",
";",
"self",
".",
"dimensionsByDepth",
"[",
"depth",
"]",
".",
"push",
"(",
"dim",
")",
";",
"}",
"dim",
".",
"rowIndexes",
".",
"push",
"(",
"rowIndex",
")",
";",
"}",
"}",
"}",
"}",
"}"
] |
Creates all subdimensions using the supplied data
|
[
"Creates",
"all",
"subdimensions",
"using",
"the",
"supplied",
"data"
] |
1c4438fd428f6b0cf2b421cfd5ed0cce436ab580
|
https://github.com/nnajm/orb/blob/1c4438fd428f6b0cf2b421cfd5ed0cce436ab580/src/js/orb.axe.js#L136-L166
|
16,148
|
nnajm/orb
|
src/js/orb.ui.cols.js
|
getUiInfo
|
function getUiInfo(depth, headers) {
var infos = headers[headers.length - 1];
var parents = self.axe.root.depth === depth ? [null] :
headers[self.axe.root.depth - depth - 1].filter(function(p) {
return p.type !== uiheaders.HeaderType.SUB_TOTAL;
});
for (var pi = 0; pi < parents.length; pi++) {
var parent = parents[pi];
var parentDim = parent == null ? self.axe.root : parent.dim;
for (var di = 0; di < parentDim.values.length; di++) {
var subvalue = parentDim.values[di];
var subdim = parentDim.subdimvals[subvalue];
var subtotalHeader;
if (!subdim.isLeaf && subdim.field.subTotal.visible) {
subtotalHeader = new uiheaders.header(axe.Type.COLUMNS, uiheaders.HeaderType.SUB_TOTAL, subdim, parent, self.dataFieldsCount());
} else {
subtotalHeader = null;
}
var header = new uiheaders.header(axe.Type.COLUMNS, null, subdim, parent, self.dataFieldsCount(), subtotalHeader);
infos.push(header);
if (!subdim.isLeaf && subdim.field.subTotal.visible) {
infos.push(subtotalHeader);
}
}
}
}
|
javascript
|
function getUiInfo(depth, headers) {
var infos = headers[headers.length - 1];
var parents = self.axe.root.depth === depth ? [null] :
headers[self.axe.root.depth - depth - 1].filter(function(p) {
return p.type !== uiheaders.HeaderType.SUB_TOTAL;
});
for (var pi = 0; pi < parents.length; pi++) {
var parent = parents[pi];
var parentDim = parent == null ? self.axe.root : parent.dim;
for (var di = 0; di < parentDim.values.length; di++) {
var subvalue = parentDim.values[di];
var subdim = parentDim.subdimvals[subvalue];
var subtotalHeader;
if (!subdim.isLeaf && subdim.field.subTotal.visible) {
subtotalHeader = new uiheaders.header(axe.Type.COLUMNS, uiheaders.HeaderType.SUB_TOTAL, subdim, parent, self.dataFieldsCount());
} else {
subtotalHeader = null;
}
var header = new uiheaders.header(axe.Type.COLUMNS, null, subdim, parent, self.dataFieldsCount(), subtotalHeader);
infos.push(header);
if (!subdim.isLeaf && subdim.field.subTotal.visible) {
infos.push(subtotalHeader);
}
}
}
}
|
[
"function",
"getUiInfo",
"(",
"depth",
",",
"headers",
")",
"{",
"var",
"infos",
"=",
"headers",
"[",
"headers",
".",
"length",
"-",
"1",
"]",
";",
"var",
"parents",
"=",
"self",
".",
"axe",
".",
"root",
".",
"depth",
"===",
"depth",
"?",
"[",
"null",
"]",
":",
"headers",
"[",
"self",
".",
"axe",
".",
"root",
".",
"depth",
"-",
"depth",
"-",
"1",
"]",
".",
"filter",
"(",
"function",
"(",
"p",
")",
"{",
"return",
"p",
".",
"type",
"!==",
"uiheaders",
".",
"HeaderType",
".",
"SUB_TOTAL",
";",
"}",
")",
";",
"for",
"(",
"var",
"pi",
"=",
"0",
";",
"pi",
"<",
"parents",
".",
"length",
";",
"pi",
"++",
")",
"{",
"var",
"parent",
"=",
"parents",
"[",
"pi",
"]",
";",
"var",
"parentDim",
"=",
"parent",
"==",
"null",
"?",
"self",
".",
"axe",
".",
"root",
":",
"parent",
".",
"dim",
";",
"for",
"(",
"var",
"di",
"=",
"0",
";",
"di",
"<",
"parentDim",
".",
"values",
".",
"length",
";",
"di",
"++",
")",
"{",
"var",
"subvalue",
"=",
"parentDim",
".",
"values",
"[",
"di",
"]",
";",
"var",
"subdim",
"=",
"parentDim",
".",
"subdimvals",
"[",
"subvalue",
"]",
";",
"var",
"subtotalHeader",
";",
"if",
"(",
"!",
"subdim",
".",
"isLeaf",
"&&",
"subdim",
".",
"field",
".",
"subTotal",
".",
"visible",
")",
"{",
"subtotalHeader",
"=",
"new",
"uiheaders",
".",
"header",
"(",
"axe",
".",
"Type",
".",
"COLUMNS",
",",
"uiheaders",
".",
"HeaderType",
".",
"SUB_TOTAL",
",",
"subdim",
",",
"parent",
",",
"self",
".",
"dataFieldsCount",
"(",
")",
")",
";",
"}",
"else",
"{",
"subtotalHeader",
"=",
"null",
";",
"}",
"var",
"header",
"=",
"new",
"uiheaders",
".",
"header",
"(",
"axe",
".",
"Type",
".",
"COLUMNS",
",",
"null",
",",
"subdim",
",",
"parent",
",",
"self",
".",
"dataFieldsCount",
"(",
")",
",",
"subtotalHeader",
")",
";",
"infos",
".",
"push",
"(",
"header",
")",
";",
"if",
"(",
"!",
"subdim",
".",
"isLeaf",
"&&",
"subdim",
".",
"field",
".",
"subTotal",
".",
"visible",
")",
"{",
"infos",
".",
"push",
"(",
"subtotalHeader",
")",
";",
"}",
"}",
"}",
"}"
] |
Fills the infos array given in argument with the dimension layout infos as column.
@param {orb.dimension} dimension - the dimension to get ui info for
@param {int} depth - the depth of the dimension that it's subdimensions will be returned
@param {object} infos - array to fill with ui dimension info
|
[
"Fills",
"the",
"infos",
"array",
"given",
"in",
"argument",
"with",
"the",
"dimension",
"layout",
"infos",
"as",
"column",
"."
] |
1c4438fd428f6b0cf2b421cfd5ed0cce436ab580
|
https://github.com/nnajm/orb/blob/1c4438fd428f6b0cf2b421cfd5ed0cce436ab580/src/js/orb.ui.cols.js#L136-L169
|
16,149
|
nnajm/orb
|
src/js/orb.utils.js
|
function(identifier, parent) {
var parts = identifier.split('.');
var i = 0;
parent = parent || window;
while (i < parts.length) {
parent[parts[i]] = parent[parts[i]] || {};
parent = parent[parts[i]];
i++;
}
return parent;
}
|
javascript
|
function(identifier, parent) {
var parts = identifier.split('.');
var i = 0;
parent = parent || window;
while (i < parts.length) {
parent[parts[i]] = parent[parts[i]] || {};
parent = parent[parts[i]];
i++;
}
return parent;
}
|
[
"function",
"(",
"identifier",
",",
"parent",
")",
"{",
"var",
"parts",
"=",
"identifier",
".",
"split",
"(",
"'.'",
")",
";",
"var",
"i",
"=",
"0",
";",
"parent",
"=",
"parent",
"||",
"window",
";",
"while",
"(",
"i",
"<",
"parts",
".",
"length",
")",
"{",
"parent",
"[",
"parts",
"[",
"i",
"]",
"]",
"=",
"parent",
"[",
"parts",
"[",
"i",
"]",
"]",
"||",
"{",
"}",
";",
"parent",
"=",
"parent",
"[",
"parts",
"[",
"i",
"]",
"]",
";",
"i",
"++",
";",
"}",
"return",
"parent",
";",
"}"
] |
Creates a namespcae hierarchy if not exists
@param {string} identifier - namespace identifier
@return {object}
|
[
"Creates",
"a",
"namespcae",
"hierarchy",
"if",
"not",
"exists"
] |
1c4438fd428f6b0cf2b421cfd5ed0cce436ab580
|
https://github.com/nnajm/orb/blob/1c4438fd428f6b0cf2b421cfd5ed0cce436ab580/src/js/orb.utils.js#L12-L22
|
|
16,150
|
nnajm/orb
|
src/js/orb.utils.js
|
function(obj) {
var arr = [];
for (var prop in obj) {
if (obj.hasOwnProperty(prop)) {
arr.push(prop);
}
}
return arr;
}
|
javascript
|
function(obj) {
var arr = [];
for (var prop in obj) {
if (obj.hasOwnProperty(prop)) {
arr.push(prop);
}
}
return arr;
}
|
[
"function",
"(",
"obj",
")",
"{",
"var",
"arr",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"prop",
"in",
"obj",
")",
"{",
"if",
"(",
"obj",
".",
"hasOwnProperty",
"(",
"prop",
")",
")",
"{",
"arr",
".",
"push",
"(",
"prop",
")",
";",
"}",
"}",
"return",
"arr",
";",
"}"
] |
Returns an array of object own properties
@param {Object} obj
@return {Array}
|
[
"Returns",
"an",
"array",
"of",
"object",
"own",
"properties"
] |
1c4438fd428f6b0cf2b421cfd5ed0cce436ab580
|
https://github.com/nnajm/orb/blob/1c4438fd428f6b0cf2b421cfd5ed0cce436ab580/src/js/orb.utils.js#L28-L36
|
|
16,151
|
nnajm/orb
|
src/js/orb.utils.js
|
function(array, predicate) {
if (this.isArray(array) && predicate) {
for (var i = 0; i < array.length; i++) {
var item = array[i];
if (predicate(item)) {
return item;
}
}
}
return undefined;
}
|
javascript
|
function(array, predicate) {
if (this.isArray(array) && predicate) {
for (var i = 0; i < array.length; i++) {
var item = array[i];
if (predicate(item)) {
return item;
}
}
}
return undefined;
}
|
[
"function",
"(",
"array",
",",
"predicate",
")",
"{",
"if",
"(",
"this",
".",
"isArray",
"(",
"array",
")",
"&&",
"predicate",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"array",
".",
"length",
";",
"i",
"++",
")",
"{",
"var",
"item",
"=",
"array",
"[",
"i",
"]",
";",
"if",
"(",
"predicate",
"(",
"item",
")",
")",
"{",
"return",
"item",
";",
"}",
"}",
"}",
"return",
"undefined",
";",
"}"
] |
Returns the first element in the array that satisfies the given predicate
@param {Array} array the array to search
@param {function} predicate Function to apply to each element until it returns true
@return {Object} The first object in the array that satisfies the predicate or undefined.
|
[
"Returns",
"the",
"first",
"element",
"in",
"the",
"array",
"that",
"satisfies",
"the",
"given",
"predicate"
] |
1c4438fd428f6b0cf2b421cfd5ed0cce436ab580
|
https://github.com/nnajm/orb/blob/1c4438fd428f6b0cf2b421cfd5ed0cce436ab580/src/js/orb.utils.js#L89-L99
|
|
16,152
|
nnajm/orb
|
src/js/orb.utils.js
|
function(obj, censorKeywords) {
function censor(key, value) {
return censorKeywords && censorKeywords.indexOf(key) > -1 ? undefined : value;
}
return JSON.stringify(obj, censor, 2);
}
|
javascript
|
function(obj, censorKeywords) {
function censor(key, value) {
return censorKeywords && censorKeywords.indexOf(key) > -1 ? undefined : value;
}
return JSON.stringify(obj, censor, 2);
}
|
[
"function",
"(",
"obj",
",",
"censorKeywords",
")",
"{",
"function",
"censor",
"(",
"key",
",",
"value",
")",
"{",
"return",
"censorKeywords",
"&&",
"censorKeywords",
".",
"indexOf",
"(",
"key",
")",
">",
"-",
"1",
"?",
"undefined",
":",
"value",
";",
"}",
"return",
"JSON",
".",
"stringify",
"(",
"obj",
",",
"censor",
",",
"2",
")",
";",
"}"
] |
Returns a JSON string represenation of an object
@param {object} obj
@return {string}
|
[
"Returns",
"a",
"JSON",
"string",
"represenation",
"of",
"an",
"object"
] |
1c4438fd428f6b0cf2b421cfd5ed0cce436ab580
|
https://github.com/nnajm/orb/blob/1c4438fd428f6b0cf2b421cfd5ed0cce436ab580/src/js/orb.utils.js#L105-L110
|
|
16,153
|
nnajm/orb
|
src/js/orb.ui.rows.js
|
getUiInfo
|
function getUiInfo(infos, dimension) {
if (dimension.values.length > 0) {
var infosMaxIndex = infos.length - 1;
var lastInfosArray = infos[infosMaxIndex];
var parent = lastInfosArray.length > 0 ? lastInfosArray[lastInfosArray.length - 1] : null;
for (var valIndex = 0; valIndex < dimension.values.length; valIndex++) {
var subvalue = dimension.values[valIndex];
var subdim = dimension.subdimvals[subvalue];
var subTotalHeader;
if (!subdim.isLeaf && subdim.field.subTotal.visible) {
subTotalHeader = new uiheaders.header(axe.Type.ROWS, uiheaders.HeaderType.SUB_TOTAL, subdim, parent, self.dataFieldsCount());
} else {
subTotalHeader = null;
}
var newHeader = new uiheaders.header(axe.Type.ROWS, null, subdim, parent, self.dataFieldsCount(), subTotalHeader);
if (valIndex > 0) {
infos.push((lastInfosArray = []));
}
lastInfosArray.push(newHeader);
if (!subdim.isLeaf) {
getUiInfo(infos, subdim);
if (subdim.field.subTotal.visible) {
infos.push([subTotalHeader]);
// add sub-total data headers if more than 1 data field and they will be the leaf headers
addDataHeaders(infos, subTotalHeader);
}
} else {
// add data headers if more than 1 data field and they will be the leaf headers
addDataHeaders(infos, newHeader);
}
}
}
}
|
javascript
|
function getUiInfo(infos, dimension) {
if (dimension.values.length > 0) {
var infosMaxIndex = infos.length - 1;
var lastInfosArray = infos[infosMaxIndex];
var parent = lastInfosArray.length > 0 ? lastInfosArray[lastInfosArray.length - 1] : null;
for (var valIndex = 0; valIndex < dimension.values.length; valIndex++) {
var subvalue = dimension.values[valIndex];
var subdim = dimension.subdimvals[subvalue];
var subTotalHeader;
if (!subdim.isLeaf && subdim.field.subTotal.visible) {
subTotalHeader = new uiheaders.header(axe.Type.ROWS, uiheaders.HeaderType.SUB_TOTAL, subdim, parent, self.dataFieldsCount());
} else {
subTotalHeader = null;
}
var newHeader = new uiheaders.header(axe.Type.ROWS, null, subdim, parent, self.dataFieldsCount(), subTotalHeader);
if (valIndex > 0) {
infos.push((lastInfosArray = []));
}
lastInfosArray.push(newHeader);
if (!subdim.isLeaf) {
getUiInfo(infos, subdim);
if (subdim.field.subTotal.visible) {
infos.push([subTotalHeader]);
// add sub-total data headers if more than 1 data field and they will be the leaf headers
addDataHeaders(infos, subTotalHeader);
}
} else {
// add data headers if more than 1 data field and they will be the leaf headers
addDataHeaders(infos, newHeader);
}
}
}
}
|
[
"function",
"getUiInfo",
"(",
"infos",
",",
"dimension",
")",
"{",
"if",
"(",
"dimension",
".",
"values",
".",
"length",
">",
"0",
")",
"{",
"var",
"infosMaxIndex",
"=",
"infos",
".",
"length",
"-",
"1",
";",
"var",
"lastInfosArray",
"=",
"infos",
"[",
"infosMaxIndex",
"]",
";",
"var",
"parent",
"=",
"lastInfosArray",
".",
"length",
">",
"0",
"?",
"lastInfosArray",
"[",
"lastInfosArray",
".",
"length",
"-",
"1",
"]",
":",
"null",
";",
"for",
"(",
"var",
"valIndex",
"=",
"0",
";",
"valIndex",
"<",
"dimension",
".",
"values",
".",
"length",
";",
"valIndex",
"++",
")",
"{",
"var",
"subvalue",
"=",
"dimension",
".",
"values",
"[",
"valIndex",
"]",
";",
"var",
"subdim",
"=",
"dimension",
".",
"subdimvals",
"[",
"subvalue",
"]",
";",
"var",
"subTotalHeader",
";",
"if",
"(",
"!",
"subdim",
".",
"isLeaf",
"&&",
"subdim",
".",
"field",
".",
"subTotal",
".",
"visible",
")",
"{",
"subTotalHeader",
"=",
"new",
"uiheaders",
".",
"header",
"(",
"axe",
".",
"Type",
".",
"ROWS",
",",
"uiheaders",
".",
"HeaderType",
".",
"SUB_TOTAL",
",",
"subdim",
",",
"parent",
",",
"self",
".",
"dataFieldsCount",
"(",
")",
")",
";",
"}",
"else",
"{",
"subTotalHeader",
"=",
"null",
";",
"}",
"var",
"newHeader",
"=",
"new",
"uiheaders",
".",
"header",
"(",
"axe",
".",
"Type",
".",
"ROWS",
",",
"null",
",",
"subdim",
",",
"parent",
",",
"self",
".",
"dataFieldsCount",
"(",
")",
",",
"subTotalHeader",
")",
";",
"if",
"(",
"valIndex",
">",
"0",
")",
"{",
"infos",
".",
"push",
"(",
"(",
"lastInfosArray",
"=",
"[",
"]",
")",
")",
";",
"}",
"lastInfosArray",
".",
"push",
"(",
"newHeader",
")",
";",
"if",
"(",
"!",
"subdim",
".",
"isLeaf",
")",
"{",
"getUiInfo",
"(",
"infos",
",",
"subdim",
")",
";",
"if",
"(",
"subdim",
".",
"field",
".",
"subTotal",
".",
"visible",
")",
"{",
"infos",
".",
"push",
"(",
"[",
"subTotalHeader",
"]",
")",
";",
"// add sub-total data headers if more than 1 data field and they will be the leaf headers",
"addDataHeaders",
"(",
"infos",
",",
"subTotalHeader",
")",
";",
"}",
"}",
"else",
"{",
"// add data headers if more than 1 data field and they will be the leaf headers",
"addDataHeaders",
"(",
"infos",
",",
"newHeader",
")",
";",
"}",
"}",
"}",
"}"
] |
Fills the infos array given in argument with the dimension layout infos as row.
@param {orb.dimension} dimension - the dimension to get ui info for
@param {object} infos - array to fill with ui dimension info
|
[
"Fills",
"the",
"infos",
"array",
"given",
"in",
"argument",
"with",
"the",
"dimension",
"layout",
"infos",
"as",
"row",
"."
] |
1c4438fd428f6b0cf2b421cfd5ed0cce436ab580
|
https://github.com/nnajm/orb/blob/1c4438fd428f6b0cf2b421cfd5ed0cce436ab580/src/js/orb.ui.rows.js#L80-L120
|
16,154
|
nnajm/orb
|
src/js/react/orb.react.compiled.js
|
setTableWidths
|
function setTableWidths(tblObject, newWidthArray) {
if (tblObject && tblObject.node) {
// reset table width
(tblObject.size = (tblObject.size || {})).width = 0;
var tbl = tblObject.node;
// for each row, set its cells width
for (var rowIndex = 0; rowIndex < tbl.rows.length; rowIndex++) {
// current row
var currRow = tbl.rows[rowIndex];
// index in newWidthArray
var arrayIndex = 0;
var currWidth = null;
// set width of each cell
for (var cellIndex = 0; cellIndex < currRow.cells.length; cellIndex++) {
// current cell
var currCell = currRow.cells[cellIndex];
if (currCell.__orb._visible) {
// cell width
var newCellWidth = 0;
// whether current cell spans vertically more than 1 row
var rowsSpan = currCell.__orb._rowSpan > 1 && rowIndex < tbl.rows.length - 1;
// current cell width is the sum of (its) "colspan" items in newWidthArray starting at 'arrayIndex'
// 'arrayIndex' should be incremented by an amount equal to current cell 'colspan' but should also skip 'inhibited' cells
for (var cspan = 0; cspan < currCell.__orb._colSpan; cspan++) {
currWidth = newWidthArray[arrayIndex];
// skip inhibited widths (width that belongs to an upper cell than spans vertically to current row)
while (currWidth && currWidth.inhibit > 0) {
currWidth.inhibit--;
arrayIndex++;
currWidth = newWidthArray[arrayIndex];
}
if (currWidth) {
// add width of cells participating in the span
newCellWidth += currWidth.width;
// if current cell spans vertically more than 1 row, mark its width as inhibited for all cells participating in this span
if (rowsSpan) {
currWidth.inhibit = currCell.__orb._rowSpan - 1;
}
// advance newWidthArray index
arrayIndex++;
}
}
currCell.children[0].style.width = newCellWidth + 'px';
// set table width (only in first iteration)
if (rowIndex === 0) {
var outerCellWidth = 0;
if (currCell.__orb) {
outerCellWidth = currCell.__orb._colSpan * (Math.ceil(currCell.__orb._paddingLeft + currCell.__orb._paddingRight + currCell.__orb._borderLeftWidth + currCell.__orb._borderRightWidth));
}
tblObject.size.width += newCellWidth + outerCellWidth;
}
}
}
// decrement inhibited state of all widths unsed in newWidthArray (not reached by current row cells)
currWidth = newWidthArray[arrayIndex];
while (currWidth) {
if (currWidth.inhibit > 0) {
currWidth.inhibit--;
}
arrayIndex++;
currWidth = newWidthArray[arrayIndex];
}
}
}
}
|
javascript
|
function setTableWidths(tblObject, newWidthArray) {
if (tblObject && tblObject.node) {
// reset table width
(tblObject.size = (tblObject.size || {})).width = 0;
var tbl = tblObject.node;
// for each row, set its cells width
for (var rowIndex = 0; rowIndex < tbl.rows.length; rowIndex++) {
// current row
var currRow = tbl.rows[rowIndex];
// index in newWidthArray
var arrayIndex = 0;
var currWidth = null;
// set width of each cell
for (var cellIndex = 0; cellIndex < currRow.cells.length; cellIndex++) {
// current cell
var currCell = currRow.cells[cellIndex];
if (currCell.__orb._visible) {
// cell width
var newCellWidth = 0;
// whether current cell spans vertically more than 1 row
var rowsSpan = currCell.__orb._rowSpan > 1 && rowIndex < tbl.rows.length - 1;
// current cell width is the sum of (its) "colspan" items in newWidthArray starting at 'arrayIndex'
// 'arrayIndex' should be incremented by an amount equal to current cell 'colspan' but should also skip 'inhibited' cells
for (var cspan = 0; cspan < currCell.__orb._colSpan; cspan++) {
currWidth = newWidthArray[arrayIndex];
// skip inhibited widths (width that belongs to an upper cell than spans vertically to current row)
while (currWidth && currWidth.inhibit > 0) {
currWidth.inhibit--;
arrayIndex++;
currWidth = newWidthArray[arrayIndex];
}
if (currWidth) {
// add width of cells participating in the span
newCellWidth += currWidth.width;
// if current cell spans vertically more than 1 row, mark its width as inhibited for all cells participating in this span
if (rowsSpan) {
currWidth.inhibit = currCell.__orb._rowSpan - 1;
}
// advance newWidthArray index
arrayIndex++;
}
}
currCell.children[0].style.width = newCellWidth + 'px';
// set table width (only in first iteration)
if (rowIndex === 0) {
var outerCellWidth = 0;
if (currCell.__orb) {
outerCellWidth = currCell.__orb._colSpan * (Math.ceil(currCell.__orb._paddingLeft + currCell.__orb._paddingRight + currCell.__orb._borderLeftWidth + currCell.__orb._borderRightWidth));
}
tblObject.size.width += newCellWidth + outerCellWidth;
}
}
}
// decrement inhibited state of all widths unsed in newWidthArray (not reached by current row cells)
currWidth = newWidthArray[arrayIndex];
while (currWidth) {
if (currWidth.inhibit > 0) {
currWidth.inhibit--;
}
arrayIndex++;
currWidth = newWidthArray[arrayIndex];
}
}
}
}
|
[
"function",
"setTableWidths",
"(",
"tblObject",
",",
"newWidthArray",
")",
"{",
"if",
"(",
"tblObject",
"&&",
"tblObject",
".",
"node",
")",
"{",
"// reset table width",
"(",
"tblObject",
".",
"size",
"=",
"(",
"tblObject",
".",
"size",
"||",
"{",
"}",
")",
")",
".",
"width",
"=",
"0",
";",
"var",
"tbl",
"=",
"tblObject",
".",
"node",
";",
"// for each row, set its cells width",
"for",
"(",
"var",
"rowIndex",
"=",
"0",
";",
"rowIndex",
"<",
"tbl",
".",
"rows",
".",
"length",
";",
"rowIndex",
"++",
")",
"{",
"// current row",
"var",
"currRow",
"=",
"tbl",
".",
"rows",
"[",
"rowIndex",
"]",
";",
"// index in newWidthArray",
"var",
"arrayIndex",
"=",
"0",
";",
"var",
"currWidth",
"=",
"null",
";",
"// set width of each cell",
"for",
"(",
"var",
"cellIndex",
"=",
"0",
";",
"cellIndex",
"<",
"currRow",
".",
"cells",
".",
"length",
";",
"cellIndex",
"++",
")",
"{",
"// current cell",
"var",
"currCell",
"=",
"currRow",
".",
"cells",
"[",
"cellIndex",
"]",
";",
"if",
"(",
"currCell",
".",
"__orb",
".",
"_visible",
")",
"{",
"// cell width",
"var",
"newCellWidth",
"=",
"0",
";",
"// whether current cell spans vertically more than 1 row",
"var",
"rowsSpan",
"=",
"currCell",
".",
"__orb",
".",
"_rowSpan",
">",
"1",
"&&",
"rowIndex",
"<",
"tbl",
".",
"rows",
".",
"length",
"-",
"1",
";",
"// current cell width is the sum of (its) \"colspan\" items in newWidthArray starting at 'arrayIndex'",
"// 'arrayIndex' should be incremented by an amount equal to current cell 'colspan' but should also skip 'inhibited' cells",
"for",
"(",
"var",
"cspan",
"=",
"0",
";",
"cspan",
"<",
"currCell",
".",
"__orb",
".",
"_colSpan",
";",
"cspan",
"++",
")",
"{",
"currWidth",
"=",
"newWidthArray",
"[",
"arrayIndex",
"]",
";",
"// skip inhibited widths (width that belongs to an upper cell than spans vertically to current row)",
"while",
"(",
"currWidth",
"&&",
"currWidth",
".",
"inhibit",
">",
"0",
")",
"{",
"currWidth",
".",
"inhibit",
"--",
";",
"arrayIndex",
"++",
";",
"currWidth",
"=",
"newWidthArray",
"[",
"arrayIndex",
"]",
";",
"}",
"if",
"(",
"currWidth",
")",
"{",
"// add width of cells participating in the span",
"newCellWidth",
"+=",
"currWidth",
".",
"width",
";",
"// if current cell spans vertically more than 1 row, mark its width as inhibited for all cells participating in this span",
"if",
"(",
"rowsSpan",
")",
"{",
"currWidth",
".",
"inhibit",
"=",
"currCell",
".",
"__orb",
".",
"_rowSpan",
"-",
"1",
";",
"}",
"// advance newWidthArray index",
"arrayIndex",
"++",
";",
"}",
"}",
"currCell",
".",
"children",
"[",
"0",
"]",
".",
"style",
".",
"width",
"=",
"newCellWidth",
"+",
"'px'",
";",
"// set table width (only in first iteration)",
"if",
"(",
"rowIndex",
"===",
"0",
")",
"{",
"var",
"outerCellWidth",
"=",
"0",
";",
"if",
"(",
"currCell",
".",
"__orb",
")",
"{",
"outerCellWidth",
"=",
"currCell",
".",
"__orb",
".",
"_colSpan",
"*",
"(",
"Math",
".",
"ceil",
"(",
"currCell",
".",
"__orb",
".",
"_paddingLeft",
"+",
"currCell",
".",
"__orb",
".",
"_paddingRight",
"+",
"currCell",
".",
"__orb",
".",
"_borderLeftWidth",
"+",
"currCell",
".",
"__orb",
".",
"_borderRightWidth",
")",
")",
";",
"}",
"tblObject",
".",
"size",
".",
"width",
"+=",
"newCellWidth",
"+",
"outerCellWidth",
";",
"}",
"}",
"}",
"// decrement inhibited state of all widths unsed in newWidthArray (not reached by current row cells)",
"currWidth",
"=",
"newWidthArray",
"[",
"arrayIndex",
"]",
";",
"while",
"(",
"currWidth",
")",
"{",
"if",
"(",
"currWidth",
".",
"inhibit",
">",
"0",
")",
"{",
"currWidth",
".",
"inhibit",
"--",
";",
"}",
"arrayIndex",
"++",
";",
"currWidth",
"=",
"newWidthArray",
"[",
"arrayIndex",
"]",
";",
"}",
"}",
"}",
"}"
] |
Sets the width of all cells of a html table element
@param {Object} tblObject - object having a table element in its 'node' property
@param {Array} newWidthArray - an array of numeric values representing the width of each individual cell.
Its length is equal to the greatest number of cells of all rows
(in case of cells having colSpan/rowSpan greater than 1.)
|
[
"Sets",
"the",
"width",
"of",
"all",
"cells",
"of",
"a",
"html",
"table",
"element"
] |
1c4438fd428f6b0cf2b421cfd5ed0cce436ab580
|
https://github.com/nnajm/orb/blob/1c4438fd428f6b0cf2b421cfd5ed0cce436ab580/src/js/react/orb.react.compiled.js#L522-L598
|
16,155
|
TamkeenLMS/electron-window-manager
|
index.js
|
function(name, title, url, setupTemplate, setup, showDevTools){
// Check if the window already exists
if(windowManager.windows[name]){
console.log('Window ' + name + ' already exists!');
// Move the focus on it
windowManager.focusOn(name);
return;
}
// The window unique name, if omitted a serialized name will be used instead; window_1 ~> window_2 ~> ...
this.name = name || ( 'window_' + ( Object.keys(windowManager.windows).length + 1 ) );
// The BrowserWindow module instance
this.object = null;
this.setup = {
'show': false,
'setupTemplate': setupTemplate
};
if(title) this.setup.title = title;
if(url) this.setup.url = url;
if(showDevTools) this.setup.showDevTools = showDevTools;
// If the setup is just the window dimensions, like '500x350'
if(isString(setup) && setup.indexOf('x') >= 0){
const dimensions = setup.split('x');
setup = {
'width': parseInt(dimensions[0], 10),
'height': parseInt(dimensions[1], 10)
};
}
// Overwrite the default setup
if(isObject(setup)){
this.setup = Object.assign(this.setup, setup);
}
// Register the window on the window manager
windowManager.windows[this.name] = this;
}
|
javascript
|
function(name, title, url, setupTemplate, setup, showDevTools){
// Check if the window already exists
if(windowManager.windows[name]){
console.log('Window ' + name + ' already exists!');
// Move the focus on it
windowManager.focusOn(name);
return;
}
// The window unique name, if omitted a serialized name will be used instead; window_1 ~> window_2 ~> ...
this.name = name || ( 'window_' + ( Object.keys(windowManager.windows).length + 1 ) );
// The BrowserWindow module instance
this.object = null;
this.setup = {
'show': false,
'setupTemplate': setupTemplate
};
if(title) this.setup.title = title;
if(url) this.setup.url = url;
if(showDevTools) this.setup.showDevTools = showDevTools;
// If the setup is just the window dimensions, like '500x350'
if(isString(setup) && setup.indexOf('x') >= 0){
const dimensions = setup.split('x');
setup = {
'width': parseInt(dimensions[0], 10),
'height': parseInt(dimensions[1], 10)
};
}
// Overwrite the default setup
if(isObject(setup)){
this.setup = Object.assign(this.setup, setup);
}
// Register the window on the window manager
windowManager.windows[this.name] = this;
}
|
[
"function",
"(",
"name",
",",
"title",
",",
"url",
",",
"setupTemplate",
",",
"setup",
",",
"showDevTools",
")",
"{",
"// Check if the window already exists",
"if",
"(",
"windowManager",
".",
"windows",
"[",
"name",
"]",
")",
"{",
"console",
".",
"log",
"(",
"'Window '",
"+",
"name",
"+",
"' already exists!'",
")",
";",
"// Move the focus on it",
"windowManager",
".",
"focusOn",
"(",
"name",
")",
";",
"return",
";",
"}",
"// The window unique name, if omitted a serialized name will be used instead; window_1 ~> window_2 ~> ...",
"this",
".",
"name",
"=",
"name",
"||",
"(",
"'window_'",
"+",
"(",
"Object",
".",
"keys",
"(",
"windowManager",
".",
"windows",
")",
".",
"length",
"+",
"1",
")",
")",
";",
"// The BrowserWindow module instance",
"this",
".",
"object",
"=",
"null",
";",
"this",
".",
"setup",
"=",
"{",
"'show'",
":",
"false",
",",
"'setupTemplate'",
":",
"setupTemplate",
"}",
";",
"if",
"(",
"title",
")",
"this",
".",
"setup",
".",
"title",
"=",
"title",
";",
"if",
"(",
"url",
")",
"this",
".",
"setup",
".",
"url",
"=",
"url",
";",
"if",
"(",
"showDevTools",
")",
"this",
".",
"setup",
".",
"showDevTools",
"=",
"showDevTools",
";",
"// If the setup is just the window dimensions, like '500x350'",
"if",
"(",
"isString",
"(",
"setup",
")",
"&&",
"setup",
".",
"indexOf",
"(",
"'x'",
")",
">=",
"0",
")",
"{",
"const",
"dimensions",
"=",
"setup",
".",
"split",
"(",
"'x'",
")",
";",
"setup",
"=",
"{",
"'width'",
":",
"parseInt",
"(",
"dimensions",
"[",
"0",
"]",
",",
"10",
")",
",",
"'height'",
":",
"parseInt",
"(",
"dimensions",
"[",
"1",
"]",
",",
"10",
")",
"}",
";",
"}",
"// Overwrite the default setup",
"if",
"(",
"isObject",
"(",
"setup",
")",
")",
"{",
"this",
".",
"setup",
"=",
"Object",
".",
"assign",
"(",
"this",
".",
"setup",
",",
"setup",
")",
";",
"}",
"// Register the window on the window manager",
"windowManager",
".",
"windows",
"[",
"this",
".",
"name",
"]",
"=",
"this",
";",
"}"
] |
Creates a new Window instance
@param name [optional] The code name for the window, each window must have a unique name
@param title [optional] The window title
@param url [optional] The targeted page/url of the window
@param setupTemplate [optional] The name of the setup template you want to use with this new window
@param setup [optional] The setup object that will be passed to the BrowserWindow module
@param showDevTools [optional] Whether to show the dev tools or not, false by default
|
[
"Creates",
"a",
"new",
"Window",
"instance"
] |
40b8fd06d14530c0e6bed1d0d91195f639d7081e
|
https://github.com/TamkeenLMS/electron-window-manager/blob/40b8fd06d14530c0e6bed1d0d91195f639d7081e/index.js#L38-L79
|
|
16,156
|
TamkeenLMS/electron-window-manager
|
index.js
|
function(name, setup){
if(!isObject(setup) || this.templates[name]) return false;
this.templates[name] = setup;
}
|
javascript
|
function(name, setup){
if(!isObject(setup) || this.templates[name]) return false;
this.templates[name] = setup;
}
|
[
"function",
"(",
"name",
",",
"setup",
")",
"{",
"if",
"(",
"!",
"isObject",
"(",
"setup",
")",
"||",
"this",
".",
"templates",
"[",
"name",
"]",
")",
"return",
"false",
";",
"this",
".",
"templates",
"[",
"name",
"]",
"=",
"setup",
";",
"}"
] |
Set a new template
|
[
"Set",
"a",
"new",
"template"
] |
40b8fd06d14530c0e6bed1d0d91195f639d7081e
|
https://github.com/TamkeenLMS/electron-window-manager/blob/40b8fd06d14530c0e6bed1d0d91195f639d7081e/index.js#L533-L537
|
|
16,157
|
TamkeenLMS/electron-window-manager
|
index.js
|
function(setup){
const screen = Electron.screen;
const screenSize = screen.getPrimaryDisplay().workAreaSize;
const position = setup.position;
let x = 0;
let y = 0;
const positionMargin = 0;
let windowWidth = setup.width;
let windowHeight = setup.height;
// If the window dimensions are not set
if(!windowWidth || !windowHeight){
console.log('Cannot position a window with the width/height not defined!');
// Put in in the center
setup.center = true;
return false;
}
// If the position name is incorrect
if(['center', 'top', 'right', 'bottom', 'left', 'topLeft', 'leftTop', 'topRight',
'rightTop', 'bottomRight', 'rightBottom', 'bottomLeft', 'leftBottom'].indexOf(position) < 0){
console.log('The specified position "' + position + '" is\'not correct! Check the docs.');
return false;
}
// It's center by default, no need to carry on
if(position === 'center'){
return false;
}
// Compensate for the frames
if (setup.frame === true) {
switch (position) {
case 'left':
break;
case 'right':
windowWidth += 8;
break;
case 'top':
windowWidth += 13;
break;
case 'bottom':
windowHeight += 50;
windowWidth += 13;
break;
case 'leftTop':
case 'topLeft':
windowWidth += 0;
windowHeight += 50;
break;
case 'rightTop':
case 'topRight':
windowWidth += 8;
windowHeight += 50;
break;
case 'leftBottom':
case 'bottomLeft':
windowWidth -= 0;
windowHeight += 50;
break;
case 'rightBottom':
case 'bottomRight':
windowWidth += 8;
windowHeight += 50;
break;
}
}
switch (position) {
case 'left':
y = Math.floor((screenSize.height - windowHeight) / 2);
x = positionMargin - 8;
break;
case 'right':
y = Math.floor((screenSize.height - windowHeight) / 2);
x = (screenSize.width - windowWidth) - positionMargin;
break;
case 'top':
y = positionMargin;
x = Math.floor((screenSize.width - windowWidth) / 2);
break;
case 'bottom':
y = (screenSize.height - windowHeight) - positionMargin;
x = Math.floor((screenSize.width - windowWidth) / 2);
break;
case 'leftTop':
case 'topLeft':
y = positionMargin;
x = positionMargin - 8;
break;
case 'rightTop':
case 'topRight':
y = positionMargin;
x = (screenSize.width - windowWidth) - positionMargin;
break;
case 'leftBottom':
case 'bottomLeft':
y = (screenSize.height - windowHeight) - positionMargin;
x = positionMargin - 8;
break;
case 'rightBottom':
case 'bottomRight':
y = (screenSize.height - windowHeight) - positionMargin;
x = (screenSize.width - windowWidth) - positionMargin;
break;
}
return [x, y];
}
|
javascript
|
function(setup){
const screen = Electron.screen;
const screenSize = screen.getPrimaryDisplay().workAreaSize;
const position = setup.position;
let x = 0;
let y = 0;
const positionMargin = 0;
let windowWidth = setup.width;
let windowHeight = setup.height;
// If the window dimensions are not set
if(!windowWidth || !windowHeight){
console.log('Cannot position a window with the width/height not defined!');
// Put in in the center
setup.center = true;
return false;
}
// If the position name is incorrect
if(['center', 'top', 'right', 'bottom', 'left', 'topLeft', 'leftTop', 'topRight',
'rightTop', 'bottomRight', 'rightBottom', 'bottomLeft', 'leftBottom'].indexOf(position) < 0){
console.log('The specified position "' + position + '" is\'not correct! Check the docs.');
return false;
}
// It's center by default, no need to carry on
if(position === 'center'){
return false;
}
// Compensate for the frames
if (setup.frame === true) {
switch (position) {
case 'left':
break;
case 'right':
windowWidth += 8;
break;
case 'top':
windowWidth += 13;
break;
case 'bottom':
windowHeight += 50;
windowWidth += 13;
break;
case 'leftTop':
case 'topLeft':
windowWidth += 0;
windowHeight += 50;
break;
case 'rightTop':
case 'topRight':
windowWidth += 8;
windowHeight += 50;
break;
case 'leftBottom':
case 'bottomLeft':
windowWidth -= 0;
windowHeight += 50;
break;
case 'rightBottom':
case 'bottomRight':
windowWidth += 8;
windowHeight += 50;
break;
}
}
switch (position) {
case 'left':
y = Math.floor((screenSize.height - windowHeight) / 2);
x = positionMargin - 8;
break;
case 'right':
y = Math.floor((screenSize.height - windowHeight) / 2);
x = (screenSize.width - windowWidth) - positionMargin;
break;
case 'top':
y = positionMargin;
x = Math.floor((screenSize.width - windowWidth) / 2);
break;
case 'bottom':
y = (screenSize.height - windowHeight) - positionMargin;
x = Math.floor((screenSize.width - windowWidth) / 2);
break;
case 'leftTop':
case 'topLeft':
y = positionMargin;
x = positionMargin - 8;
break;
case 'rightTop':
case 'topRight':
y = positionMargin;
x = (screenSize.width - windowWidth) - positionMargin;
break;
case 'leftBottom':
case 'bottomLeft':
y = (screenSize.height - windowHeight) - positionMargin;
x = positionMargin - 8;
break;
case 'rightBottom':
case 'bottomRight':
y = (screenSize.height - windowHeight) - positionMargin;
x = (screenSize.width - windowWidth) - positionMargin;
break;
}
return [x, y];
}
|
[
"function",
"(",
"setup",
")",
"{",
"const",
"screen",
"=",
"Electron",
".",
"screen",
";",
"const",
"screenSize",
"=",
"screen",
".",
"getPrimaryDisplay",
"(",
")",
".",
"workAreaSize",
";",
"const",
"position",
"=",
"setup",
".",
"position",
";",
"let",
"x",
"=",
"0",
";",
"let",
"y",
"=",
"0",
";",
"const",
"positionMargin",
"=",
"0",
";",
"let",
"windowWidth",
"=",
"setup",
".",
"width",
";",
"let",
"windowHeight",
"=",
"setup",
".",
"height",
";",
"// If the window dimensions are not set",
"if",
"(",
"!",
"windowWidth",
"||",
"!",
"windowHeight",
")",
"{",
"console",
".",
"log",
"(",
"'Cannot position a window with the width/height not defined!'",
")",
";",
"// Put in in the center",
"setup",
".",
"center",
"=",
"true",
";",
"return",
"false",
";",
"}",
"// If the position name is incorrect",
"if",
"(",
"[",
"'center'",
",",
"'top'",
",",
"'right'",
",",
"'bottom'",
",",
"'left'",
",",
"'topLeft'",
",",
"'leftTop'",
",",
"'topRight'",
",",
"'rightTop'",
",",
"'bottomRight'",
",",
"'rightBottom'",
",",
"'bottomLeft'",
",",
"'leftBottom'",
"]",
".",
"indexOf",
"(",
"position",
")",
"<",
"0",
")",
"{",
"console",
".",
"log",
"(",
"'The specified position \"'",
"+",
"position",
"+",
"'\" is\\'not correct! Check the docs.'",
")",
";",
"return",
"false",
";",
"}",
"// It's center by default, no need to carry on",
"if",
"(",
"position",
"===",
"'center'",
")",
"{",
"return",
"false",
";",
"}",
"// Compensate for the frames",
"if",
"(",
"setup",
".",
"frame",
"===",
"true",
")",
"{",
"switch",
"(",
"position",
")",
"{",
"case",
"'left'",
":",
"break",
";",
"case",
"'right'",
":",
"windowWidth",
"+=",
"8",
";",
"break",
";",
"case",
"'top'",
":",
"windowWidth",
"+=",
"13",
";",
"break",
";",
"case",
"'bottom'",
":",
"windowHeight",
"+=",
"50",
";",
"windowWidth",
"+=",
"13",
";",
"break",
";",
"case",
"'leftTop'",
":",
"case",
"'topLeft'",
":",
"windowWidth",
"+=",
"0",
";",
"windowHeight",
"+=",
"50",
";",
"break",
";",
"case",
"'rightTop'",
":",
"case",
"'topRight'",
":",
"windowWidth",
"+=",
"8",
";",
"windowHeight",
"+=",
"50",
";",
"break",
";",
"case",
"'leftBottom'",
":",
"case",
"'bottomLeft'",
":",
"windowWidth",
"-=",
"0",
";",
"windowHeight",
"+=",
"50",
";",
"break",
";",
"case",
"'rightBottom'",
":",
"case",
"'bottomRight'",
":",
"windowWidth",
"+=",
"8",
";",
"windowHeight",
"+=",
"50",
";",
"break",
";",
"}",
"}",
"switch",
"(",
"position",
")",
"{",
"case",
"'left'",
":",
"y",
"=",
"Math",
".",
"floor",
"(",
"(",
"screenSize",
".",
"height",
"-",
"windowHeight",
")",
"/",
"2",
")",
";",
"x",
"=",
"positionMargin",
"-",
"8",
";",
"break",
";",
"case",
"'right'",
":",
"y",
"=",
"Math",
".",
"floor",
"(",
"(",
"screenSize",
".",
"height",
"-",
"windowHeight",
")",
"/",
"2",
")",
";",
"x",
"=",
"(",
"screenSize",
".",
"width",
"-",
"windowWidth",
")",
"-",
"positionMargin",
";",
"break",
";",
"case",
"'top'",
":",
"y",
"=",
"positionMargin",
";",
"x",
"=",
"Math",
".",
"floor",
"(",
"(",
"screenSize",
".",
"width",
"-",
"windowWidth",
")",
"/",
"2",
")",
";",
"break",
";",
"case",
"'bottom'",
":",
"y",
"=",
"(",
"screenSize",
".",
"height",
"-",
"windowHeight",
")",
"-",
"positionMargin",
";",
"x",
"=",
"Math",
".",
"floor",
"(",
"(",
"screenSize",
".",
"width",
"-",
"windowWidth",
")",
"/",
"2",
")",
";",
"break",
";",
"case",
"'leftTop'",
":",
"case",
"'topLeft'",
":",
"y",
"=",
"positionMargin",
";",
"x",
"=",
"positionMargin",
"-",
"8",
";",
"break",
";",
"case",
"'rightTop'",
":",
"case",
"'topRight'",
":",
"y",
"=",
"positionMargin",
";",
"x",
"=",
"(",
"screenSize",
".",
"width",
"-",
"windowWidth",
")",
"-",
"positionMargin",
";",
"break",
";",
"case",
"'leftBottom'",
":",
"case",
"'bottomLeft'",
":",
"y",
"=",
"(",
"screenSize",
".",
"height",
"-",
"windowHeight",
")",
"-",
"positionMargin",
";",
"x",
"=",
"positionMargin",
"-",
"8",
";",
"break",
";",
"case",
"'rightBottom'",
":",
"case",
"'bottomRight'",
":",
"y",
"=",
"(",
"screenSize",
".",
"height",
"-",
"windowHeight",
")",
"-",
"positionMargin",
";",
"x",
"=",
"(",
"screenSize",
".",
"width",
"-",
"windowWidth",
")",
"-",
"positionMargin",
";",
"break",
";",
"}",
"return",
"[",
"x",
",",
"y",
"]",
";",
"}"
] |
Resolves a position name into x & y coordinates.
@param setup The window setup object
|
[
"Resolves",
"a",
"position",
"name",
"into",
"x",
"&",
"y",
"coordinates",
"."
] |
40b8fd06d14530c0e6bed1d0d91195f639d7081e
|
https://github.com/TamkeenLMS/electron-window-manager/blob/40b8fd06d14530c0e6bed1d0d91195f639d7081e/index.js#L595-L719
|
|
16,158
|
TamkeenLMS/electron-window-manager
|
index.js
|
function(config){
if(isString(config)){
this.config.appBase = config;
}else if(isObject(config)){// If the config object is provided
this.config = Object.assign(this.config, config);
}
// If the app base isn't provided
if(!this.config.appBase){
this.config.appBase = utils.getAppLocalPath();
}else if(this.config.appBase.length && this.config.appBase[this.config.appBase.length-1] !== '/'){
this.config.appBase += '/';
}
// If the layouts list was passed in the config
if(this.config.layouts && isObject(this.config.layouts)){
Object.keys(this.config.layouts).forEach(key => {
layouts.add(key, this.config.layouts[key]);
});
}
// If the dev mode is on
if(this.config.devMode === true){
// Attach some shortcuts
Application.on('ready', function(){
// Ctrl+F12 to toggle the dev tools
Shortcuts.register('CmdOrCtrl+F12', function(){
const window = windowManager.getCurrent();
if(window) window.toggleDevTools();
});
// Ctrl+R to reload the page
Shortcuts.register('CmdOrCtrl+R', function(){
const window = windowManager.getCurrent();
if(window) window.reload();
});
});
}
// If a default setup is provided
if(this.config.defaultSetup){
this.setDefaultSetup(this.config.defaultSetup);
delete this.config.defaultSetup;
}
}
|
javascript
|
function(config){
if(isString(config)){
this.config.appBase = config;
}else if(isObject(config)){// If the config object is provided
this.config = Object.assign(this.config, config);
}
// If the app base isn't provided
if(!this.config.appBase){
this.config.appBase = utils.getAppLocalPath();
}else if(this.config.appBase.length && this.config.appBase[this.config.appBase.length-1] !== '/'){
this.config.appBase += '/';
}
// If the layouts list was passed in the config
if(this.config.layouts && isObject(this.config.layouts)){
Object.keys(this.config.layouts).forEach(key => {
layouts.add(key, this.config.layouts[key]);
});
}
// If the dev mode is on
if(this.config.devMode === true){
// Attach some shortcuts
Application.on('ready', function(){
// Ctrl+F12 to toggle the dev tools
Shortcuts.register('CmdOrCtrl+F12', function(){
const window = windowManager.getCurrent();
if(window) window.toggleDevTools();
});
// Ctrl+R to reload the page
Shortcuts.register('CmdOrCtrl+R', function(){
const window = windowManager.getCurrent();
if(window) window.reload();
});
});
}
// If a default setup is provided
if(this.config.defaultSetup){
this.setDefaultSetup(this.config.defaultSetup);
delete this.config.defaultSetup;
}
}
|
[
"function",
"(",
"config",
")",
"{",
"if",
"(",
"isString",
"(",
"config",
")",
")",
"{",
"this",
".",
"config",
".",
"appBase",
"=",
"config",
";",
"}",
"else",
"if",
"(",
"isObject",
"(",
"config",
")",
")",
"{",
"// If the config object is provided",
"this",
".",
"config",
"=",
"Object",
".",
"assign",
"(",
"this",
".",
"config",
",",
"config",
")",
";",
"}",
"// If the app base isn't provided",
"if",
"(",
"!",
"this",
".",
"config",
".",
"appBase",
")",
"{",
"this",
".",
"config",
".",
"appBase",
"=",
"utils",
".",
"getAppLocalPath",
"(",
")",
";",
"}",
"else",
"if",
"(",
"this",
".",
"config",
".",
"appBase",
".",
"length",
"&&",
"this",
".",
"config",
".",
"appBase",
"[",
"this",
".",
"config",
".",
"appBase",
".",
"length",
"-",
"1",
"]",
"!==",
"'/'",
")",
"{",
"this",
".",
"config",
".",
"appBase",
"+=",
"'/'",
";",
"}",
"// If the layouts list was passed in the config",
"if",
"(",
"this",
".",
"config",
".",
"layouts",
"&&",
"isObject",
"(",
"this",
".",
"config",
".",
"layouts",
")",
")",
"{",
"Object",
".",
"keys",
"(",
"this",
".",
"config",
".",
"layouts",
")",
".",
"forEach",
"(",
"key",
"=>",
"{",
"layouts",
".",
"add",
"(",
"key",
",",
"this",
".",
"config",
".",
"layouts",
"[",
"key",
"]",
")",
";",
"}",
")",
";",
"}",
"// If the dev mode is on",
"if",
"(",
"this",
".",
"config",
".",
"devMode",
"===",
"true",
")",
"{",
"// Attach some shortcuts",
"Application",
".",
"on",
"(",
"'ready'",
",",
"function",
"(",
")",
"{",
"// Ctrl+F12 to toggle the dev tools",
"Shortcuts",
".",
"register",
"(",
"'CmdOrCtrl+F12'",
",",
"function",
"(",
")",
"{",
"const",
"window",
"=",
"windowManager",
".",
"getCurrent",
"(",
")",
";",
"if",
"(",
"window",
")",
"window",
".",
"toggleDevTools",
"(",
")",
";",
"}",
")",
";",
"// Ctrl+R to reload the page",
"Shortcuts",
".",
"register",
"(",
"'CmdOrCtrl+R'",
",",
"function",
"(",
")",
"{",
"const",
"window",
"=",
"windowManager",
".",
"getCurrent",
"(",
")",
";",
"if",
"(",
"window",
")",
"window",
".",
"reload",
"(",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
"// If a default setup is provided",
"if",
"(",
"this",
".",
"config",
".",
"defaultSetup",
")",
"{",
"this",
".",
"setDefaultSetup",
"(",
"this",
".",
"config",
".",
"defaultSetup",
")",
";",
"delete",
"this",
".",
"config",
".",
"defaultSetup",
";",
"}",
"}"
] |
Initiate the module
@param config The configuration for the module
|
[
"Initiate",
"the",
"module"
] |
40b8fd06d14530c0e6bed1d0d91195f639d7081e
|
https://github.com/TamkeenLMS/electron-window-manager/blob/40b8fd06d14530c0e6bed1d0d91195f639d7081e/index.js#L799-L846
|
|
16,159
|
TamkeenLMS/electron-window-manager
|
index.js
|
function(file){
const list = require(utils.getAppLocalPath() + file);
if(!isObject(list)) return false;
Object.keys(list).forEach(key => {
let window = list[key];
this.createNew(key, window.title, window.url, window.setupTemplate, window.setup);
});
}
|
javascript
|
function(file){
const list = require(utils.getAppLocalPath() + file);
if(!isObject(list)) return false;
Object.keys(list).forEach(key => {
let window = list[key];
this.createNew(key, window.title, window.url, window.setupTemplate, window.setup);
});
}
|
[
"function",
"(",
"file",
")",
"{",
"const",
"list",
"=",
"require",
"(",
"utils",
".",
"getAppLocalPath",
"(",
")",
"+",
"file",
")",
";",
"if",
"(",
"!",
"isObject",
"(",
"list",
")",
")",
"return",
"false",
";",
"Object",
".",
"keys",
"(",
"list",
")",
".",
"forEach",
"(",
"key",
"=>",
"{",
"let",
"window",
"=",
"list",
"[",
"key",
"]",
";",
"this",
".",
"createNew",
"(",
"key",
",",
"window",
".",
"title",
",",
"window",
".",
"url",
",",
"window",
".",
"setupTemplate",
",",
"window",
".",
"setup",
")",
";",
"}",
")",
";",
"}"
] |
Using this method you can create more than one window with the setup information retrieved from a JSON file.
|
[
"Using",
"this",
"method",
"you",
"can",
"create",
"more",
"than",
"one",
"window",
"with",
"the",
"setup",
"information",
"retrieved",
"from",
"a",
"JSON",
"file",
"."
] |
40b8fd06d14530c0e6bed1d0d91195f639d7081e
|
https://github.com/TamkeenLMS/electron-window-manager/blob/40b8fd06d14530c0e6bed1d0d91195f639d7081e/index.js#L866-L874
|
|
16,160
|
TamkeenLMS/electron-window-manager
|
index.js
|
function(name, title, url, setupTemplate, setup, showDevTools){
// Create the window instance
const window = new Window(name, title, url, setupTemplate, setup, showDevTools);
// If the window was created
return (window == null || Object.keys(window).length === 0) ?false :window;
}
|
javascript
|
function(name, title, url, setupTemplate, setup, showDevTools){
// Create the window instance
const window = new Window(name, title, url, setupTemplate, setup, showDevTools);
// If the window was created
return (window == null || Object.keys(window).length === 0) ?false :window;
}
|
[
"function",
"(",
"name",
",",
"title",
",",
"url",
",",
"setupTemplate",
",",
"setup",
",",
"showDevTools",
")",
"{",
"// Create the window instance",
"const",
"window",
"=",
"new",
"Window",
"(",
"name",
",",
"title",
",",
"url",
",",
"setupTemplate",
",",
"setup",
",",
"showDevTools",
")",
";",
"// If the window was created",
"return",
"(",
"window",
"==",
"null",
"||",
"Object",
".",
"keys",
"(",
"window",
")",
".",
"length",
"===",
"0",
")",
"?",
"false",
":",
"window",
";",
"}"
] |
Create a new window instance. Check the Window object for documentation.
|
[
"Create",
"a",
"new",
"window",
"instance",
".",
"Check",
"the",
"Window",
"object",
"for",
"documentation",
"."
] |
40b8fd06d14530c0e6bed1d0d91195f639d7081e
|
https://github.com/TamkeenLMS/electron-window-manager/blob/40b8fd06d14530c0e6bed1d0d91195f639d7081e/index.js#L879-L885
|
|
16,161
|
TamkeenLMS/electron-window-manager
|
index.js
|
function(name, title, content, setupTemplate, setup, showDevTools){
const window = this.createNew(name, title, content, setupTemplate, setup, showDevTools);
if(window) window.open();
return window;
}
|
javascript
|
function(name, title, content, setupTemplate, setup, showDevTools){
const window = this.createNew(name, title, content, setupTemplate, setup, showDevTools);
if(window) window.open();
return window;
}
|
[
"function",
"(",
"name",
",",
"title",
",",
"content",
",",
"setupTemplate",
",",
"setup",
",",
"showDevTools",
")",
"{",
"const",
"window",
"=",
"this",
".",
"createNew",
"(",
"name",
",",
"title",
",",
"content",
",",
"setupTemplate",
",",
"setup",
",",
"showDevTools",
")",
";",
"if",
"(",
"window",
")",
"window",
".",
"open",
"(",
")",
";",
"return",
"window",
";",
"}"
] |
Opens a new window
|
[
"Opens",
"a",
"new",
"window"
] |
40b8fd06d14530c0e6bed1d0d91195f639d7081e
|
https://github.com/TamkeenLMS/electron-window-manager/blob/40b8fd06d14530c0e6bed1d0d91195f639d7081e/index.js#L890-L894
|
|
16,162
|
TamkeenLMS/electron-window-manager
|
index.js
|
function(name){
const window = this.get(name);
if(!window) return;
return this.createNew(false, false, false, false, this.setup);
}
|
javascript
|
function(name){
const window = this.get(name);
if(!window) return;
return this.createNew(false, false, false, false, this.setup);
}
|
[
"function",
"(",
"name",
")",
"{",
"const",
"window",
"=",
"this",
".",
"get",
"(",
"name",
")",
";",
"if",
"(",
"!",
"window",
")",
"return",
";",
"return",
"this",
".",
"createNew",
"(",
"false",
",",
"false",
",",
"false",
",",
"false",
",",
"this",
".",
"setup",
")",
";",
"}"
] |
Create a clone of the passed window
|
[
"Create",
"a",
"clone",
"of",
"the",
"passed",
"window"
] |
40b8fd06d14530c0e6bed1d0d91195f639d7081e
|
https://github.com/TamkeenLMS/electron-window-manager/blob/40b8fd06d14530c0e6bed1d0d91195f639d7081e/index.js#L899-L904
|
|
16,163
|
TamkeenLMS/electron-window-manager
|
index.js
|
function(id) {
let instance;
Object.keys(this.windows).forEach(key => {
let window = this.windows[key];
if(window.object.id === id){
instance = window;
}
});
return instance;
}
|
javascript
|
function(id) {
let instance;
Object.keys(this.windows).forEach(key => {
let window = this.windows[key];
if(window.object.id === id){
instance = window;
}
});
return instance;
}
|
[
"function",
"(",
"id",
")",
"{",
"let",
"instance",
";",
"Object",
".",
"keys",
"(",
"this",
".",
"windows",
")",
".",
"forEach",
"(",
"key",
"=>",
"{",
"let",
"window",
"=",
"this",
".",
"windows",
"[",
"key",
"]",
";",
"if",
"(",
"window",
".",
"object",
".",
"id",
"===",
"id",
")",
"{",
"instance",
"=",
"window",
";",
"}",
"}",
")",
";",
"return",
"instance",
";",
"}"
] |
Get a window instance, by BrowserWindow instance id
|
[
"Get",
"a",
"window",
"instance",
"by",
"BrowserWindow",
"instance",
"id"
] |
40b8fd06d14530c0e6bed1d0d91195f639d7081e
|
https://github.com/TamkeenLMS/electron-window-manager/blob/40b8fd06d14530c0e6bed1d0d91195f639d7081e/index.js#L921-L930
|
|
16,164
|
TamkeenLMS/electron-window-manager
|
index.js
|
function(){
Object.keys(this.windows).forEach(key => {
let window = this.windows[key];
window.close();
});
}
|
javascript
|
function(){
Object.keys(this.windows).forEach(key => {
let window = this.windows[key];
window.close();
});
}
|
[
"function",
"(",
")",
"{",
"Object",
".",
"keys",
"(",
"this",
".",
"windows",
")",
".",
"forEach",
"(",
"key",
"=>",
"{",
"let",
"window",
"=",
"this",
".",
"windows",
"[",
"key",
"]",
";",
"window",
".",
"close",
"(",
")",
";",
"}",
")",
";",
"}"
] |
Close all windows created by this module
|
[
"Close",
"all",
"windows",
"created",
"by",
"this",
"module"
] |
40b8fd06d14530c0e6bed1d0d91195f639d7081e
|
https://github.com/TamkeenLMS/electron-window-manager/blob/40b8fd06d14530c0e6bed1d0d91195f639d7081e/index.js#L967-L972
|
|
16,165
|
TamkeenLMS/electron-window-manager
|
index.js
|
function(name){
// Get all the windows
const windows = BrowserWindow.getAllWindows();
// Get the window through the name
const windowID = this.get(name).object.id;
if(!windows.length || !windowID) return false;
// Loop through the windows, close all of them and focus on the targeted one
Object.keys(windows).forEach(key => {
let window = windows[key];
if(window.id !== windowID){
window.close();
}
});
this.get(name).focus();
}
|
javascript
|
function(name){
// Get all the windows
const windows = BrowserWindow.getAllWindows();
// Get the window through the name
const windowID = this.get(name).object.id;
if(!windows.length || !windowID) return false;
// Loop through the windows, close all of them and focus on the targeted one
Object.keys(windows).forEach(key => {
let window = windows[key];
if(window.id !== windowID){
window.close();
}
});
this.get(name).focus();
}
|
[
"function",
"(",
"name",
")",
"{",
"// Get all the windows",
"const",
"windows",
"=",
"BrowserWindow",
".",
"getAllWindows",
"(",
")",
";",
"// Get the window through the name",
"const",
"windowID",
"=",
"this",
".",
"get",
"(",
"name",
")",
".",
"object",
".",
"id",
";",
"if",
"(",
"!",
"windows",
".",
"length",
"||",
"!",
"windowID",
")",
"return",
"false",
";",
"// Loop through the windows, close all of them and focus on the targeted one",
"Object",
".",
"keys",
"(",
"windows",
")",
".",
"forEach",
"(",
"key",
"=>",
"{",
"let",
"window",
"=",
"windows",
"[",
"key",
"]",
";",
"if",
"(",
"window",
".",
"id",
"!==",
"windowID",
")",
"{",
"window",
".",
"close",
"(",
")",
";",
"}",
"}",
")",
";",
"this",
".",
"get",
"(",
"name",
")",
".",
"focus",
"(",
")",
";",
"}"
] |
Close all window except for one
|
[
"Close",
"all",
"window",
"except",
"for",
"one"
] |
40b8fd06d14530c0e6bed1d0d91195f639d7081e
|
https://github.com/TamkeenLMS/electron-window-manager/blob/40b8fd06d14530c0e6bed1d0d91195f639d7081e/index.js#L977-L994
|
|
16,166
|
TamkeenLMS/electron-window-manager
|
index.js
|
function(event, callback){
let id = windowManager.eventEmitter.listenerCount(event);
windowManager.eventEmitter.addListener(event, function(event){
callback.call(null, event.data, event.target, event.emittedBy);
});
return windowManager.eventEmitter.listeners(event)[id];
}
|
javascript
|
function(event, callback){
let id = windowManager.eventEmitter.listenerCount(event);
windowManager.eventEmitter.addListener(event, function(event){
callback.call(null, event.data, event.target, event.emittedBy);
});
return windowManager.eventEmitter.listeners(event)[id];
}
|
[
"function",
"(",
"event",
",",
"callback",
")",
"{",
"let",
"id",
"=",
"windowManager",
".",
"eventEmitter",
".",
"listenerCount",
"(",
"event",
")",
";",
"windowManager",
".",
"eventEmitter",
".",
"addListener",
"(",
"event",
",",
"function",
"(",
"event",
")",
"{",
"callback",
".",
"call",
"(",
"null",
",",
"event",
".",
"data",
",",
"event",
".",
"target",
",",
"event",
".",
"emittedBy",
")",
";",
"}",
")",
";",
"return",
"windowManager",
".",
"eventEmitter",
".",
"listeners",
"(",
"event",
")",
"[",
"id",
"]",
";",
"}"
] |
Sets the callback to trigger whenever an event is emitted
@param event The name of the event
@param callback The callback to trigger, this callback will be given the data passed (if any), and
the name of the targeted window and finally the name of the window that triggered/emitted the event
@return the handler that add into the event listeners array
|
[
"Sets",
"the",
"callback",
"to",
"trigger",
"whenever",
"an",
"event",
"is",
"emitted"
] |
40b8fd06d14530c0e6bed1d0d91195f639d7081e
|
https://github.com/TamkeenLMS/electron-window-manager/blob/40b8fd06d14530c0e6bed1d0d91195f639d7081e/index.js#L1107-L1115
|
|
16,167
|
rofrischmann/inline-style-prefixer
|
benchmark/packages/302/utils/getBrowserInformation.js
|
getBrowserInformation
|
function getBrowserInformation(userAgent) {
var browserInfo = _bowser2.default._detect(userAgent);
for (var browser in prefixByBrowser) {
if (browserInfo.hasOwnProperty(browser)) {
var prefix = prefixByBrowser[browser];
browserInfo.jsPrefix = prefix;
browserInfo.cssPrefix = '-' + prefix.toLowerCase() + '-';
break;
}
}
browserInfo.browserName = getBrowserName(browserInfo);
// For cordova IOS 8 the version is missing, set truncated osversion to prevent NaN
if (browserInfo.version) {
browserInfo.browserVersion = parseFloat(browserInfo.version);
} else {
browserInfo.browserVersion = parseInt(parseFloat(browserInfo.osversion), 10);
}
browserInfo.osVersion = parseFloat(browserInfo.osversion);
// iOS forces all browsers to use Safari under the hood
// as the Safari version seems to match the iOS version
// we just explicitely use the osversion instead
// https://github.com/rofrischmann/inline-style-prefixer/issues/72
if (browserInfo.browserName === 'ios_saf' && browserInfo.browserVersion > browserInfo.osVersion) {
browserInfo.browserVersion = browserInfo.osVersion;
}
// seperate native android chrome
// https://github.com/rofrischmann/inline-style-prefixer/issues/45
if (browserInfo.browserName === 'android' && browserInfo.chrome && browserInfo.browserVersion > 37) {
browserInfo.browserName = 'and_chr';
}
// For android < 4.4 we want to check the osversion
// not the chrome version, see issue #26
// https://github.com/rofrischmann/inline-style-prefixer/issues/26
if (browserInfo.browserName === 'android' && browserInfo.osVersion < 5) {
browserInfo.browserVersion = browserInfo.osVersion;
}
// Samsung browser are basically build on Chrome > 44
// https://github.com/rofrischmann/inline-style-prefixer/issues/102
if (browserInfo.browserName === 'android' && browserInfo.samsungBrowser) {
browserInfo.browserName = 'and_chr';
browserInfo.browserVersion = 44;
}
return browserInfo;
}
|
javascript
|
function getBrowserInformation(userAgent) {
var browserInfo = _bowser2.default._detect(userAgent);
for (var browser in prefixByBrowser) {
if (browserInfo.hasOwnProperty(browser)) {
var prefix = prefixByBrowser[browser];
browserInfo.jsPrefix = prefix;
browserInfo.cssPrefix = '-' + prefix.toLowerCase() + '-';
break;
}
}
browserInfo.browserName = getBrowserName(browserInfo);
// For cordova IOS 8 the version is missing, set truncated osversion to prevent NaN
if (browserInfo.version) {
browserInfo.browserVersion = parseFloat(browserInfo.version);
} else {
browserInfo.browserVersion = parseInt(parseFloat(browserInfo.osversion), 10);
}
browserInfo.osVersion = parseFloat(browserInfo.osversion);
// iOS forces all browsers to use Safari under the hood
// as the Safari version seems to match the iOS version
// we just explicitely use the osversion instead
// https://github.com/rofrischmann/inline-style-prefixer/issues/72
if (browserInfo.browserName === 'ios_saf' && browserInfo.browserVersion > browserInfo.osVersion) {
browserInfo.browserVersion = browserInfo.osVersion;
}
// seperate native android chrome
// https://github.com/rofrischmann/inline-style-prefixer/issues/45
if (browserInfo.browserName === 'android' && browserInfo.chrome && browserInfo.browserVersion > 37) {
browserInfo.browserName = 'and_chr';
}
// For android < 4.4 we want to check the osversion
// not the chrome version, see issue #26
// https://github.com/rofrischmann/inline-style-prefixer/issues/26
if (browserInfo.browserName === 'android' && browserInfo.osVersion < 5) {
browserInfo.browserVersion = browserInfo.osVersion;
}
// Samsung browser are basically build on Chrome > 44
// https://github.com/rofrischmann/inline-style-prefixer/issues/102
if (browserInfo.browserName === 'android' && browserInfo.samsungBrowser) {
browserInfo.browserName = 'and_chr';
browserInfo.browserVersion = 44;
}
return browserInfo;
}
|
[
"function",
"getBrowserInformation",
"(",
"userAgent",
")",
"{",
"var",
"browserInfo",
"=",
"_bowser2",
".",
"default",
".",
"_detect",
"(",
"userAgent",
")",
";",
"for",
"(",
"var",
"browser",
"in",
"prefixByBrowser",
")",
"{",
"if",
"(",
"browserInfo",
".",
"hasOwnProperty",
"(",
"browser",
")",
")",
"{",
"var",
"prefix",
"=",
"prefixByBrowser",
"[",
"browser",
"]",
";",
"browserInfo",
".",
"jsPrefix",
"=",
"prefix",
";",
"browserInfo",
".",
"cssPrefix",
"=",
"'-'",
"+",
"prefix",
".",
"toLowerCase",
"(",
")",
"+",
"'-'",
";",
"break",
";",
"}",
"}",
"browserInfo",
".",
"browserName",
"=",
"getBrowserName",
"(",
"browserInfo",
")",
";",
"// For cordova IOS 8 the version is missing, set truncated osversion to prevent NaN",
"if",
"(",
"browserInfo",
".",
"version",
")",
"{",
"browserInfo",
".",
"browserVersion",
"=",
"parseFloat",
"(",
"browserInfo",
".",
"version",
")",
";",
"}",
"else",
"{",
"browserInfo",
".",
"browserVersion",
"=",
"parseInt",
"(",
"parseFloat",
"(",
"browserInfo",
".",
"osversion",
")",
",",
"10",
")",
";",
"}",
"browserInfo",
".",
"osVersion",
"=",
"parseFloat",
"(",
"browserInfo",
".",
"osversion",
")",
";",
"// iOS forces all browsers to use Safari under the hood",
"// as the Safari version seems to match the iOS version",
"// we just explicitely use the osversion instead",
"// https://github.com/rofrischmann/inline-style-prefixer/issues/72",
"if",
"(",
"browserInfo",
".",
"browserName",
"===",
"'ios_saf'",
"&&",
"browserInfo",
".",
"browserVersion",
">",
"browserInfo",
".",
"osVersion",
")",
"{",
"browserInfo",
".",
"browserVersion",
"=",
"browserInfo",
".",
"osVersion",
";",
"}",
"// seperate native android chrome",
"// https://github.com/rofrischmann/inline-style-prefixer/issues/45",
"if",
"(",
"browserInfo",
".",
"browserName",
"===",
"'android'",
"&&",
"browserInfo",
".",
"chrome",
"&&",
"browserInfo",
".",
"browserVersion",
">",
"37",
")",
"{",
"browserInfo",
".",
"browserName",
"=",
"'and_chr'",
";",
"}",
"// For android < 4.4 we want to check the osversion",
"// not the chrome version, see issue #26",
"// https://github.com/rofrischmann/inline-style-prefixer/issues/26",
"if",
"(",
"browserInfo",
".",
"browserName",
"===",
"'android'",
"&&",
"browserInfo",
".",
"osVersion",
"<",
"5",
")",
"{",
"browserInfo",
".",
"browserVersion",
"=",
"browserInfo",
".",
"osVersion",
";",
"}",
"// Samsung browser are basically build on Chrome > 44",
"// https://github.com/rofrischmann/inline-style-prefixer/issues/102",
"if",
"(",
"browserInfo",
".",
"browserName",
"===",
"'android'",
"&&",
"browserInfo",
".",
"samsungBrowser",
")",
"{",
"browserInfo",
".",
"browserName",
"=",
"'and_chr'",
";",
"browserInfo",
".",
"browserVersion",
"=",
"44",
";",
"}",
"return",
"browserInfo",
";",
"}"
] |
Uses bowser to get default browser browserInformation such as version and name
Evaluates bowser browserInfo and adds vendorPrefix browserInformation
@param {string} userAgent - userAgent that gets evaluated
|
[
"Uses",
"bowser",
"to",
"get",
"default",
"browser",
"browserInformation",
"such",
"as",
"version",
"and",
"name",
"Evaluates",
"bowser",
"browserInfo",
"and",
"adds",
"vendorPrefix",
"browserInformation"
] |
07f2d5239e305e9e3ce89276e20ce088eb4940ac
|
https://github.com/rofrischmann/inline-style-prefixer/blob/07f2d5239e305e9e3ce89276e20ce088eb4940ac/benchmark/packages/302/utils/getBrowserInformation.js#L73-L126
|
16,168
|
baalexander/node-xmlrpc
|
lib/cookies.js
|
function(name) {
var cookie = this.cookies[name]
if (cookie && this.checkNotExpired(name)) {
return this.cookies[name].value
}
return null
}
|
javascript
|
function(name) {
var cookie = this.cookies[name]
if (cookie && this.checkNotExpired(name)) {
return this.cookies[name].value
}
return null
}
|
[
"function",
"(",
"name",
")",
"{",
"var",
"cookie",
"=",
"this",
".",
"cookies",
"[",
"name",
"]",
"if",
"(",
"cookie",
"&&",
"this",
".",
"checkNotExpired",
"(",
"name",
")",
")",
"{",
"return",
"this",
".",
"cookies",
"[",
"name",
"]",
".",
"value",
"}",
"return",
"null",
"}"
] |
Obtains value of the cookie with specified name.
This call checks expiration dates and does not return expired cookies.
@param {String} name cookie name
@return {String} cookie value or null
|
[
"Obtains",
"value",
"of",
"the",
"cookie",
"with",
"specified",
"name",
".",
"This",
"call",
"checks",
"expiration",
"dates",
"and",
"does",
"not",
"return",
"expired",
"cookies",
"."
] |
d9c88c4185e16637ed5a22c1b91c80e958e8d69e
|
https://github.com/baalexander/node-xmlrpc/blob/d9c88c4185e16637ed5a22c1b91c80e958e8d69e/lib/cookies.js#L17-L23
|
|
16,169
|
baalexander/node-xmlrpc
|
lib/cookies.js
|
function(name, value, options) {
var cookie = typeof options == 'object'
? {value: value, expires: options.expires, secure: options.secure || false, new: options.new || false}
: {value: value}
if (this.checkNotExpired(name, cookie)) {
this.cookies[name] = cookie
}
}
|
javascript
|
function(name, value, options) {
var cookie = typeof options == 'object'
? {value: value, expires: options.expires, secure: options.secure || false, new: options.new || false}
: {value: value}
if (this.checkNotExpired(name, cookie)) {
this.cookies[name] = cookie
}
}
|
[
"function",
"(",
"name",
",",
"value",
",",
"options",
")",
"{",
"var",
"cookie",
"=",
"typeof",
"options",
"==",
"'object'",
"?",
"{",
"value",
":",
"value",
",",
"expires",
":",
"options",
".",
"expires",
",",
"secure",
":",
"options",
".",
"secure",
"||",
"false",
",",
"new",
":",
"options",
".",
"new",
"||",
"false",
"}",
":",
"{",
"value",
":",
"value",
"}",
"if",
"(",
"this",
".",
"checkNotExpired",
"(",
"name",
",",
"cookie",
")",
")",
"{",
"this",
".",
"cookies",
"[",
"name",
"]",
"=",
"cookie",
"}",
"}"
] |
Sets cookie's value and optional options
@param {String} name cookie's name
@param {String} value value
@param {Object} options with the following fields:
- {Boolean} secure - is cookie secure or not (does not mean anything for now)
- {Date} expires - cookie's expiration date. If specified then cookie will disappear after that date
|
[
"Sets",
"cookie",
"s",
"value",
"and",
"optional",
"options"
] |
d9c88c4185e16637ed5a22c1b91c80e958e8d69e
|
https://github.com/baalexander/node-xmlrpc/blob/d9c88c4185e16637ed5a22c1b91c80e958e8d69e/lib/cookies.js#L33-L40
|
|
16,170
|
baalexander/node-xmlrpc
|
lib/cookies.js
|
function(headers) {
var cookies = headers['set-cookie']
if (cookies) {
cookies.forEach(function(c) {
var cookiesParams = c.split(';')
var cookiePair = cookiesParams.shift().split('=')
var options = {}
cookiesParams.forEach(function(param) {
param = param.trim()
if (param.toLowerCase().indexOf('expires') == 0) {
var date = param.split('=')[1].trim()
options.expires = new Date(date)
}
})
this.set(cookiePair[0].trim(), cookiePair[1].trim(), options)
}.bind(this))
}
}
|
javascript
|
function(headers) {
var cookies = headers['set-cookie']
if (cookies) {
cookies.forEach(function(c) {
var cookiesParams = c.split(';')
var cookiePair = cookiesParams.shift().split('=')
var options = {}
cookiesParams.forEach(function(param) {
param = param.trim()
if (param.toLowerCase().indexOf('expires') == 0) {
var date = param.split('=')[1].trim()
options.expires = new Date(date)
}
})
this.set(cookiePair[0].trim(), cookiePair[1].trim(), options)
}.bind(this))
}
}
|
[
"function",
"(",
"headers",
")",
"{",
"var",
"cookies",
"=",
"headers",
"[",
"'set-cookie'",
"]",
"if",
"(",
"cookies",
")",
"{",
"cookies",
".",
"forEach",
"(",
"function",
"(",
"c",
")",
"{",
"var",
"cookiesParams",
"=",
"c",
".",
"split",
"(",
"';'",
")",
"var",
"cookiePair",
"=",
"cookiesParams",
".",
"shift",
"(",
")",
".",
"split",
"(",
"'='",
")",
"var",
"options",
"=",
"{",
"}",
"cookiesParams",
".",
"forEach",
"(",
"function",
"(",
"param",
")",
"{",
"param",
"=",
"param",
".",
"trim",
"(",
")",
"if",
"(",
"param",
".",
"toLowerCase",
"(",
")",
".",
"indexOf",
"(",
"'expires'",
")",
"==",
"0",
")",
"{",
"var",
"date",
"=",
"param",
".",
"split",
"(",
"'='",
")",
"[",
"1",
"]",
".",
"trim",
"(",
")",
"options",
".",
"expires",
"=",
"new",
"Date",
"(",
"date",
")",
"}",
"}",
")",
"this",
".",
"set",
"(",
"cookiePair",
"[",
"0",
"]",
".",
"trim",
"(",
")",
",",
"cookiePair",
"[",
"1",
"]",
".",
"trim",
"(",
")",
",",
"options",
")",
"}",
".",
"bind",
"(",
"this",
")",
")",
"}",
"}"
] |
Parses headers from server's response for 'set-cookie' header and store cookie's values.
Also parses expiration date
@param headers
|
[
"Parses",
"headers",
"from",
"server",
"s",
"response",
"for",
"set",
"-",
"cookie",
"header",
"and",
"store",
"cookie",
"s",
"values",
".",
"Also",
"parses",
"expiration",
"date"
] |
d9c88c4185e16637ed5a22c1b91c80e958e8d69e
|
https://github.com/baalexander/node-xmlrpc/blob/d9c88c4185e16637ed5a22c1b91c80e958e8d69e/lib/cookies.js#L66-L83
|
|
16,171
|
baalexander/node-xmlrpc
|
lib/server.js
|
Server
|
function Server(options, isSecure, onListening) {
if (false === (this instanceof Server)) {
return new Server(options, isSecure)
}
onListening = onListening || function() {}
var that = this
// If a string URI is passed in, converts to URI fields
if (typeof options === 'string') {
options = url.parse(options)
options.host = options.hostname
options.path = options.pathname
}
function handleMethodCall(request, response) {
var deserializer = new Deserializer()
deserializer.deserializeMethodCall(request, function(error, methodName, params) {
if (Object.prototype.hasOwnProperty.call(that._events, methodName)) {
that.emit(methodName, null, params, function(error, value) {
var xml = null
if (error !== null) {
xml = Serializer.serializeFault(error)
}
else {
xml = Serializer.serializeMethodResponse(value)
}
response.writeHead(200, {'Content-Type': 'text/xml'})
response.end(xml)
})
}
else {
that.emit('NotFound', methodName, params)
response.writeHead(404)
response.end()
}
})
}
this.httpServer = isSecure ? https.createServer(options, handleMethodCall)
: http.createServer(handleMethodCall)
process.nextTick(function() {
this.httpServer.listen(options.port, options.host, onListening)
}.bind(this))
this.close = function(callback) {
this.httpServer.once('close', callback)
this.httpServer.close()
}.bind(this)
}
|
javascript
|
function Server(options, isSecure, onListening) {
if (false === (this instanceof Server)) {
return new Server(options, isSecure)
}
onListening = onListening || function() {}
var that = this
// If a string URI is passed in, converts to URI fields
if (typeof options === 'string') {
options = url.parse(options)
options.host = options.hostname
options.path = options.pathname
}
function handleMethodCall(request, response) {
var deserializer = new Deserializer()
deserializer.deserializeMethodCall(request, function(error, methodName, params) {
if (Object.prototype.hasOwnProperty.call(that._events, methodName)) {
that.emit(methodName, null, params, function(error, value) {
var xml = null
if (error !== null) {
xml = Serializer.serializeFault(error)
}
else {
xml = Serializer.serializeMethodResponse(value)
}
response.writeHead(200, {'Content-Type': 'text/xml'})
response.end(xml)
})
}
else {
that.emit('NotFound', methodName, params)
response.writeHead(404)
response.end()
}
})
}
this.httpServer = isSecure ? https.createServer(options, handleMethodCall)
: http.createServer(handleMethodCall)
process.nextTick(function() {
this.httpServer.listen(options.port, options.host, onListening)
}.bind(this))
this.close = function(callback) {
this.httpServer.once('close', callback)
this.httpServer.close()
}.bind(this)
}
|
[
"function",
"Server",
"(",
"options",
",",
"isSecure",
",",
"onListening",
")",
"{",
"if",
"(",
"false",
"===",
"(",
"this",
"instanceof",
"Server",
")",
")",
"{",
"return",
"new",
"Server",
"(",
"options",
",",
"isSecure",
")",
"}",
"onListening",
"=",
"onListening",
"||",
"function",
"(",
")",
"{",
"}",
"var",
"that",
"=",
"this",
"// If a string URI is passed in, converts to URI fields",
"if",
"(",
"typeof",
"options",
"===",
"'string'",
")",
"{",
"options",
"=",
"url",
".",
"parse",
"(",
"options",
")",
"options",
".",
"host",
"=",
"options",
".",
"hostname",
"options",
".",
"path",
"=",
"options",
".",
"pathname",
"}",
"function",
"handleMethodCall",
"(",
"request",
",",
"response",
")",
"{",
"var",
"deserializer",
"=",
"new",
"Deserializer",
"(",
")",
"deserializer",
".",
"deserializeMethodCall",
"(",
"request",
",",
"function",
"(",
"error",
",",
"methodName",
",",
"params",
")",
"{",
"if",
"(",
"Object",
".",
"prototype",
".",
"hasOwnProperty",
".",
"call",
"(",
"that",
".",
"_events",
",",
"methodName",
")",
")",
"{",
"that",
".",
"emit",
"(",
"methodName",
",",
"null",
",",
"params",
",",
"function",
"(",
"error",
",",
"value",
")",
"{",
"var",
"xml",
"=",
"null",
"if",
"(",
"error",
"!==",
"null",
")",
"{",
"xml",
"=",
"Serializer",
".",
"serializeFault",
"(",
"error",
")",
"}",
"else",
"{",
"xml",
"=",
"Serializer",
".",
"serializeMethodResponse",
"(",
"value",
")",
"}",
"response",
".",
"writeHead",
"(",
"200",
",",
"{",
"'Content-Type'",
":",
"'text/xml'",
"}",
")",
"response",
".",
"end",
"(",
"xml",
")",
"}",
")",
"}",
"else",
"{",
"that",
".",
"emit",
"(",
"'NotFound'",
",",
"methodName",
",",
"params",
")",
"response",
".",
"writeHead",
"(",
"404",
")",
"response",
".",
"end",
"(",
")",
"}",
"}",
")",
"}",
"this",
".",
"httpServer",
"=",
"isSecure",
"?",
"https",
".",
"createServer",
"(",
"options",
",",
"handleMethodCall",
")",
":",
"http",
".",
"createServer",
"(",
"handleMethodCall",
")",
"process",
".",
"nextTick",
"(",
"function",
"(",
")",
"{",
"this",
".",
"httpServer",
".",
"listen",
"(",
"options",
".",
"port",
",",
"options",
".",
"host",
",",
"onListening",
")",
"}",
".",
"bind",
"(",
"this",
")",
")",
"this",
".",
"close",
"=",
"function",
"(",
"callback",
")",
"{",
"this",
".",
"httpServer",
".",
"once",
"(",
"'close'",
",",
"callback",
")",
"this",
".",
"httpServer",
".",
"close",
"(",
")",
"}",
".",
"bind",
"(",
"this",
")",
"}"
] |
Creates a new Server object. Also creates an HTTP server to start listening
for XML-RPC method calls. Will emit an event with the XML-RPC call's method
name when receiving a method call.
@constructor
@param {Object|String} options - The HTTP server options. Either a URI string
(e.g. 'http://localhost:9090') or an object
with fields:
- {String} host - (optional)
- {Number} port
@param {Boolean} isSecure - True if using https for making calls,
otherwise false.
@return {Server}
|
[
"Creates",
"a",
"new",
"Server",
"object",
".",
"Also",
"creates",
"an",
"HTTP",
"server",
"to",
"start",
"listening",
"for",
"XML",
"-",
"RPC",
"method",
"calls",
".",
"Will",
"emit",
"an",
"event",
"with",
"the",
"XML",
"-",
"RPC",
"call",
"s",
"method",
"name",
"when",
"receiving",
"a",
"method",
"call",
"."
] |
d9c88c4185e16637ed5a22c1b91c80e958e8d69e
|
https://github.com/baalexander/node-xmlrpc/blob/d9c88c4185e16637ed5a22c1b91c80e958e8d69e/lib/server.js#L23-L72
|
16,172
|
baalexander/node-xmlrpc
|
lib/client.js
|
Client
|
function Client(options, isSecure) {
// Invokes with new if called without
if (false === (this instanceof Client)) {
return new Client(options, isSecure)
}
// If a string URI is passed in, converts to URI fields
if (typeof options === 'string') {
options = url.parse(options)
options.host = options.hostname
options.path = options.pathname
}
if (typeof options.url !== 'undefined') {
var parsedUrl = url.parse(options.url);
options.host = parsedUrl.hostname;
options.path = parsedUrl.pathname;
options.port = parsedUrl.port;
}
// Set the HTTP request headers
var headers = {
'User-Agent' : 'NodeJS XML-RPC Client'
, 'Content-Type' : 'text/xml'
, 'Accept' : 'text/xml'
, 'Accept-Charset' : 'UTF8'
, 'Connection' : 'Keep-Alive'
}
options.headers = options.headers || {}
if (options.headers.Authorization == null &&
options.basic_auth != null &&
options.basic_auth.user != null &&
options.basic_auth.pass != null)
{
var auth = options.basic_auth.user + ':' + options.basic_auth.pass
options.headers['Authorization'] = 'Basic ' + new Buffer(auth).toString('base64')
}
for (var attribute in headers) {
if (options.headers[attribute] === undefined) {
options.headers[attribute] = headers[attribute]
}
}
options.method = 'POST'
this.options = options
this.isSecure = isSecure
this.headersProcessors = {
processors: [],
composeRequest: function(headers) {
this.processors.forEach(function(p) {p.composeRequest(headers);})
},
parseResponse: function(headers) {
this.processors.forEach(function(p) {p.parseResponse(headers);})
}
};
if (options.cookies) {
this.cookies = new Cookies();
this.headersProcessors.processors.unshift(this.cookies);
}
}
|
javascript
|
function Client(options, isSecure) {
// Invokes with new if called without
if (false === (this instanceof Client)) {
return new Client(options, isSecure)
}
// If a string URI is passed in, converts to URI fields
if (typeof options === 'string') {
options = url.parse(options)
options.host = options.hostname
options.path = options.pathname
}
if (typeof options.url !== 'undefined') {
var parsedUrl = url.parse(options.url);
options.host = parsedUrl.hostname;
options.path = parsedUrl.pathname;
options.port = parsedUrl.port;
}
// Set the HTTP request headers
var headers = {
'User-Agent' : 'NodeJS XML-RPC Client'
, 'Content-Type' : 'text/xml'
, 'Accept' : 'text/xml'
, 'Accept-Charset' : 'UTF8'
, 'Connection' : 'Keep-Alive'
}
options.headers = options.headers || {}
if (options.headers.Authorization == null &&
options.basic_auth != null &&
options.basic_auth.user != null &&
options.basic_auth.pass != null)
{
var auth = options.basic_auth.user + ':' + options.basic_auth.pass
options.headers['Authorization'] = 'Basic ' + new Buffer(auth).toString('base64')
}
for (var attribute in headers) {
if (options.headers[attribute] === undefined) {
options.headers[attribute] = headers[attribute]
}
}
options.method = 'POST'
this.options = options
this.isSecure = isSecure
this.headersProcessors = {
processors: [],
composeRequest: function(headers) {
this.processors.forEach(function(p) {p.composeRequest(headers);})
},
parseResponse: function(headers) {
this.processors.forEach(function(p) {p.parseResponse(headers);})
}
};
if (options.cookies) {
this.cookies = new Cookies();
this.headersProcessors.processors.unshift(this.cookies);
}
}
|
[
"function",
"Client",
"(",
"options",
",",
"isSecure",
")",
"{",
"// Invokes with new if called without",
"if",
"(",
"false",
"===",
"(",
"this",
"instanceof",
"Client",
")",
")",
"{",
"return",
"new",
"Client",
"(",
"options",
",",
"isSecure",
")",
"}",
"// If a string URI is passed in, converts to URI fields",
"if",
"(",
"typeof",
"options",
"===",
"'string'",
")",
"{",
"options",
"=",
"url",
".",
"parse",
"(",
"options",
")",
"options",
".",
"host",
"=",
"options",
".",
"hostname",
"options",
".",
"path",
"=",
"options",
".",
"pathname",
"}",
"if",
"(",
"typeof",
"options",
".",
"url",
"!==",
"'undefined'",
")",
"{",
"var",
"parsedUrl",
"=",
"url",
".",
"parse",
"(",
"options",
".",
"url",
")",
";",
"options",
".",
"host",
"=",
"parsedUrl",
".",
"hostname",
";",
"options",
".",
"path",
"=",
"parsedUrl",
".",
"pathname",
";",
"options",
".",
"port",
"=",
"parsedUrl",
".",
"port",
";",
"}",
"// Set the HTTP request headers",
"var",
"headers",
"=",
"{",
"'User-Agent'",
":",
"'NodeJS XML-RPC Client'",
",",
"'Content-Type'",
":",
"'text/xml'",
",",
"'Accept'",
":",
"'text/xml'",
",",
"'Accept-Charset'",
":",
"'UTF8'",
",",
"'Connection'",
":",
"'Keep-Alive'",
"}",
"options",
".",
"headers",
"=",
"options",
".",
"headers",
"||",
"{",
"}",
"if",
"(",
"options",
".",
"headers",
".",
"Authorization",
"==",
"null",
"&&",
"options",
".",
"basic_auth",
"!=",
"null",
"&&",
"options",
".",
"basic_auth",
".",
"user",
"!=",
"null",
"&&",
"options",
".",
"basic_auth",
".",
"pass",
"!=",
"null",
")",
"{",
"var",
"auth",
"=",
"options",
".",
"basic_auth",
".",
"user",
"+",
"':'",
"+",
"options",
".",
"basic_auth",
".",
"pass",
"options",
".",
"headers",
"[",
"'Authorization'",
"]",
"=",
"'Basic '",
"+",
"new",
"Buffer",
"(",
"auth",
")",
".",
"toString",
"(",
"'base64'",
")",
"}",
"for",
"(",
"var",
"attribute",
"in",
"headers",
")",
"{",
"if",
"(",
"options",
".",
"headers",
"[",
"attribute",
"]",
"===",
"undefined",
")",
"{",
"options",
".",
"headers",
"[",
"attribute",
"]",
"=",
"headers",
"[",
"attribute",
"]",
"}",
"}",
"options",
".",
"method",
"=",
"'POST'",
"this",
".",
"options",
"=",
"options",
"this",
".",
"isSecure",
"=",
"isSecure",
"this",
".",
"headersProcessors",
"=",
"{",
"processors",
":",
"[",
"]",
",",
"composeRequest",
":",
"function",
"(",
"headers",
")",
"{",
"this",
".",
"processors",
".",
"forEach",
"(",
"function",
"(",
"p",
")",
"{",
"p",
".",
"composeRequest",
"(",
"headers",
")",
";",
"}",
")",
"}",
",",
"parseResponse",
":",
"function",
"(",
"headers",
")",
"{",
"this",
".",
"processors",
".",
"forEach",
"(",
"function",
"(",
"p",
")",
"{",
"p",
".",
"parseResponse",
"(",
"headers",
")",
";",
"}",
")",
"}",
"}",
";",
"if",
"(",
"options",
".",
"cookies",
")",
"{",
"this",
".",
"cookies",
"=",
"new",
"Cookies",
"(",
")",
";",
"this",
".",
"headersProcessors",
".",
"processors",
".",
"unshift",
"(",
"this",
".",
"cookies",
")",
";",
"}",
"}"
] |
Creates a Client object for making XML-RPC method calls.
@constructor
@param {Object|String} options - Server options to make the HTTP request to.
Either a URI string
(e.g. 'http://localhost:9090') or an object
with fields:
- {String} host - (optional)
- {Number} port
- {String} url - (optional) - may be used instead of host/port pair
- {Boolean} cookies - (optional) - if true then cookies returned by server will be stored and sent back on the next calls.
Also it will be possible to access/manipulate cookies via #setCookie/#getCookie methods
@param {Boolean} isSecure - True if using https for making calls,
otherwise false.
@return {Client}
|
[
"Creates",
"a",
"Client",
"object",
"for",
"making",
"XML",
"-",
"RPC",
"method",
"calls",
"."
] |
d9c88c4185e16637ed5a22c1b91c80e958e8d69e
|
https://github.com/baalexander/node-xmlrpc/blob/d9c88c4185e16637ed5a22c1b91c80e958e8d69e/lib/client.js#L25-L88
|
16,173
|
kyma-project/console
|
core/src/luigi-config/luigi-config.js
|
getNamespace
|
async function getNamespace(namespaceName) {
const cacheName = '_console_namespace_promise_cache_';
if (!window[cacheName]) {
window[cacheName] = {};
}
const cache = window[cacheName];
if (!cache[namespaceName]) {
cache[namespaceName] = fetchFromKyma(
`${k8sServerUrl}/api/v1/namespaces/${namespaceName}`
);
}
return await cache[namespaceName];
}
|
javascript
|
async function getNamespace(namespaceName) {
const cacheName = '_console_namespace_promise_cache_';
if (!window[cacheName]) {
window[cacheName] = {};
}
const cache = window[cacheName];
if (!cache[namespaceName]) {
cache[namespaceName] = fetchFromKyma(
`${k8sServerUrl}/api/v1/namespaces/${namespaceName}`
);
}
return await cache[namespaceName];
}
|
[
"async",
"function",
"getNamespace",
"(",
"namespaceName",
")",
"{",
"const",
"cacheName",
"=",
"'_console_namespace_promise_cache_'",
";",
"if",
"(",
"!",
"window",
"[",
"cacheName",
"]",
")",
"{",
"window",
"[",
"cacheName",
"]",
"=",
"{",
"}",
";",
"}",
"const",
"cache",
"=",
"window",
"[",
"cacheName",
"]",
";",
"if",
"(",
"!",
"cache",
"[",
"namespaceName",
"]",
")",
"{",
"cache",
"[",
"namespaceName",
"]",
"=",
"fetchFromKyma",
"(",
"`",
"${",
"k8sServerUrl",
"}",
"${",
"namespaceName",
"}",
"`",
")",
";",
"}",
"return",
"await",
"cache",
"[",
"namespaceName",
"]",
";",
"}"
] |
We're using Promise based caching approach, since we often
execute getNamespace twice at the same time and we only
want to do one rest call.
@param {string} namespaceName
@returns {Promise} nsPromise
|
[
"We",
"re",
"using",
"Promise",
"based",
"caching",
"approach",
"since",
"we",
"often",
"execute",
"getNamespace",
"twice",
"at",
"the",
"same",
"time",
"and",
"we",
"only",
"want",
"to",
"do",
"one",
"rest",
"call",
"."
] |
23b3d5a1809ffc806f9657a4e91f6701bf6a88ea
|
https://github.com/kyma-project/console/blob/23b3d5a1809ffc806f9657a4e91f6701bf6a88ea/core/src/luigi-config/luigi-config.js#L239-L251
|
16,174
|
jeff-collins/ment.io
|
ment.io/scripts.js
|
function(scope, element, attrs, ngModel) {
function read() {
var html = element.html();
// When we clear the content editable the browser leaves a <br> behind
// If strip-br attribute is provided then we strip this out
if (attrs.stripBr && html === '<br>') {
html = '';
}
ngModel.$setViewValue(html);
}
if(!ngModel) return; // do nothing if no ng-model
// Specify how UI should be updated
ngModel.$render = function() {
if (ngModel.$viewValue !== element.html()) {
element.html($sce.getTrustedHtml(ngModel.$viewValue || ''));
}
};
// Listen for change events to enable binding
element.on('blur keyup change', function() {
scope.$apply(read);
});
read(); // initialize
}
|
javascript
|
function(scope, element, attrs, ngModel) {
function read() {
var html = element.html();
// When we clear the content editable the browser leaves a <br> behind
// If strip-br attribute is provided then we strip this out
if (attrs.stripBr && html === '<br>') {
html = '';
}
ngModel.$setViewValue(html);
}
if(!ngModel) return; // do nothing if no ng-model
// Specify how UI should be updated
ngModel.$render = function() {
if (ngModel.$viewValue !== element.html()) {
element.html($sce.getTrustedHtml(ngModel.$viewValue || ''));
}
};
// Listen for change events to enable binding
element.on('blur keyup change', function() {
scope.$apply(read);
});
read(); // initialize
}
|
[
"function",
"(",
"scope",
",",
"element",
",",
"attrs",
",",
"ngModel",
")",
"{",
"function",
"read",
"(",
")",
"{",
"var",
"html",
"=",
"element",
".",
"html",
"(",
")",
";",
"// When we clear the content editable the browser leaves a <br> behind",
"// If strip-br attribute is provided then we strip this out",
"if",
"(",
"attrs",
".",
"stripBr",
"&&",
"html",
"===",
"'<br>'",
")",
"{",
"html",
"=",
"''",
";",
"}",
"ngModel",
".",
"$setViewValue",
"(",
"html",
")",
";",
"}",
"if",
"(",
"!",
"ngModel",
")",
"return",
";",
"// do nothing if no ng-model",
"// Specify how UI should be updated",
"ngModel",
".",
"$render",
"=",
"function",
"(",
")",
"{",
"if",
"(",
"ngModel",
".",
"$viewValue",
"!==",
"element",
".",
"html",
"(",
")",
")",
"{",
"element",
".",
"html",
"(",
"$sce",
".",
"getTrustedHtml",
"(",
"ngModel",
".",
"$viewValue",
"||",
"''",
")",
")",
";",
"}",
"}",
";",
"// Listen for change events to enable binding",
"element",
".",
"on",
"(",
"'blur keyup change'",
",",
"function",
"(",
")",
"{",
"scope",
".",
"$apply",
"(",
"read",
")",
";",
"}",
")",
";",
"read",
"(",
")",
";",
"// initialize",
"}"
] |
get a hold of NgModelController
|
[
"get",
"a",
"hold",
"of",
"NgModelController"
] |
ad2a0a98cee5f7779a78c62e9f9f4f8105bfa759
|
https://github.com/jeff-collins/ment.io/blob/ad2a0a98cee5f7779a78c62e9f9f4f8105bfa759/ment.io/scripts.js#L144-L169
|
|
16,175
|
Breeze/breeze.js
|
src/a40_entityMetadata.js
|
MetadataStore
|
function MetadataStore(config) {
config = config || { };
assertConfig(config)
.whereParam("namingConvention").isOptional().isInstanceOf(NamingConvention).withDefault(NamingConvention.defaultInstance)
.whereParam("localQueryComparisonOptions").isOptional().isInstanceOf(LocalQueryComparisonOptions).withDefault(LocalQueryComparisonOptions.defaultInstance)
.whereParam("serializerFn").isOptional().isFunction()
.applyAll(this);
this.dataServices = []; // array of dataServices;
this._resourceEntityTypeMap = {}; // key is resource name - value is qualified entityType name
this._structuralTypeMap = {}; // key is qualified structuraltype name - value is structuralType. ( structural = entityType or complexType).
this._shortNameMap = {}; // key is shortName, value is qualified name - does not need to be serialized.
this._ctorRegistry = {}; // key is either short or qual type name - value is ctor;
this._incompleteTypeMap = {}; // key is entityTypeName; value is array of nav props
this._incompleteComplexTypeMap = {}; // key is complexTypeName; value is array of complexType props
this._id = __id++;
this.metadataFetched = new Event("metadataFetched", this);
}
|
javascript
|
function MetadataStore(config) {
config = config || { };
assertConfig(config)
.whereParam("namingConvention").isOptional().isInstanceOf(NamingConvention).withDefault(NamingConvention.defaultInstance)
.whereParam("localQueryComparisonOptions").isOptional().isInstanceOf(LocalQueryComparisonOptions).withDefault(LocalQueryComparisonOptions.defaultInstance)
.whereParam("serializerFn").isOptional().isFunction()
.applyAll(this);
this.dataServices = []; // array of dataServices;
this._resourceEntityTypeMap = {}; // key is resource name - value is qualified entityType name
this._structuralTypeMap = {}; // key is qualified structuraltype name - value is structuralType. ( structural = entityType or complexType).
this._shortNameMap = {}; // key is shortName, value is qualified name - does not need to be serialized.
this._ctorRegistry = {}; // key is either short or qual type name - value is ctor;
this._incompleteTypeMap = {}; // key is entityTypeName; value is array of nav props
this._incompleteComplexTypeMap = {}; // key is complexTypeName; value is array of complexType props
this._id = __id++;
this.metadataFetched = new Event("metadataFetched", this);
}
|
[
"function",
"MetadataStore",
"(",
"config",
")",
"{",
"config",
"=",
"config",
"||",
"{",
"}",
";",
"assertConfig",
"(",
"config",
")",
".",
"whereParam",
"(",
"\"namingConvention\"",
")",
".",
"isOptional",
"(",
")",
".",
"isInstanceOf",
"(",
"NamingConvention",
")",
".",
"withDefault",
"(",
"NamingConvention",
".",
"defaultInstance",
")",
".",
"whereParam",
"(",
"\"localQueryComparisonOptions\"",
")",
".",
"isOptional",
"(",
")",
".",
"isInstanceOf",
"(",
"LocalQueryComparisonOptions",
")",
".",
"withDefault",
"(",
"LocalQueryComparisonOptions",
".",
"defaultInstance",
")",
".",
"whereParam",
"(",
"\"serializerFn\"",
")",
".",
"isOptional",
"(",
")",
".",
"isFunction",
"(",
")",
".",
"applyAll",
"(",
"this",
")",
";",
"this",
".",
"dataServices",
"=",
"[",
"]",
";",
"// array of dataServices;",
"this",
".",
"_resourceEntityTypeMap",
"=",
"{",
"}",
";",
"// key is resource name - value is qualified entityType name",
"this",
".",
"_structuralTypeMap",
"=",
"{",
"}",
";",
"// key is qualified structuraltype name - value is structuralType. ( structural = entityType or complexType).",
"this",
".",
"_shortNameMap",
"=",
"{",
"}",
";",
"// key is shortName, value is qualified name - does not need to be serialized.",
"this",
".",
"_ctorRegistry",
"=",
"{",
"}",
";",
"// key is either short or qual type name - value is ctor;",
"this",
".",
"_incompleteTypeMap",
"=",
"{",
"}",
";",
"// key is entityTypeName; value is array of nav props",
"this",
".",
"_incompleteComplexTypeMap",
"=",
"{",
"}",
";",
"// key is complexTypeName; value is array of complexType props",
"this",
".",
"_id",
"=",
"__id",
"++",
";",
"this",
".",
"metadataFetched",
"=",
"new",
"Event",
"(",
"\"metadataFetched\"",
",",
"this",
")",
";",
"}"
] |
Constructs a new MetadataStore.
@example
var ms = new MetadataStore();
The store can then be associated with an EntityManager
@example
var entityManager = new EntityManager( {
serviceName: "breeze/NorthwindIBModel",
metadataStore: ms
});
or for an existing EntityManager
@example
Assume em1 is an existing EntityManager
em1.setProperties( { metadataStore: ms });
@method <ctor> MetadataStore
@param [config] {Object} Configuration settings .
@param [config.namingConvention=NamingConvention.defaultInstance] {NamingConvention} NamingConvention to be used in mapping property names
between client and server. Uses the NamingConvention.defaultInstance if not specified.
@param [config.localQueryComparisonOptions=LocalQueryComparisonOptions.defaultInstance] {LocalQueryComparisonOptions} The LocalQueryComparisonOptions to be
used when performing "local queries" in order to match the semantics of queries against a remote service.
@param [config.serializerFn] A function that is used to mediate the serialization of instances of this type.
|
[
"Constructs",
"a",
"new",
"MetadataStore",
"."
] |
06b4919202bd20388847ce7d0cf57b6011cca158
|
https://github.com/Breeze/breeze.js/blob/06b4919202bd20388847ce7d0cf57b6011cca158/src/a40_entityMetadata.js#L69-L86
|
16,176
|
Breeze/breeze.js
|
src/a40_entityMetadata.js
|
parseTypeNameWithSchema
|
function parseTypeNameWithSchema(entityTypeName, schema) {
var result = parseTypeName(entityTypeName);
if (schema && schema.cSpaceOSpaceMapping) {
var ns = getNamespaceFor(result.shortTypeName, schema);
if (ns) {
result = makeTypeHash(result.shortTypeName, ns);
}
}
return result;
}
|
javascript
|
function parseTypeNameWithSchema(entityTypeName, schema) {
var result = parseTypeName(entityTypeName);
if (schema && schema.cSpaceOSpaceMapping) {
var ns = getNamespaceFor(result.shortTypeName, schema);
if (ns) {
result = makeTypeHash(result.shortTypeName, ns);
}
}
return result;
}
|
[
"function",
"parseTypeNameWithSchema",
"(",
"entityTypeName",
",",
"schema",
")",
"{",
"var",
"result",
"=",
"parseTypeName",
"(",
"entityTypeName",
")",
";",
"if",
"(",
"schema",
"&&",
"schema",
".",
"cSpaceOSpaceMapping",
")",
"{",
"var",
"ns",
"=",
"getNamespaceFor",
"(",
"result",
".",
"shortTypeName",
",",
"schema",
")",
";",
"if",
"(",
"ns",
")",
"{",
"result",
"=",
"makeTypeHash",
"(",
"result",
".",
"shortTypeName",
",",
"ns",
")",
";",
"}",
"}",
"return",
"result",
";",
"}"
] |
schema is only needed for navProperty type name
|
[
"schema",
"is",
"only",
"needed",
"for",
"navProperty",
"type",
"name"
] |
06b4919202bd20388847ce7d0cf57b6011cca158
|
https://github.com/Breeze/breeze.js/blob/06b4919202bd20388847ce7d0cf57b6011cca158/src/a40_entityMetadata.js#L1124-L1133
|
16,177
|
Breeze/breeze.js
|
src/a40_entityMetadata.js
|
ComplexType
|
function ComplexType(config) {
if (arguments.length > 1) {
throw new Error("The ComplexType ctor has a single argument that is a configuration object.");
}
assertConfig(config)
.whereParam("shortName").isNonEmptyString()
.whereParam("namespace").isString().isOptional().withDefault("")
.whereParam("dataProperties").isOptional()
.whereParam("isComplexType").isOptional().isBoolean() // needed because this ctor can get called from the addEntityType method which needs the isComplexType prop
.whereParam("custom").isOptional()
.applyAll(this);
this.name = qualifyTypeName(this.shortName, this.namespace);
this.isComplexType = true;
this.dataProperties = [];
this.complexProperties = [];
this.validators = [];
this.concurrencyProperties = [];
this.unmappedProperties = [];
this.navigationProperties = []; // not yet supported
this.keyProperties = []; // may be used later to enforce uniqueness on arrays of complextypes.
addProperties(this, config.dataProperties, DataProperty);
}
|
javascript
|
function ComplexType(config) {
if (arguments.length > 1) {
throw new Error("The ComplexType ctor has a single argument that is a configuration object.");
}
assertConfig(config)
.whereParam("shortName").isNonEmptyString()
.whereParam("namespace").isString().isOptional().withDefault("")
.whereParam("dataProperties").isOptional()
.whereParam("isComplexType").isOptional().isBoolean() // needed because this ctor can get called from the addEntityType method which needs the isComplexType prop
.whereParam("custom").isOptional()
.applyAll(this);
this.name = qualifyTypeName(this.shortName, this.namespace);
this.isComplexType = true;
this.dataProperties = [];
this.complexProperties = [];
this.validators = [];
this.concurrencyProperties = [];
this.unmappedProperties = [];
this.navigationProperties = []; // not yet supported
this.keyProperties = []; // may be used later to enforce uniqueness on arrays of complextypes.
addProperties(this, config.dataProperties, DataProperty);
}
|
[
"function",
"ComplexType",
"(",
"config",
")",
"{",
"if",
"(",
"arguments",
".",
"length",
">",
"1",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"The ComplexType ctor has a single argument that is a configuration object.\"",
")",
";",
"}",
"assertConfig",
"(",
"config",
")",
".",
"whereParam",
"(",
"\"shortName\"",
")",
".",
"isNonEmptyString",
"(",
")",
".",
"whereParam",
"(",
"\"namespace\"",
")",
".",
"isString",
"(",
")",
".",
"isOptional",
"(",
")",
".",
"withDefault",
"(",
"\"\"",
")",
".",
"whereParam",
"(",
"\"dataProperties\"",
")",
".",
"isOptional",
"(",
")",
".",
"whereParam",
"(",
"\"isComplexType\"",
")",
".",
"isOptional",
"(",
")",
".",
"isBoolean",
"(",
")",
"// needed because this ctor can get called from the addEntityType method which needs the isComplexType prop",
".",
"whereParam",
"(",
"\"custom\"",
")",
".",
"isOptional",
"(",
")",
".",
"applyAll",
"(",
"this",
")",
";",
"this",
".",
"name",
"=",
"qualifyTypeName",
"(",
"this",
".",
"shortName",
",",
"this",
".",
"namespace",
")",
";",
"this",
".",
"isComplexType",
"=",
"true",
";",
"this",
".",
"dataProperties",
"=",
"[",
"]",
";",
"this",
".",
"complexProperties",
"=",
"[",
"]",
";",
"this",
".",
"validators",
"=",
"[",
"]",
";",
"this",
".",
"concurrencyProperties",
"=",
"[",
"]",
";",
"this",
".",
"unmappedProperties",
"=",
"[",
"]",
";",
"this",
".",
"navigationProperties",
"=",
"[",
"]",
";",
"// not yet supported",
"this",
".",
"keyProperties",
"=",
"[",
"]",
";",
"// may be used later to enforce uniqueness on arrays of complextypes.",
"addProperties",
"(",
"this",
",",
"config",
".",
"dataProperties",
",",
"DataProperty",
")",
";",
"}"
] |
Container for all of the metadata about a specific type of Complex object.
@class ComplexType
@example
var complexType = new ComplexType( {
shortName: "address",
namespace: "myAppNamespace"
});
@method <ctor> ComplexType
@param config {Object} Configuration settings
@param config.shortName {String}
@param [config.namespace=""] {String}
@param [config.dataProperties] {Array of DataProperties}
@param [config.custom] {Object}
|
[
"Container",
"for",
"all",
"of",
"the",
"metadata",
"about",
"a",
"specific",
"type",
"of",
"Complex",
"object",
"."
] |
06b4919202bd20388847ce7d0cf57b6011cca158
|
https://github.com/Breeze/breeze.js/blob/06b4919202bd20388847ce7d0cf57b6011cca158/src/a40_entityMetadata.js#L2168-L2192
|
16,178
|
Breeze/breeze.js
|
src/a40_entityMetadata.js
|
parseTypeName
|
function parseTypeName(entityTypeName) {
if (!entityTypeName) {
return null;
}
var typeParts = entityTypeName.split(":#");
if (typeParts.length > 1) {
return makeTypeHash(typeParts[0], typeParts[1]);
}
if (__stringStartsWith(entityTypeName, MetadataStore.ANONTYPE_PREFIX)) {
var typeHash = makeTypeHash(entityTypeName);
typeHash.isAnonymous = true
return typeHash;
}
var entityTypeNameNoAssembly = entityTypeName.split(",")[0];
var typeParts = entityTypeNameNoAssembly.split(".");
if (typeParts.length > 1) {
var shortName = typeParts[typeParts.length - 1];
var namespaceParts = typeParts.slice(0, typeParts.length - 1);
var ns = namespaceParts.join(".");
return makeTypeHash(shortName, ns);
} else {
return makeTypeHash(entityTypeName);
}
}
|
javascript
|
function parseTypeName(entityTypeName) {
if (!entityTypeName) {
return null;
}
var typeParts = entityTypeName.split(":#");
if (typeParts.length > 1) {
return makeTypeHash(typeParts[0], typeParts[1]);
}
if (__stringStartsWith(entityTypeName, MetadataStore.ANONTYPE_PREFIX)) {
var typeHash = makeTypeHash(entityTypeName);
typeHash.isAnonymous = true
return typeHash;
}
var entityTypeNameNoAssembly = entityTypeName.split(",")[0];
var typeParts = entityTypeNameNoAssembly.split(".");
if (typeParts.length > 1) {
var shortName = typeParts[typeParts.length - 1];
var namespaceParts = typeParts.slice(0, typeParts.length - 1);
var ns = namespaceParts.join(".");
return makeTypeHash(shortName, ns);
} else {
return makeTypeHash(entityTypeName);
}
}
|
[
"function",
"parseTypeName",
"(",
"entityTypeName",
")",
"{",
"if",
"(",
"!",
"entityTypeName",
")",
"{",
"return",
"null",
";",
"}",
"var",
"typeParts",
"=",
"entityTypeName",
".",
"split",
"(",
"\":#\"",
")",
";",
"if",
"(",
"typeParts",
".",
"length",
">",
"1",
")",
"{",
"return",
"makeTypeHash",
"(",
"typeParts",
"[",
"0",
"]",
",",
"typeParts",
"[",
"1",
"]",
")",
";",
"}",
"if",
"(",
"__stringStartsWith",
"(",
"entityTypeName",
",",
"MetadataStore",
".",
"ANONTYPE_PREFIX",
")",
")",
"{",
"var",
"typeHash",
"=",
"makeTypeHash",
"(",
"entityTypeName",
")",
";",
"typeHash",
".",
"isAnonymous",
"=",
"true",
"return",
"typeHash",
";",
"}",
"var",
"entityTypeNameNoAssembly",
"=",
"entityTypeName",
".",
"split",
"(",
"\",\"",
")",
"[",
"0",
"]",
";",
"var",
"typeParts",
"=",
"entityTypeNameNoAssembly",
".",
"split",
"(",
"\".\"",
")",
";",
"if",
"(",
"typeParts",
".",
"length",
">",
"1",
")",
"{",
"var",
"shortName",
"=",
"typeParts",
"[",
"typeParts",
".",
"length",
"-",
"1",
"]",
";",
"var",
"namespaceParts",
"=",
"typeParts",
".",
"slice",
"(",
"0",
",",
"typeParts",
".",
"length",
"-",
"1",
")",
";",
"var",
"ns",
"=",
"namespaceParts",
".",
"join",
"(",
"\".\"",
")",
";",
"return",
"makeTypeHash",
"(",
"shortName",
",",
"ns",
")",
";",
"}",
"else",
"{",
"return",
"makeTypeHash",
"(",
"entityTypeName",
")",
";",
"}",
"}"
] |
functions shared between classes related to Metadata
|
[
"functions",
"shared",
"between",
"classes",
"related",
"to",
"Metadata"
] |
06b4919202bd20388847ce7d0cf57b6011cca158
|
https://github.com/Breeze/breeze.js/blob/06b4919202bd20388847ce7d0cf57b6011cca158/src/a40_entityMetadata.js#L3158-L3183
|
16,179
|
Breeze/breeze.js
|
src/a40_entityMetadata.js
|
addProperties
|
function addProperties(entityType, propObj, ctor) {
if (!propObj) return;
if (Array.isArray(propObj)) {
propObj.forEach(entityType._addPropertyCore.bind(entityType));
} else if (typeof (propObj) === 'object') {
for (var key in propObj) {
if (__hasOwnProperty(propObj, key)) {
var value = propObj[key];
value.name = key;
var prop = new ctor(value);
entityType._addPropertyCore(prop);
}
}
} else {
throw new Error("The 'dataProperties' or 'navigationProperties' values must be either an array of data/nav properties or an object where each property defines a data/nav property");
}
}
|
javascript
|
function addProperties(entityType, propObj, ctor) {
if (!propObj) return;
if (Array.isArray(propObj)) {
propObj.forEach(entityType._addPropertyCore.bind(entityType));
} else if (typeof (propObj) === 'object') {
for (var key in propObj) {
if (__hasOwnProperty(propObj, key)) {
var value = propObj[key];
value.name = key;
var prop = new ctor(value);
entityType._addPropertyCore(prop);
}
}
} else {
throw new Error("The 'dataProperties' or 'navigationProperties' values must be either an array of data/nav properties or an object where each property defines a data/nav property");
}
}
|
[
"function",
"addProperties",
"(",
"entityType",
",",
"propObj",
",",
"ctor",
")",
"{",
"if",
"(",
"!",
"propObj",
")",
"return",
";",
"if",
"(",
"Array",
".",
"isArray",
"(",
"propObj",
")",
")",
"{",
"propObj",
".",
"forEach",
"(",
"entityType",
".",
"_addPropertyCore",
".",
"bind",
"(",
"entityType",
")",
")",
";",
"}",
"else",
"if",
"(",
"typeof",
"(",
"propObj",
")",
"===",
"'object'",
")",
"{",
"for",
"(",
"var",
"key",
"in",
"propObj",
")",
"{",
"if",
"(",
"__hasOwnProperty",
"(",
"propObj",
",",
"key",
")",
")",
"{",
"var",
"value",
"=",
"propObj",
"[",
"key",
"]",
";",
"value",
".",
"name",
"=",
"key",
";",
"var",
"prop",
"=",
"new",
"ctor",
"(",
"value",
")",
";",
"entityType",
".",
"_addPropertyCore",
"(",
"prop",
")",
";",
"}",
"}",
"}",
"else",
"{",
"throw",
"new",
"Error",
"(",
"\"The 'dataProperties' or 'navigationProperties' values must be either an array of data/nav properties or an object where each property defines a data/nav property\"",
")",
";",
"}",
"}"
] |
Used by both ComplexType and EntityType
|
[
"Used",
"by",
"both",
"ComplexType",
"and",
"EntityType"
] |
06b4919202bd20388847ce7d0cf57b6011cca158
|
https://github.com/Breeze/breeze.js/blob/06b4919202bd20388847ce7d0cf57b6011cca158/src/a40_entityMetadata.js#L3206-L3223
|
16,180
|
Breeze/breeze.js
|
build/breeze.debug.js
|
__getOwnPropertyValues
|
function __getOwnPropertyValues(source) {
var result = [];
for (var name in source) {
if (__hasOwnProperty(source, name)) {
result.push(source[name]);
}
}
return result;
}
|
javascript
|
function __getOwnPropertyValues(source) {
var result = [];
for (var name in source) {
if (__hasOwnProperty(source, name)) {
result.push(source[name]);
}
}
return result;
}
|
[
"function",
"__getOwnPropertyValues",
"(",
"source",
")",
"{",
"var",
"result",
"=",
"[",
"]",
";",
"for",
"(",
"var",
"name",
"in",
"source",
")",
"{",
"if",
"(",
"__hasOwnProperty",
"(",
"source",
",",
"name",
")",
")",
"{",
"result",
".",
"push",
"(",
"source",
"[",
"name",
"]",
")",
";",
"}",
"}",
"return",
"result",
";",
"}"
] |
end functional extensions
|
[
"end",
"functional",
"extensions"
] |
06b4919202bd20388847ce7d0cf57b6011cca158
|
https://github.com/Breeze/breeze.js/blob/06b4919202bd20388847ce7d0cf57b6011cca158/build/breeze.debug.js#L114-L122
|
16,181
|
Breeze/breeze.js
|
build/breeze.debug.js
|
__toJSONSafe
|
function __toJSONSafe(obj, replacer) {
if (obj !== Object(obj)) return obj; // primitive value
if (obj._$visited) return undefined;
replacer = replacer || __safeReplacer;
if (obj.toJSON) {
var newObj = obj.toJSON();
if (newObj !== Object(newObj)) return newObj; // primitive value
if (newObj !== obj) return __toJSONSafe(newObj, replacer);
// toJSON returned the object unchanged.
obj = newObj;
}
obj._$visited = true;
var result;
if (obj instanceof Array) {
result = obj.map(function (o) {
return __toJSONSafe(o, replacer);
});
} else if (typeof (obj) === "function") {
result = undefined;
} else {
result = {};
for (var prop in obj) {
if (prop === "_$visited") continue;
var val = obj[prop];
if (replacer) {
val = replacer(prop, val);
if (val === undefined) continue;
}
val = __toJSONSafe(val, replacer);
if (val === undefined) continue;
result[prop] = val;
}
}
delete obj._$visited;
return result;
}
|
javascript
|
function __toJSONSafe(obj, replacer) {
if (obj !== Object(obj)) return obj; // primitive value
if (obj._$visited) return undefined;
replacer = replacer || __safeReplacer;
if (obj.toJSON) {
var newObj = obj.toJSON();
if (newObj !== Object(newObj)) return newObj; // primitive value
if (newObj !== obj) return __toJSONSafe(newObj, replacer);
// toJSON returned the object unchanged.
obj = newObj;
}
obj._$visited = true;
var result;
if (obj instanceof Array) {
result = obj.map(function (o) {
return __toJSONSafe(o, replacer);
});
} else if (typeof (obj) === "function") {
result = undefined;
} else {
result = {};
for (var prop in obj) {
if (prop === "_$visited") continue;
var val = obj[prop];
if (replacer) {
val = replacer(prop, val);
if (val === undefined) continue;
}
val = __toJSONSafe(val, replacer);
if (val === undefined) continue;
result[prop] = val;
}
}
delete obj._$visited;
return result;
}
|
[
"function",
"__toJSONSafe",
"(",
"obj",
",",
"replacer",
")",
"{",
"if",
"(",
"obj",
"!==",
"Object",
"(",
"obj",
")",
")",
"return",
"obj",
";",
"// primitive value",
"if",
"(",
"obj",
".",
"_$visited",
")",
"return",
"undefined",
";",
"replacer",
"=",
"replacer",
"||",
"__safeReplacer",
";",
"if",
"(",
"obj",
".",
"toJSON",
")",
"{",
"var",
"newObj",
"=",
"obj",
".",
"toJSON",
"(",
")",
";",
"if",
"(",
"newObj",
"!==",
"Object",
"(",
"newObj",
")",
")",
"return",
"newObj",
";",
"// primitive value",
"if",
"(",
"newObj",
"!==",
"obj",
")",
"return",
"__toJSONSafe",
"(",
"newObj",
",",
"replacer",
")",
";",
"// toJSON returned the object unchanged.",
"obj",
"=",
"newObj",
";",
"}",
"obj",
".",
"_$visited",
"=",
"true",
";",
"var",
"result",
";",
"if",
"(",
"obj",
"instanceof",
"Array",
")",
"{",
"result",
"=",
"obj",
".",
"map",
"(",
"function",
"(",
"o",
")",
"{",
"return",
"__toJSONSafe",
"(",
"o",
",",
"replacer",
")",
";",
"}",
")",
";",
"}",
"else",
"if",
"(",
"typeof",
"(",
"obj",
")",
"===",
"\"function\"",
")",
"{",
"result",
"=",
"undefined",
";",
"}",
"else",
"{",
"result",
"=",
"{",
"}",
";",
"for",
"(",
"var",
"prop",
"in",
"obj",
")",
"{",
"if",
"(",
"prop",
"===",
"\"_$visited\"",
")",
"continue",
";",
"var",
"val",
"=",
"obj",
"[",
"prop",
"]",
";",
"if",
"(",
"replacer",
")",
"{",
"val",
"=",
"replacer",
"(",
"prop",
",",
"val",
")",
";",
"if",
"(",
"val",
"===",
"undefined",
")",
"continue",
";",
"}",
"val",
"=",
"__toJSONSafe",
"(",
"val",
",",
"replacer",
")",
";",
"if",
"(",
"val",
"===",
"undefined",
")",
"continue",
";",
"result",
"[",
"prop",
"]",
"=",
"val",
";",
"}",
"}",
"delete",
"obj",
".",
"_$visited",
";",
"return",
"result",
";",
"}"
] |
safely perform toJSON logic on objects with cycles.
|
[
"safely",
"perform",
"toJSON",
"logic",
"on",
"objects",
"with",
"cycles",
"."
] |
06b4919202bd20388847ce7d0cf57b6011cca158
|
https://github.com/Breeze/breeze.js/blob/06b4919202bd20388847ce7d0cf57b6011cca158/build/breeze.debug.js#L216-L251
|
16,182
|
Breeze/breeze.js
|
build/breeze.debug.js
|
__resolveProperties
|
function __resolveProperties(sources, propertyNames) {
var r = {};
var length = sources.length;
propertyNames.forEach(function (pn) {
for (var i = 0; i < length; i++) {
var src = sources[i];
if (src) {
var val = src[pn];
if (val !== undefined) {
r[pn] = val;
break;
}
}
}
});
return r;
}
|
javascript
|
function __resolveProperties(sources, propertyNames) {
var r = {};
var length = sources.length;
propertyNames.forEach(function (pn) {
for (var i = 0; i < length; i++) {
var src = sources[i];
if (src) {
var val = src[pn];
if (val !== undefined) {
r[pn] = val;
break;
}
}
}
});
return r;
}
|
[
"function",
"__resolveProperties",
"(",
"sources",
",",
"propertyNames",
")",
"{",
"var",
"r",
"=",
"{",
"}",
";",
"var",
"length",
"=",
"sources",
".",
"length",
";",
"propertyNames",
".",
"forEach",
"(",
"function",
"(",
"pn",
")",
"{",
"for",
"(",
"var",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"{",
"var",
"src",
"=",
"sources",
"[",
"i",
"]",
";",
"if",
"(",
"src",
")",
"{",
"var",
"val",
"=",
"src",
"[",
"pn",
"]",
";",
"if",
"(",
"val",
"!==",
"undefined",
")",
"{",
"r",
"[",
"pn",
"]",
"=",
"val",
";",
"break",
";",
"}",
"}",
"}",
"}",
")",
";",
"return",
"r",
";",
"}"
] |
resolves the values of a list of properties by checking each property in multiple sources until a value is found.
|
[
"resolves",
"the",
"values",
"of",
"a",
"list",
"of",
"properties",
"by",
"checking",
"each",
"property",
"in",
"multiple",
"sources",
"until",
"a",
"value",
"is",
"found",
"."
] |
06b4919202bd20388847ce7d0cf57b6011cca158
|
https://github.com/Breeze/breeze.js/blob/06b4919202bd20388847ce7d0cf57b6011cca158/build/breeze.debug.js#L254-L270
|
16,183
|
Breeze/breeze.js
|
build/breeze.debug.js
|
__map
|
function __map(items, fn, includeNull) {
// whether to return nulls in array of results; default = true;
includeNull = includeNull == null ? true : includeNull;
if (items == null) return items;
var result;
if (Array.isArray(items)) {
result = [];
items.forEach(function (v, ix) {
var r = fn(v, ix);
if (r != null || includeNull) {
result[ix] = r;
}
});
} else {
result = fn(items);
}
return result;
}
|
javascript
|
function __map(items, fn, includeNull) {
// whether to return nulls in array of results; default = true;
includeNull = includeNull == null ? true : includeNull;
if (items == null) return items;
var result;
if (Array.isArray(items)) {
result = [];
items.forEach(function (v, ix) {
var r = fn(v, ix);
if (r != null || includeNull) {
result[ix] = r;
}
});
} else {
result = fn(items);
}
return result;
}
|
[
"function",
"__map",
"(",
"items",
",",
"fn",
",",
"includeNull",
")",
"{",
"// whether to return nulls in array of results; default = true;",
"includeNull",
"=",
"includeNull",
"==",
"null",
"?",
"true",
":",
"includeNull",
";",
"if",
"(",
"items",
"==",
"null",
")",
"return",
"items",
";",
"var",
"result",
";",
"if",
"(",
"Array",
".",
"isArray",
"(",
"items",
")",
")",
"{",
"result",
"=",
"[",
"]",
";",
"items",
".",
"forEach",
"(",
"function",
"(",
"v",
",",
"ix",
")",
"{",
"var",
"r",
"=",
"fn",
"(",
"v",
",",
"ix",
")",
";",
"if",
"(",
"r",
"!=",
"null",
"||",
"includeNull",
")",
"{",
"result",
"[",
"ix",
"]",
"=",
"r",
";",
"}",
"}",
")",
";",
"}",
"else",
"{",
"result",
"=",
"fn",
"(",
"items",
")",
";",
"}",
"return",
"result",
";",
"}"
] |
a version of Array.map that doesn't require an array, i.e. works on arrays and scalars.
|
[
"a",
"version",
"of",
"Array",
".",
"map",
"that",
"doesn",
"t",
"require",
"an",
"array",
"i",
".",
"e",
".",
"works",
"on",
"arrays",
"and",
"scalars",
"."
] |
06b4919202bd20388847ce7d0cf57b6011cca158
|
https://github.com/Breeze/breeze.js/blob/06b4919202bd20388847ce7d0cf57b6011cca158/build/breeze.debug.js#L286-L303
|
16,184
|
Breeze/breeze.js
|
build/breeze.debug.js
|
__getArray
|
function __getArray(source, propName) {
var arr = source[propName];
if (!arr) {
arr = [];
source[propName] = arr;
}
return arr;
}
|
javascript
|
function __getArray(source, propName) {
var arr = source[propName];
if (!arr) {
arr = [];
source[propName] = arr;
}
return arr;
}
|
[
"function",
"__getArray",
"(",
"source",
",",
"propName",
")",
"{",
"var",
"arr",
"=",
"source",
"[",
"propName",
"]",
";",
"if",
"(",
"!",
"arr",
")",
"{",
"arr",
"=",
"[",
"]",
";",
"source",
"[",
"propName",
"]",
"=",
"arr",
";",
"}",
"return",
"arr",
";",
"}"
] |
end of array functions returns and array for a source and a prop, and creates the prop if needed.
|
[
"end",
"of",
"array",
"functions",
"returns",
"and",
"array",
"for",
"a",
"source",
"and",
"a",
"prop",
"and",
"creates",
"the",
"prop",
"if",
"needed",
"."
] |
06b4919202bd20388847ce7d0cf57b6011cca158
|
https://github.com/Breeze/breeze.js/blob/06b4919202bd20388847ce7d0cf57b6011cca158/build/breeze.debug.js#L402-L409
|
16,185
|
Breeze/breeze.js
|
build/breeze.debug.js
|
__requireLibCore
|
function __requireLibCore(libName) {
var window = global.window;
if (!window) return; // Must run in a browser. Todo: add commonjs support
// get library from browser globals if we can
var lib = window[libName];
if (lib) return lib;
// if require exists, maybe require can get it.
// This method is synchronous so it can't load modules with AMD.
// It can only obtain modules from require that have already been loaded.
// Developer should bootstrap such that the breeze module
// loads after all other libraries that breeze should find with this method
// See documentation
var r = window.require;
if (r) { // if require exists
if (r.defined) { // require.defined is not standard and may not exist
// require.defined returns true if module has been loaded
return r.defined(libName) ? r(libName) : undefined;
} else {
// require.defined does not exist so we have to call require('libName') directly.
// The require('libName') overload is synchronous and does not load modules.
// It throws an exception if the module isn't already loaded.
try {
return r(libName);
} catch (e) {
// require('libName') threw because module not loaded
return;
}
}
}
}
|
javascript
|
function __requireLibCore(libName) {
var window = global.window;
if (!window) return; // Must run in a browser. Todo: add commonjs support
// get library from browser globals if we can
var lib = window[libName];
if (lib) return lib;
// if require exists, maybe require can get it.
// This method is synchronous so it can't load modules with AMD.
// It can only obtain modules from require that have already been loaded.
// Developer should bootstrap such that the breeze module
// loads after all other libraries that breeze should find with this method
// See documentation
var r = window.require;
if (r) { // if require exists
if (r.defined) { // require.defined is not standard and may not exist
// require.defined returns true if module has been loaded
return r.defined(libName) ? r(libName) : undefined;
} else {
// require.defined does not exist so we have to call require('libName') directly.
// The require('libName') overload is synchronous and does not load modules.
// It throws an exception if the module isn't already loaded.
try {
return r(libName);
} catch (e) {
// require('libName') threw because module not loaded
return;
}
}
}
}
|
[
"function",
"__requireLibCore",
"(",
"libName",
")",
"{",
"var",
"window",
"=",
"global",
".",
"window",
";",
"if",
"(",
"!",
"window",
")",
"return",
";",
"// Must run in a browser. Todo: add commonjs support",
"// get library from browser globals if we can",
"var",
"lib",
"=",
"window",
"[",
"libName",
"]",
";",
"if",
"(",
"lib",
")",
"return",
"lib",
";",
"// if require exists, maybe require can get it.",
"// This method is synchronous so it can't load modules with AMD.",
"// It can only obtain modules from require that have already been loaded.",
"// Developer should bootstrap such that the breeze module",
"// loads after all other libraries that breeze should find with this method",
"// See documentation",
"var",
"r",
"=",
"window",
".",
"require",
";",
"if",
"(",
"r",
")",
"{",
"// if require exists",
"if",
"(",
"r",
".",
"defined",
")",
"{",
"// require.defined is not standard and may not exist",
"// require.defined returns true if module has been loaded",
"return",
"r",
".",
"defined",
"(",
"libName",
")",
"?",
"r",
"(",
"libName",
")",
":",
"undefined",
";",
"}",
"else",
"{",
"// require.defined does not exist so we have to call require('libName') directly.",
"// The require('libName') overload is synchronous and does not load modules.",
"// It throws an exception if the module isn't already loaded.",
"try",
"{",
"return",
"r",
"(",
"libName",
")",
";",
"}",
"catch",
"(",
"e",
")",
"{",
"// require('libName') threw because module not loaded",
"return",
";",
"}",
"}",
"}",
"}"
] |
Returns the 'libName' module if loaded or else returns undefined
|
[
"Returns",
"the",
"libName",
"module",
"if",
"loaded",
"or",
"else",
"returns",
"undefined"
] |
06b4919202bd20388847ce7d0cf57b6011cca158
|
https://github.com/Breeze/breeze.js/blob/06b4919202bd20388847ce7d0cf57b6011cca158/build/breeze.debug.js#L423-L454
|
16,186
|
Breeze/breeze.js
|
build/breeze.debug.js
|
__isPrimitive
|
function __isPrimitive(obj) {
if (obj == null) return false;
// true for numbers, strings, booleans and null, false for objects
if (obj != Object(obj)) return true;
return __isDate(obj);
}
|
javascript
|
function __isPrimitive(obj) {
if (obj == null) return false;
// true for numbers, strings, booleans and null, false for objects
if (obj != Object(obj)) return true;
return __isDate(obj);
}
|
[
"function",
"__isPrimitive",
"(",
"obj",
")",
"{",
"if",
"(",
"obj",
"==",
"null",
")",
"return",
"false",
";",
"// true for numbers, strings, booleans and null, false for objects",
"if",
"(",
"obj",
"!=",
"Object",
"(",
"obj",
")",
")",
"return",
"true",
";",
"return",
"__isDate",
"(",
"obj",
")",
";",
"}"
] |
returns true for booleans, numbers, strings and dates false for null, and non-date objects, functions, and arrays
|
[
"returns",
"true",
"for",
"booleans",
"numbers",
"strings",
"and",
"dates",
"false",
"for",
"null",
"and",
"non",
"-",
"date",
"objects",
"functions",
"and",
"arrays"
] |
06b4919202bd20388847ce7d0cf57b6011cca158
|
https://github.com/Breeze/breeze.js/blob/06b4919202bd20388847ce7d0cf57b6011cca158/build/breeze.debug.js#L609-L614
|
16,187
|
Breeze/breeze.js
|
build/breeze.debug.js
|
__stringStartsWith
|
function __stringStartsWith(str, prefix) {
// returns true for empty string or null prefix
if ((!str)) return false;
if (prefix == "" || prefix == null) return true;
return str.indexOf(prefix, 0) === 0;
}
|
javascript
|
function __stringStartsWith(str, prefix) {
// returns true for empty string or null prefix
if ((!str)) return false;
if (prefix == "" || prefix == null) return true;
return str.indexOf(prefix, 0) === 0;
}
|
[
"function",
"__stringStartsWith",
"(",
"str",
",",
"prefix",
")",
"{",
"// returns true for empty string or null prefix",
"if",
"(",
"(",
"!",
"str",
")",
")",
"return",
"false",
";",
"if",
"(",
"prefix",
"==",
"\"\"",
"||",
"prefix",
"==",
"null",
")",
"return",
"true",
";",
"return",
"str",
".",
"indexOf",
"(",
"prefix",
",",
"0",
")",
"===",
"0",
";",
"}"
] |
end of is Functions string functions
|
[
"end",
"of",
"is",
"Functions",
"string",
"functions"
] |
06b4919202bd20388847ce7d0cf57b6011cca158
|
https://github.com/Breeze/breeze.js/blob/06b4919202bd20388847ce7d0cf57b6011cca158/build/breeze.debug.js#L620-L625
|
16,188
|
Breeze/breeze.js
|
build/breeze.debug.js
|
Enum
|
function Enum(name, methodObj) {
this.name = name;
var prototype = new EnumSymbol(methodObj);
prototype.parentEnum = this;
this._symbolPrototype = prototype;
if (methodObj) {
Object.keys(methodObj).forEach(function (key) {
prototype[key] = methodObj[key];
});
}
}
|
javascript
|
function Enum(name, methodObj) {
this.name = name;
var prototype = new EnumSymbol(methodObj);
prototype.parentEnum = this;
this._symbolPrototype = prototype;
if (methodObj) {
Object.keys(methodObj).forEach(function (key) {
prototype[key] = methodObj[key];
});
}
}
|
[
"function",
"Enum",
"(",
"name",
",",
"methodObj",
")",
"{",
"this",
".",
"name",
"=",
"name",
";",
"var",
"prototype",
"=",
"new",
"EnumSymbol",
"(",
"methodObj",
")",
";",
"prototype",
".",
"parentEnum",
"=",
"this",
";",
"this",
".",
"_symbolPrototype",
"=",
"prototype",
";",
"if",
"(",
"methodObj",
")",
"{",
"Object",
".",
"keys",
"(",
"methodObj",
")",
".",
"forEach",
"(",
"function",
"(",
"key",
")",
"{",
"prototype",
"[",
"key",
"]",
"=",
"methodObj",
"[",
"key",
"]",
";",
"}",
")",
";",
"}",
"}"
] |
Base class for all Breeze enumerations, such as EntityState, DataType, FetchStrategy, MergeStrategy etc.
A Breeze Enum is a namespaced set of constant values. Each Enum consists of a group of related constants, called 'symbols'.
Unlike enums in some other environments, each 'symbol' can have both methods and properties.
@example
Example of creating a new Enum
var prototype = {
nextDay: function () {
var nextIndex = (this.dayIndex+1) % 7;
return DayOfWeek.getSymbols()[nextIndex];
}
};
var DayOfWeek = new Enum("DayOfWeek", prototype);
DayOfWeek.Monday = DayOfWeek.addSymbol( { dayIndex: 0 });
DayOfWeek.Tuesday = DayOfWeek.addSymbol( { dayIndex: 1 });
DayOfWeek.Wednesday = DayOfWeek.addSymbol( { dayIndex: 2 });
DayOfWeek.Thursday = DayOfWeek.addSymbol( { dayIndex: 3 });
DayOfWeek.Friday = DayOfWeek.addSymbol( { dayIndex: 4 });
DayOfWeek.Saturday = DayOfWeek.addSymbol( { dayIndex: 5, isWeekend: true });
DayOfWeek.Sunday = DayOfWeek.addSymbol( { dayIndex: 6, isWeekend: true });
DayOfWeek.resolveSymbols();
custom methods
ok(DayOfWeek.Monday.nextDay() === DayOfWeek.Tuesday);
ok(DayOfWeek.Sunday.nextDay() === DayOfWeek.Monday);
custom properties
ok(DayOfWeek.Tuesday.isWeekend === undefined);
ok(DayOfWeek.Saturday.isWeekend == true);
Standard enum capabilities
ok(DayOfWeek instanceof Enum);
ok(Enum.isSymbol(DayOfWeek.Wednesday));
ok(DayOfWeek.contains(DayOfWeek.Thursday));
ok(DayOfWeek.Tuesday.parentEnum == DayOfWeek);
ok(DayOfWeek.getSymbols().length === 7);
ok(DayOfWeek.Friday.toString() === "Friday");
@class Enum
Enum constructor - may be used to create new Enums.
@example
var prototype = {
nextDay: function () {
var nextIndex = (this.dayIndex+1) % 7;
return DayOfWeek.getSymbols()[nextIndex];
}
};
var DayOfWeek = new Enum("DayOfWeek", prototype);
@method <ctor> Enum
@param name {String}
@param [methodObj] {Object}
|
[
"Base",
"class",
"for",
"all",
"Breeze",
"enumerations",
"such",
"as",
"EntityState",
"DataType",
"FetchStrategy",
"MergeStrategy",
"etc",
".",
"A",
"Breeze",
"Enum",
"is",
"a",
"namespaced",
"set",
"of",
"constant",
"values",
".",
"Each",
"Enum",
"consists",
"of",
"a",
"group",
"of",
"related",
"constants",
"called",
"symbols",
".",
"Unlike",
"enums",
"in",
"some",
"other",
"environments",
"each",
"symbol",
"can",
"have",
"both",
"methods",
"and",
"properties",
"."
] |
06b4919202bd20388847ce7d0cf57b6011cca158
|
https://github.com/Breeze/breeze.js/blob/06b4919202bd20388847ce7d0cf57b6011cca158/build/breeze.debug.js#L1148-L1158
|
16,189
|
Breeze/breeze.js
|
build/breeze.debug.js
|
EntityAspect
|
function EntityAspect(entity) {
if (entity === null) {
var nullInstance = EntityAspect._nullInstance;
if (nullInstance) return nullInstance;
EntityAspect._nullInstance = this;
} else if (entity === undefined) {
throw new Error("The EntityAspect ctor requires an entity as its only argument.");
} else if (entity.entityAspect) {
return entity.entityAspect;
}
// if called without new
if (!(this instanceof EntityAspect)) {
return new EntityAspect(entity);
}
this.entity = entity;
// TODO: keep public or not?
this.entityGroup = null;
this.entityManager = null;
this.entityState = EntityState.Detached;
this.isBeingSaved = false;
this.originalValues = {};
this.hasValidationErrors = false;
this._validationErrors = {};
// Uncomment when we implement entityAspect.isNavigationPropertyLoaded method
// this._loadedNavPropMap = {};
this.validationErrorsChanged = new Event("validationErrorsChanged", this);
this.propertyChanged = new Event("propertyChanged", this);
// in case this is the NULL entityAspect. - used with ComplexAspects that have no parent.
if (entity != null) {
entity.entityAspect = this;
// entityType should already be on the entity from 'watch'
var entityType = entity.entityType || entity._$entityType;
if (!entityType) {
var typeName = entity.prototype._$typeName;
if (!typeName) {
throw new Error("This entity is not registered as a valid EntityType");
} else {
throw new Error("Metadata for this entityType has not yet been resolved: " + typeName);
}
}
var entityCtor = entityType.getEntityCtor();
__modelLibraryDef.getDefaultInstance().startTracking(entity, entityCtor.prototype);
}
}
|
javascript
|
function EntityAspect(entity) {
if (entity === null) {
var nullInstance = EntityAspect._nullInstance;
if (nullInstance) return nullInstance;
EntityAspect._nullInstance = this;
} else if (entity === undefined) {
throw new Error("The EntityAspect ctor requires an entity as its only argument.");
} else if (entity.entityAspect) {
return entity.entityAspect;
}
// if called without new
if (!(this instanceof EntityAspect)) {
return new EntityAspect(entity);
}
this.entity = entity;
// TODO: keep public or not?
this.entityGroup = null;
this.entityManager = null;
this.entityState = EntityState.Detached;
this.isBeingSaved = false;
this.originalValues = {};
this.hasValidationErrors = false;
this._validationErrors = {};
// Uncomment when we implement entityAspect.isNavigationPropertyLoaded method
// this._loadedNavPropMap = {};
this.validationErrorsChanged = new Event("validationErrorsChanged", this);
this.propertyChanged = new Event("propertyChanged", this);
// in case this is the NULL entityAspect. - used with ComplexAspects that have no parent.
if (entity != null) {
entity.entityAspect = this;
// entityType should already be on the entity from 'watch'
var entityType = entity.entityType || entity._$entityType;
if (!entityType) {
var typeName = entity.prototype._$typeName;
if (!typeName) {
throw new Error("This entity is not registered as a valid EntityType");
} else {
throw new Error("Metadata for this entityType has not yet been resolved: " + typeName);
}
}
var entityCtor = entityType.getEntityCtor();
__modelLibraryDef.getDefaultInstance().startTracking(entity, entityCtor.prototype);
}
}
|
[
"function",
"EntityAspect",
"(",
"entity",
")",
"{",
"if",
"(",
"entity",
"===",
"null",
")",
"{",
"var",
"nullInstance",
"=",
"EntityAspect",
".",
"_nullInstance",
";",
"if",
"(",
"nullInstance",
")",
"return",
"nullInstance",
";",
"EntityAspect",
".",
"_nullInstance",
"=",
"this",
";",
"}",
"else",
"if",
"(",
"entity",
"===",
"undefined",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"The EntityAspect ctor requires an entity as its only argument.\"",
")",
";",
"}",
"else",
"if",
"(",
"entity",
".",
"entityAspect",
")",
"{",
"return",
"entity",
".",
"entityAspect",
";",
"}",
"// if called without new",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"EntityAspect",
")",
")",
"{",
"return",
"new",
"EntityAspect",
"(",
"entity",
")",
";",
"}",
"this",
".",
"entity",
"=",
"entity",
";",
"// TODO: keep public or not?",
"this",
".",
"entityGroup",
"=",
"null",
";",
"this",
".",
"entityManager",
"=",
"null",
";",
"this",
".",
"entityState",
"=",
"EntityState",
".",
"Detached",
";",
"this",
".",
"isBeingSaved",
"=",
"false",
";",
"this",
".",
"originalValues",
"=",
"{",
"}",
";",
"this",
".",
"hasValidationErrors",
"=",
"false",
";",
"this",
".",
"_validationErrors",
"=",
"{",
"}",
";",
"// Uncomment when we implement entityAspect.isNavigationPropertyLoaded method",
"// this._loadedNavPropMap = {};",
"this",
".",
"validationErrorsChanged",
"=",
"new",
"Event",
"(",
"\"validationErrorsChanged\"",
",",
"this",
")",
";",
"this",
".",
"propertyChanged",
"=",
"new",
"Event",
"(",
"\"propertyChanged\"",
",",
"this",
")",
";",
"// in case this is the NULL entityAspect. - used with ComplexAspects that have no parent.",
"if",
"(",
"entity",
"!=",
"null",
")",
"{",
"entity",
".",
"entityAspect",
"=",
"this",
";",
"// entityType should already be on the entity from 'watch'",
"var",
"entityType",
"=",
"entity",
".",
"entityType",
"||",
"entity",
".",
"_$entityType",
";",
"if",
"(",
"!",
"entityType",
")",
"{",
"var",
"typeName",
"=",
"entity",
".",
"prototype",
".",
"_$typeName",
";",
"if",
"(",
"!",
"typeName",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"This entity is not registered as a valid EntityType\"",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"Error",
"(",
"\"Metadata for this entityType has not yet been resolved: \"",
"+",
"typeName",
")",
";",
"}",
"}",
"var",
"entityCtor",
"=",
"entityType",
".",
"getEntityCtor",
"(",
")",
";",
"__modelLibraryDef",
".",
"getDefaultInstance",
"(",
")",
".",
"startTracking",
"(",
"entity",
",",
"entityCtor",
".",
"prototype",
")",
";",
"}",
"}"
] |
An EntityAspect instance is associated with every attached entity and is accessed via the entity's 'entityAspect' property.
The EntityAspect itself provides properties to determine and modify the EntityState of the entity and has methods
that provide a variety of services including validation and change tracking.
An EntityAspect will almost never need to be constructed directly. You will usually get an EntityAspect by accessing
an entities 'entityAspect' property. This property will be automatically attached when an entity is created via either
a query, import or EntityManager.createEntity call.
@example
assume order is an order entity attached to an EntityManager.
var aspect = order.entityAspect;
var currentState = aspect.entityState;
@class EntityAspect
|
[
"An",
"EntityAspect",
"instance",
"is",
"associated",
"with",
"every",
"attached",
"entity",
"and",
"is",
"accessed",
"via",
"the",
"entity",
"s",
"entityAspect",
"property",
"."
] |
06b4919202bd20388847ce7d0cf57b6011cca158
|
https://github.com/Breeze/breeze.js/blob/06b4919202bd20388847ce7d0cf57b6011cca158/build/breeze.debug.js#L3499-L3547
|
16,190
|
Breeze/breeze.js
|
build/breeze.debug.js
|
validateTarget
|
function validateTarget(target, coIndex) {
var ok = true;
var stype = target.entityType || target.complexType;
var aspect = target.entityAspect || target.complexAspect;
var entityAspect = target.entityAspect || target.complexAspect.getEntityAspect();
var context = { entity: entityAspect.entity };
if (coIndex !== undefined) {
context.index = coIndex;
}
stype.getProperties().forEach(function (p) {
var value = target.getProperty(p.name);
var validators = p.getAllValidators();
if (validators.length > 0) {
context.property = p;
context.propertyName = aspect.getPropertyPath(p.name);
ok = entityAspect._validateProperty(value, context) && ok;
}
if (p.isComplexProperty) {
if (p.isScalar) {
ok = validateTarget(value) && ok;
} else {
ok = value.reduce(function (pv, cv, ix) {
return validateTarget(cv, ix) && pv;
}, ok);
}
}
});
// then target level
stype.getAllValidators().forEach(function (validator) {
ok = validate(entityAspect, validator, target) && ok;
});
return ok;
}
|
javascript
|
function validateTarget(target, coIndex) {
var ok = true;
var stype = target.entityType || target.complexType;
var aspect = target.entityAspect || target.complexAspect;
var entityAspect = target.entityAspect || target.complexAspect.getEntityAspect();
var context = { entity: entityAspect.entity };
if (coIndex !== undefined) {
context.index = coIndex;
}
stype.getProperties().forEach(function (p) {
var value = target.getProperty(p.name);
var validators = p.getAllValidators();
if (validators.length > 0) {
context.property = p;
context.propertyName = aspect.getPropertyPath(p.name);
ok = entityAspect._validateProperty(value, context) && ok;
}
if (p.isComplexProperty) {
if (p.isScalar) {
ok = validateTarget(value) && ok;
} else {
ok = value.reduce(function (pv, cv, ix) {
return validateTarget(cv, ix) && pv;
}, ok);
}
}
});
// then target level
stype.getAllValidators().forEach(function (validator) {
ok = validate(entityAspect, validator, target) && ok;
});
return ok;
}
|
[
"function",
"validateTarget",
"(",
"target",
",",
"coIndex",
")",
"{",
"var",
"ok",
"=",
"true",
";",
"var",
"stype",
"=",
"target",
".",
"entityType",
"||",
"target",
".",
"complexType",
";",
"var",
"aspect",
"=",
"target",
".",
"entityAspect",
"||",
"target",
".",
"complexAspect",
";",
"var",
"entityAspect",
"=",
"target",
".",
"entityAspect",
"||",
"target",
".",
"complexAspect",
".",
"getEntityAspect",
"(",
")",
";",
"var",
"context",
"=",
"{",
"entity",
":",
"entityAspect",
".",
"entity",
"}",
";",
"if",
"(",
"coIndex",
"!==",
"undefined",
")",
"{",
"context",
".",
"index",
"=",
"coIndex",
";",
"}",
"stype",
".",
"getProperties",
"(",
")",
".",
"forEach",
"(",
"function",
"(",
"p",
")",
"{",
"var",
"value",
"=",
"target",
".",
"getProperty",
"(",
"p",
".",
"name",
")",
";",
"var",
"validators",
"=",
"p",
".",
"getAllValidators",
"(",
")",
";",
"if",
"(",
"validators",
".",
"length",
">",
"0",
")",
"{",
"context",
".",
"property",
"=",
"p",
";",
"context",
".",
"propertyName",
"=",
"aspect",
".",
"getPropertyPath",
"(",
"p",
".",
"name",
")",
";",
"ok",
"=",
"entityAspect",
".",
"_validateProperty",
"(",
"value",
",",
"context",
")",
"&&",
"ok",
";",
"}",
"if",
"(",
"p",
".",
"isComplexProperty",
")",
"{",
"if",
"(",
"p",
".",
"isScalar",
")",
"{",
"ok",
"=",
"validateTarget",
"(",
"value",
")",
"&&",
"ok",
";",
"}",
"else",
"{",
"ok",
"=",
"value",
".",
"reduce",
"(",
"function",
"(",
"pv",
",",
"cv",
",",
"ix",
")",
"{",
"return",
"validateTarget",
"(",
"cv",
",",
"ix",
")",
"&&",
"pv",
";",
"}",
",",
"ok",
")",
";",
"}",
"}",
"}",
")",
";",
"// then target level",
"stype",
".",
"getAllValidators",
"(",
")",
".",
"forEach",
"(",
"function",
"(",
"validator",
")",
"{",
"ok",
"=",
"validate",
"(",
"entityAspect",
",",
"validator",
",",
"target",
")",
"&&",
"ok",
";",
"}",
")",
";",
"return",
"ok",
";",
"}"
] |
coIndex is only used where target is a complex object that is part of an array of complex objects in which case ctIndex is the index of the target within the array.
|
[
"coIndex",
"is",
"only",
"used",
"where",
"target",
"is",
"a",
"complex",
"object",
"that",
"is",
"part",
"of",
"an",
"array",
"of",
"complex",
"objects",
"in",
"which",
"case",
"ctIndex",
"is",
"the",
"index",
"of",
"the",
"target",
"within",
"the",
"array",
"."
] |
06b4919202bd20388847ce7d0cf57b6011cca158
|
https://github.com/Breeze/breeze.js/blob/06b4919202bd20388847ce7d0cf57b6011cca158/build/breeze.debug.js#L3993-L4028
|
16,191
|
Breeze/breeze.js
|
build/breeze.debug.js
|
ComplexAspect
|
function ComplexAspect(complexObject, parent, parentProperty) {
if (!complexObject) {
throw new Error("The ComplexAspect ctor requires an entity as its only argument.");
}
if (complexObject.complexAspect) {
return complexObject.complexAspect;
}
// if called without new
if (!(this instanceof ComplexAspect)) {
return new ComplexAspect(complexObject, parent, parentProperty);
}
// entityType should already be on the entity from 'watch'
this.complexObject = complexObject;
complexObject.complexAspect = this;
// TODO: keep public or not?
this.originalValues = {};
// if a standalone complexObject
if (parent != null) {
this.parent = parent;
this.parentProperty = parentProperty;
}
var complexType = complexObject.complexType;
if (!complexType) {
var typeName = complexObject.prototype._$typeName;
if (!typeName) {
throw new Error("This entity is not registered as a valid ComplexType");
} else {
throw new Error("Metadata for this complexType has not yet been resolved: " + typeName);
}
}
var complexCtor = complexType.getCtor();
__modelLibraryDef.getDefaultInstance().startTracking(complexObject, complexCtor.prototype);
}
|
javascript
|
function ComplexAspect(complexObject, parent, parentProperty) {
if (!complexObject) {
throw new Error("The ComplexAspect ctor requires an entity as its only argument.");
}
if (complexObject.complexAspect) {
return complexObject.complexAspect;
}
// if called without new
if (!(this instanceof ComplexAspect)) {
return new ComplexAspect(complexObject, parent, parentProperty);
}
// entityType should already be on the entity from 'watch'
this.complexObject = complexObject;
complexObject.complexAspect = this;
// TODO: keep public or not?
this.originalValues = {};
// if a standalone complexObject
if (parent != null) {
this.parent = parent;
this.parentProperty = parentProperty;
}
var complexType = complexObject.complexType;
if (!complexType) {
var typeName = complexObject.prototype._$typeName;
if (!typeName) {
throw new Error("This entity is not registered as a valid ComplexType");
} else {
throw new Error("Metadata for this complexType has not yet been resolved: " + typeName);
}
}
var complexCtor = complexType.getCtor();
__modelLibraryDef.getDefaultInstance().startTracking(complexObject, complexCtor.prototype);
}
|
[
"function",
"ComplexAspect",
"(",
"complexObject",
",",
"parent",
",",
"parentProperty",
")",
"{",
"if",
"(",
"!",
"complexObject",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"The ComplexAspect ctor requires an entity as its only argument.\"",
")",
";",
"}",
"if",
"(",
"complexObject",
".",
"complexAspect",
")",
"{",
"return",
"complexObject",
".",
"complexAspect",
";",
"}",
"// if called without new",
"if",
"(",
"!",
"(",
"this",
"instanceof",
"ComplexAspect",
")",
")",
"{",
"return",
"new",
"ComplexAspect",
"(",
"complexObject",
",",
"parent",
",",
"parentProperty",
")",
";",
"}",
"// entityType should already be on the entity from 'watch'",
"this",
".",
"complexObject",
"=",
"complexObject",
";",
"complexObject",
".",
"complexAspect",
"=",
"this",
";",
"// TODO: keep public or not?",
"this",
".",
"originalValues",
"=",
"{",
"}",
";",
"// if a standalone complexObject",
"if",
"(",
"parent",
"!=",
"null",
")",
"{",
"this",
".",
"parent",
"=",
"parent",
";",
"this",
".",
"parentProperty",
"=",
"parentProperty",
";",
"}",
"var",
"complexType",
"=",
"complexObject",
".",
"complexType",
";",
"if",
"(",
"!",
"complexType",
")",
"{",
"var",
"typeName",
"=",
"complexObject",
".",
"prototype",
".",
"_$typeName",
";",
"if",
"(",
"!",
"typeName",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"This entity is not registered as a valid ComplexType\"",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"Error",
"(",
"\"Metadata for this complexType has not yet been resolved: \"",
"+",
"typeName",
")",
";",
"}",
"}",
"var",
"complexCtor",
"=",
"complexType",
".",
"getCtor",
"(",
")",
";",
"__modelLibraryDef",
".",
"getDefaultInstance",
"(",
")",
".",
"startTracking",
"(",
"complexObject",
",",
"complexCtor",
".",
"prototype",
")",
";",
"}"
] |
An ComplexAspect instance is associated with every complex object instance and is accessed via the complex object's 'complexAspect' property.
The ComplexAspect itself provides properties to determine the parent object, parent property and original values for the complex object.
A ComplexAspect will almost never need to be constructed directly. You will usually get an ComplexAspect by accessing
an entities 'complexAspect' property. This property will be automatically attached when an complex object is created as part of an
entity via either a query, import or EntityManager.createEntity call.
@example
assume address is a complex property on the 'Customer' type
var aspect = aCustomer.address.complexAspect;
aCustomer === aspect.parent;
@class ComplexAspect
|
[
"An",
"ComplexAspect",
"instance",
"is",
"associated",
"with",
"every",
"complex",
"object",
"instance",
"and",
"is",
"accessed",
"via",
"the",
"complex",
"object",
"s",
"complexAspect",
"property",
"."
] |
06b4919202bd20388847ce7d0cf57b6011cca158
|
https://github.com/Breeze/breeze.js/blob/06b4919202bd20388847ce7d0cf57b6011cca158/build/breeze.debug.js#L4332-L4369
|
16,192
|
Breeze/breeze.js
|
build/breeze.debug.js
|
EntityKey
|
function EntityKey(entityType, keyValues) {
assertParam(entityType, "entityType").isInstanceOf(EntityType).check();
var subtypes = entityType.getSelfAndSubtypes();
if (subtypes.length > 1) {
this._subtypes = subtypes.filter(function (st) {
return st.isAbstract === false;
});
}
if (!Array.isArray(keyValues)) {
keyValues = __arraySlice(arguments, 1);
}
this.entityType = entityType;
entityType.keyProperties.forEach(function (kp, i) {
// insure that guid keys are comparable.
if (kp.dataType === DataType.Guid) {
keyValues[i] = keyValues[i] && keyValues[i].toLowerCase();
}
});
this.values = keyValues;
this._keyInGroup = createKeyString(keyValues);
}
|
javascript
|
function EntityKey(entityType, keyValues) {
assertParam(entityType, "entityType").isInstanceOf(EntityType).check();
var subtypes = entityType.getSelfAndSubtypes();
if (subtypes.length > 1) {
this._subtypes = subtypes.filter(function (st) {
return st.isAbstract === false;
});
}
if (!Array.isArray(keyValues)) {
keyValues = __arraySlice(arguments, 1);
}
this.entityType = entityType;
entityType.keyProperties.forEach(function (kp, i) {
// insure that guid keys are comparable.
if (kp.dataType === DataType.Guid) {
keyValues[i] = keyValues[i] && keyValues[i].toLowerCase();
}
});
this.values = keyValues;
this._keyInGroup = createKeyString(keyValues);
}
|
[
"function",
"EntityKey",
"(",
"entityType",
",",
"keyValues",
")",
"{",
"assertParam",
"(",
"entityType",
",",
"\"entityType\"",
")",
".",
"isInstanceOf",
"(",
"EntityType",
")",
".",
"check",
"(",
")",
";",
"var",
"subtypes",
"=",
"entityType",
".",
"getSelfAndSubtypes",
"(",
")",
";",
"if",
"(",
"subtypes",
".",
"length",
">",
"1",
")",
"{",
"this",
".",
"_subtypes",
"=",
"subtypes",
".",
"filter",
"(",
"function",
"(",
"st",
")",
"{",
"return",
"st",
".",
"isAbstract",
"===",
"false",
";",
"}",
")",
";",
"}",
"if",
"(",
"!",
"Array",
".",
"isArray",
"(",
"keyValues",
")",
")",
"{",
"keyValues",
"=",
"__arraySlice",
"(",
"arguments",
",",
"1",
")",
";",
"}",
"this",
".",
"entityType",
"=",
"entityType",
";",
"entityType",
".",
"keyProperties",
".",
"forEach",
"(",
"function",
"(",
"kp",
",",
"i",
")",
"{",
"// insure that guid keys are comparable.",
"if",
"(",
"kp",
".",
"dataType",
"===",
"DataType",
".",
"Guid",
")",
"{",
"keyValues",
"[",
"i",
"]",
"=",
"keyValues",
"[",
"i",
"]",
"&&",
"keyValues",
"[",
"i",
"]",
".",
"toLowerCase",
"(",
")",
";",
"}",
"}",
")",
";",
"this",
".",
"values",
"=",
"keyValues",
";",
"this",
".",
"_keyInGroup",
"=",
"createKeyString",
"(",
"keyValues",
")",
";",
"}"
] |
An EntityKey is an object that represents the unique identity of an entity. EntityKey's are immutable.
@class EntityKey
Constructs a new EntityKey. Each entity within an EntityManager will have a unique EntityKey.
@example
assume em1 is an EntityManager containing a number of existing entities.
var empType = em1.metadataStore.getEntityType("Employee");
var entityKey = new EntityKey(empType, 1);
EntityKey's may also be found by calling EntityAspect.getKey()
@example
assume employee1 is an existing Employee entity
var empKey = employee1.entityAspect.getKey();
Multipart keys are created by passing an array as the 'keyValues' parameter
@example
var empTerrType = em1.metadataStore.getEntityType("EmployeeTerritory");
var empTerrKey = new EntityKey(empTerrType, [ 1, 77]);
The order of the properties in the 'keyValues' array must be the same as that
returned by empTerrType.keyProperties
@method <ctor> EntityKey
@param entityType {EntityType} The {{#crossLink "EntityType"}}{{/crossLink}} of the entity.
@param keyValues {value|Array of values} A single value or an array of values.
|
[
"An",
"EntityKey",
"is",
"an",
"object",
"that",
"represents",
"the",
"unique",
"identity",
"of",
"an",
"entity",
".",
"EntityKey",
"s",
"are",
"immutable",
"."
] |
06b4919202bd20388847ce7d0cf57b6011cca158
|
https://github.com/Breeze/breeze.js/blob/06b4919202bd20388847ce7d0cf57b6011cca158/build/breeze.debug.js#L4474-L4498
|
16,193
|
Breeze/breeze.js
|
build/breeze.debug.js
|
JsonResultsAdapter
|
function JsonResultsAdapter(config) {
if (arguments.length !== 1) {
throw new Error("The JsonResultsAdapter ctor should be called with a single argument that is a configuration object.");
}
assertConfig(config)
.whereParam("name").isNonEmptyString()
.whereParam("extractResults").isFunction().isOptional().withDefault(extractResultsDefault)
.whereParam("extractSaveResults").isFunction().isOptional().withDefault(extractSaveResultsDefault)
.whereParam("extractKeyMappings").isFunction().isOptional().withDefault(extractKeyMappingsDefault)
.whereParam("extractDeletedKeys").isFunction().isOptional().withDefault(extractDeletedKeysDefault)
.whereParam("visitNode").isFunction()
.applyAll(this);
__config._storeObject(this, proto._$typeName, this.name);
}
|
javascript
|
function JsonResultsAdapter(config) {
if (arguments.length !== 1) {
throw new Error("The JsonResultsAdapter ctor should be called with a single argument that is a configuration object.");
}
assertConfig(config)
.whereParam("name").isNonEmptyString()
.whereParam("extractResults").isFunction().isOptional().withDefault(extractResultsDefault)
.whereParam("extractSaveResults").isFunction().isOptional().withDefault(extractSaveResultsDefault)
.whereParam("extractKeyMappings").isFunction().isOptional().withDefault(extractKeyMappingsDefault)
.whereParam("extractDeletedKeys").isFunction().isOptional().withDefault(extractDeletedKeysDefault)
.whereParam("visitNode").isFunction()
.applyAll(this);
__config._storeObject(this, proto._$typeName, this.name);
}
|
[
"function",
"JsonResultsAdapter",
"(",
"config",
")",
"{",
"if",
"(",
"arguments",
".",
"length",
"!==",
"1",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"The JsonResultsAdapter ctor should be called with a single argument that is a configuration object.\"",
")",
";",
"}",
"assertConfig",
"(",
"config",
")",
".",
"whereParam",
"(",
"\"name\"",
")",
".",
"isNonEmptyString",
"(",
")",
".",
"whereParam",
"(",
"\"extractResults\"",
")",
".",
"isFunction",
"(",
")",
".",
"isOptional",
"(",
")",
".",
"withDefault",
"(",
"extractResultsDefault",
")",
".",
"whereParam",
"(",
"\"extractSaveResults\"",
")",
".",
"isFunction",
"(",
")",
".",
"isOptional",
"(",
")",
".",
"withDefault",
"(",
"extractSaveResultsDefault",
")",
".",
"whereParam",
"(",
"\"extractKeyMappings\"",
")",
".",
"isFunction",
"(",
")",
".",
"isOptional",
"(",
")",
".",
"withDefault",
"(",
"extractKeyMappingsDefault",
")",
".",
"whereParam",
"(",
"\"extractDeletedKeys\"",
")",
".",
"isFunction",
"(",
")",
".",
"isOptional",
"(",
")",
".",
"withDefault",
"(",
"extractDeletedKeysDefault",
")",
".",
"whereParam",
"(",
"\"visitNode\"",
")",
".",
"isFunction",
"(",
")",
".",
"applyAll",
"(",
"this",
")",
";",
"__config",
".",
"_storeObject",
"(",
"this",
",",
"proto",
".",
"_$typeName",
",",
"this",
".",
"name",
")",
";",
"}"
] |
A JsonResultsAdapter instance is used to provide custom extraction and parsing logic on the json results returned by any web service.
This facility makes it possible for breeze to talk to virtually any web service and return objects that will be first class 'breeze' citizens.
@class JsonResultsAdapter
JsonResultsAdapter constructor
@example
var jsonResultsAdapter = new JsonResultsAdapter({
name: "test1e",
extractResults: function(json) {
return json.results;
},
visitNode: function(node, mappingContext, nodeContext) {
var entityType = normalizeTypeName(node.$type);
var propertyName = nodeContext.propertyName;
var ignore = propertyName && propertyName.substr(0, 1) === "$";
return {
entityType: entityType,
nodeId: node.$id,
nodeRefId: node.$ref,
ignore: ignore,
passThru: false // default
};
}
});
var dataService = new DataService( {
serviceName: "breeze/foo",
jsonResultsAdapter: jsonResultsAdapter
});
var entityManager = new EntityManager( {
dataService: dataService
});
@method <ctor> JsonResultsAdapter
@param config {Object}
@param config.name {String} The name of this adapter. This name is used to uniquely identify and locate this instance when an 'exported' JsonResultsAdapter is later imported.
@param [config.extractResults] {Function} Called once per query operation to extract the 'payload' from any json received over the wire.
This method has a default implementation which to simply return the "results" property from any json returned as a result of executing the query.
@param [config.extractSaveResults] {Function} Called once per save operation to extract the entities from any json received over the wire. Must return an array.
This method has a default implementation which to simply return the "entities" property from any json returned as a result of executing the save.
@param [config.extractKeyMappings] {Function} Called once per save operation to extract the key mappings from any json received over the wire. Must return an array.
This method has a default implementation which to simply return the "keyMappings" property from any json returned as a result of executing the save.
@param config.visitNode {Function} A visitor method that will be called on each node of the returned payload.
|
[
"A",
"JsonResultsAdapter",
"instance",
"is",
"used",
"to",
"provide",
"custom",
"extraction",
"and",
"parsing",
"logic",
"on",
"the",
"json",
"results",
"returned",
"by",
"any",
"web",
"service",
".",
"This",
"facility",
"makes",
"it",
"possible",
"for",
"breeze",
"to",
"talk",
"to",
"virtually",
"any",
"web",
"service",
"and",
"return",
"objects",
"that",
"will",
"be",
"first",
"class",
"breeze",
"citizens",
"."
] |
06b4919202bd20388847ce7d0cf57b6011cca158
|
https://github.com/Breeze/breeze.js/blob/06b4919202bd20388847ce7d0cf57b6011cca158/build/breeze.debug.js#L6332-L6346
|
16,194
|
Breeze/breeze.js
|
build/breeze.debug.js
|
LocalQueryComparisonOptions
|
function LocalQueryComparisonOptions(config) {
assertConfig(config || {})
.whereParam("name").isOptional().isString()
.whereParam("isCaseSensitive").isOptional().isBoolean()
.whereParam("usesSql92CompliantStringComparison").isBoolean()
.applyAll(this);
if (!this.name) {
this.name = __getUuid();
}
__config._storeObject(this, proto._$typeName, this.name);
}
|
javascript
|
function LocalQueryComparisonOptions(config) {
assertConfig(config || {})
.whereParam("name").isOptional().isString()
.whereParam("isCaseSensitive").isOptional().isBoolean()
.whereParam("usesSql92CompliantStringComparison").isBoolean()
.applyAll(this);
if (!this.name) {
this.name = __getUuid();
}
__config._storeObject(this, proto._$typeName, this.name);
}
|
[
"function",
"LocalQueryComparisonOptions",
"(",
"config",
")",
"{",
"assertConfig",
"(",
"config",
"||",
"{",
"}",
")",
".",
"whereParam",
"(",
"\"name\"",
")",
".",
"isOptional",
"(",
")",
".",
"isString",
"(",
")",
".",
"whereParam",
"(",
"\"isCaseSensitive\"",
")",
".",
"isOptional",
"(",
")",
".",
"isBoolean",
"(",
")",
".",
"whereParam",
"(",
"\"usesSql92CompliantStringComparison\"",
")",
".",
"isBoolean",
"(",
")",
".",
"applyAll",
"(",
"this",
")",
";",
"if",
"(",
"!",
"this",
".",
"name",
")",
"{",
"this",
".",
"name",
"=",
"__getUuid",
"(",
")",
";",
"}",
"__config",
".",
"_storeObject",
"(",
"this",
",",
"proto",
".",
"_$typeName",
",",
"this",
".",
"name",
")",
";",
"}"
] |
A LocalQueryComparisonOptions instance is used to specify the "comparison rules" used when performing "local queries" in order
to match the semantics of these same queries when executed against a remote service. These options should be set based on the
manner in which your remote service interprets certain comparison operations.
The default LocalQueryComparisonOptions stipulates 'caseInsensitive" queries with ANSI SQL rules regarding comparisons of unequal
length strings.
@class LocalQueryComparisonOptions
LocalQueryComparisonOptions constructor
@example
create a 'caseSensitive - non SQL' instance.
var lqco = new LocalQueryComparisonOptions({
name: "caseSensitive-nonSQL"
isCaseSensitive: true;
usesSql92CompliantStringComparison: false;
});
either apply it globally
lqco.setAsDefault();
or to a specific MetadataStore
var ms = new MetadataStore({ localQueryComparisonOptions: lqco });
var em = new EntityManager( { metadataStore: ms });
@method <ctor> LocalQueryComparisonOptions
@param config {Object}
@param [config.name] {String}
@param [config.isCaseSensitive] {Boolean} Whether predicates that involve strings will be interpreted in a "caseSensitive" manner. Default is 'false'
@param [config.usesSql92CompliantStringComparison] {Boolean} Whether of not to enforce the ANSI SQL standard
of padding strings of unequal lengths before comparison with spaces. Note that per the standard, padding only occurs with equality and
inequality predicates, and not with operations like 'startsWith', 'endsWith' or 'contains'. Default is true.
|
[
"A",
"LocalQueryComparisonOptions",
"instance",
"is",
"used",
"to",
"specify",
"the",
"comparison",
"rules",
"used",
"when",
"performing",
"local",
"queries",
"in",
"order",
"to",
"match",
"the",
"semantics",
"of",
"these",
"same",
"queries",
"when",
"executed",
"against",
"a",
"remote",
"service",
".",
"These",
"options",
"should",
"be",
"set",
"based",
"on",
"the",
"manner",
"in",
"which",
"your",
"remote",
"service",
"interprets",
"certain",
"comparison",
"operations",
"."
] |
06b4919202bd20388847ce7d0cf57b6011cca158
|
https://github.com/Breeze/breeze.js/blob/06b4919202bd20388847ce7d0cf57b6011cca158/build/breeze.debug.js#L9767-L9777
|
16,195
|
Breeze/breeze.js
|
build/breeze.debug.js
|
NamingConvention
|
function NamingConvention(config) {
assertConfig(config || {})
.whereParam("name").isOptional().isString()
.whereParam("serverPropertyNameToClient").isFunction()
.whereParam("clientPropertyNameToServer").isFunction()
.applyAll(this);
if (!this.name) {
this.name = __getUuid();
}
__config._storeObject(this, proto._$typeName, this.name);
}
|
javascript
|
function NamingConvention(config) {
assertConfig(config || {})
.whereParam("name").isOptional().isString()
.whereParam("serverPropertyNameToClient").isFunction()
.whereParam("clientPropertyNameToServer").isFunction()
.applyAll(this);
if (!this.name) {
this.name = __getUuid();
}
__config._storeObject(this, proto._$typeName, this.name);
}
|
[
"function",
"NamingConvention",
"(",
"config",
")",
"{",
"assertConfig",
"(",
"config",
"||",
"{",
"}",
")",
".",
"whereParam",
"(",
"\"name\"",
")",
".",
"isOptional",
"(",
")",
".",
"isString",
"(",
")",
".",
"whereParam",
"(",
"\"serverPropertyNameToClient\"",
")",
".",
"isFunction",
"(",
")",
".",
"whereParam",
"(",
"\"clientPropertyNameToServer\"",
")",
".",
"isFunction",
"(",
")",
".",
"applyAll",
"(",
"this",
")",
";",
"if",
"(",
"!",
"this",
".",
"name",
")",
"{",
"this",
".",
"name",
"=",
"__getUuid",
"(",
")",
";",
"}",
"__config",
".",
"_storeObject",
"(",
"this",
",",
"proto",
".",
"_$typeName",
",",
"this",
".",
"name",
")",
";",
"}"
] |
A NamingConvention instance is used to specify the naming conventions under which a MetadataStore
will translate property names between the server and the javascript client.
The default NamingConvention does not perform any translation, it simply passes property names thru unchanged.
@class NamingConvention
NamingConvention constructor
@example
A naming convention that converts the first character of every property name to uppercase on the server
and lowercase on the client.
var namingConv = new NamingConvention({
serverPropertyNameToClient: function(serverPropertyName) {
return serverPropertyName.substr(0, 1).toLowerCase() + serverPropertyName.substr(1);
},
clientPropertyNameToServer: function(clientPropertyName) {
return clientPropertyName.substr(0, 1).toUpperCase() + clientPropertyName.substr(1);
}
});
var ms = new MetadataStore({ namingConvention: namingConv });
var em = new EntityManager( { metadataStore: ms });
@method <ctor> NamingConvention
@param config {Object}
@param config.serverPropertyNameToClient {Function} Function that takes a server property name add converts it into a client side property name.
@param config.clientPropertyNameToServer {Function} Function that takes a client property name add converts it into a server side property name.
|
[
"A",
"NamingConvention",
"instance",
"is",
"used",
"to",
"specify",
"the",
"naming",
"conventions",
"under",
"which",
"a",
"MetadataStore",
"will",
"translate",
"property",
"names",
"between",
"the",
"server",
"and",
"the",
"javascript",
"client",
"."
] |
06b4919202bd20388847ce7d0cf57b6011cca158
|
https://github.com/Breeze/breeze.js/blob/06b4919202bd20388847ce7d0cf57b6011cca158/build/breeze.debug.js#L9858-L9868
|
16,196
|
Breeze/breeze.js
|
build/breeze.debug.js
|
function () {
// empty ctor is used by all subclasses.
if (arguments.length === 0) return;
if (arguments.length === 1) {
// 3 possibilities:
// Predicate(aPredicate)
// Predicate([ aPredicate ])
// Predicate(["freight", ">", 100"])
// Predicate( "freight gt 100" } // passthru ( i.e. maybe an odata string)
// Predicate( { freight: { ">": 100 } })
var arg = arguments[0];
if (Array.isArray(arg)) {
if (arg.length === 1) {
// recurse
return Predicate(arg[0]);
} else {
return createPredicateFromArray(arg);
}
} else if (arg instanceof Predicate) {
return arg;
} else if (typeof arg == 'string') {
return new PassthruPredicate(arg);
} else {
return createPredicateFromObject(arg);
}
} else {
// 2 possibilities
// Predicate("freight", ">", 100");
// Predicate("orders", "any", "freight", ">", 950);
return createPredicateFromArray(Array.prototype.slice.call(arguments, 0));
}
}
|
javascript
|
function () {
// empty ctor is used by all subclasses.
if (arguments.length === 0) return;
if (arguments.length === 1) {
// 3 possibilities:
// Predicate(aPredicate)
// Predicate([ aPredicate ])
// Predicate(["freight", ">", 100"])
// Predicate( "freight gt 100" } // passthru ( i.e. maybe an odata string)
// Predicate( { freight: { ">": 100 } })
var arg = arguments[0];
if (Array.isArray(arg)) {
if (arg.length === 1) {
// recurse
return Predicate(arg[0]);
} else {
return createPredicateFromArray(arg);
}
} else if (arg instanceof Predicate) {
return arg;
} else if (typeof arg == 'string') {
return new PassthruPredicate(arg);
} else {
return createPredicateFromObject(arg);
}
} else {
// 2 possibilities
// Predicate("freight", ">", 100");
// Predicate("orders", "any", "freight", ">", 950);
return createPredicateFromArray(Array.prototype.slice.call(arguments, 0));
}
}
|
[
"function",
"(",
")",
"{",
"// empty ctor is used by all subclasses.",
"if",
"(",
"arguments",
".",
"length",
"===",
"0",
")",
"return",
";",
"if",
"(",
"arguments",
".",
"length",
"===",
"1",
")",
"{",
"// 3 possibilities:",
"// Predicate(aPredicate)",
"// Predicate([ aPredicate ])",
"// Predicate([\"freight\", \">\", 100\"])",
"// Predicate( \"freight gt 100\" } // passthru ( i.e. maybe an odata string)",
"// Predicate( { freight: { \">\": 100 } })",
"var",
"arg",
"=",
"arguments",
"[",
"0",
"]",
";",
"if",
"(",
"Array",
".",
"isArray",
"(",
"arg",
")",
")",
"{",
"if",
"(",
"arg",
".",
"length",
"===",
"1",
")",
"{",
"// recurse",
"return",
"Predicate",
"(",
"arg",
"[",
"0",
"]",
")",
";",
"}",
"else",
"{",
"return",
"createPredicateFromArray",
"(",
"arg",
")",
";",
"}",
"}",
"else",
"if",
"(",
"arg",
"instanceof",
"Predicate",
")",
"{",
"return",
"arg",
";",
"}",
"else",
"if",
"(",
"typeof",
"arg",
"==",
"'string'",
")",
"{",
"return",
"new",
"PassthruPredicate",
"(",
"arg",
")",
";",
"}",
"else",
"{",
"return",
"createPredicateFromObject",
"(",
"arg",
")",
";",
"}",
"}",
"else",
"{",
"// 2 possibilities",
"// Predicate(\"freight\", \">\", 100\");",
"// Predicate(\"orders\", \"any\", \"freight\", \">\", 950);",
"return",
"createPredicateFromArray",
"(",
"Array",
".",
"prototype",
".",
"slice",
".",
"call",
"(",
"arguments",
",",
"0",
")",
")",
";",
"}",
"}"
] |
Used to define a 'where' predicate for an EntityQuery. Predicates are immutable, which means that any
method that would modify a Predicate actually returns a new Predicate.
@class Predicate
Predicate constructor
@example
var p1 = new Predicate("CompanyName", "StartsWith", "B");
var query = new EntityQuery("Customers").where(p1);
or
@example
var p2 = new Predicate("Region", FilterQueryOp.Equals, null);
var query = new EntityQuery("Customers").where(p2);
@method <ctor> Predicate
@param property {String} A property name, a nested property name or an expression involving a property name.
@param operator {FilterQueryOp|String}
@param value {Object} - This will be treated as either a property expression or a literal depending on context. In general,
if the value can be interpreted as a property expression it will be, otherwise it will be treated as a literal.
In most cases this works well, but you can also force the interpretation by making the value argument itself an object with a 'value'
property and an 'isLiteral' property set to either true or false. Breeze also tries to infer the dataType of any
literal based on context, if this fails you can force this inference by making the value argument an object with a
'value' property and a 'dataType' property set to one of the breeze.DataType enumeration instances.
|
[
"Used",
"to",
"define",
"a",
"where",
"predicate",
"for",
"an",
"EntityQuery",
".",
"Predicates",
"are",
"immutable",
"which",
"means",
"that",
"any",
"method",
"that",
"would",
"modify",
"a",
"Predicate",
"actually",
"returns",
"a",
"new",
"Predicate",
"."
] |
06b4919202bd20388847ce7d0cf57b6011cca158
|
https://github.com/Breeze/breeze.js/blob/06b4919202bd20388847ce7d0cf57b6011cca158/build/breeze.debug.js#L9983-L10014
|
|
16,197
|
Breeze/breeze.js
|
build/breeze.debug.js
|
getPropertyPathValue
|
function getPropertyPathValue(obj, propertyPath) {
var properties = Array.isArray(propertyPath) ? propertyPath : propertyPath.split(".");
if (properties.length === 1) {
return obj.getProperty(propertyPath);
} else {
var nextValue = obj;
// hack use of some to perform mapFirst operation.
properties.some(function (prop) {
nextValue = nextValue.getProperty(prop);
return nextValue == null;
});
return nextValue;
}
}
|
javascript
|
function getPropertyPathValue(obj, propertyPath) {
var properties = Array.isArray(propertyPath) ? propertyPath : propertyPath.split(".");
if (properties.length === 1) {
return obj.getProperty(propertyPath);
} else {
var nextValue = obj;
// hack use of some to perform mapFirst operation.
properties.some(function (prop) {
nextValue = nextValue.getProperty(prop);
return nextValue == null;
});
return nextValue;
}
}
|
[
"function",
"getPropertyPathValue",
"(",
"obj",
",",
"propertyPath",
")",
"{",
"var",
"properties",
"=",
"Array",
".",
"isArray",
"(",
"propertyPath",
")",
"?",
"propertyPath",
":",
"propertyPath",
".",
"split",
"(",
"\".\"",
")",
";",
"if",
"(",
"properties",
".",
"length",
"===",
"1",
")",
"{",
"return",
"obj",
".",
"getProperty",
"(",
"propertyPath",
")",
";",
"}",
"else",
"{",
"var",
"nextValue",
"=",
"obj",
";",
"// hack use of some to perform mapFirst operation.",
"properties",
".",
"some",
"(",
"function",
"(",
"prop",
")",
"{",
"nextValue",
"=",
"nextValue",
".",
"getProperty",
"(",
"prop",
")",
";",
"return",
"nextValue",
"==",
"null",
";",
"}",
")",
";",
"return",
"nextValue",
";",
"}",
"}"
] |
used by EntityQuery and Predicate
|
[
"used",
"by",
"EntityQuery",
"and",
"Predicate"
] |
06b4919202bd20388847ce7d0cf57b6011cca158
|
https://github.com/Breeze/breeze.js/blob/06b4919202bd20388847ce7d0cf57b6011cca158/build/breeze.debug.js#L12510-L12523
|
16,198
|
Breeze/breeze.js
|
build/breeze.debug.js
|
EntityManager
|
function EntityManager(config) {
if (arguments.length > 1) {
throw new Error("The EntityManager ctor has a single optional argument that is either a 'serviceName' or a configuration object.");
}
if (arguments.length === 0) {
config = { serviceName: "" };
} else if (typeof config === 'string') {
config = { serviceName: config };
}
updateWithConfig(this, config, true);
this.entityChanged = new Event("entityChanged", this);
this.validationErrorsChanged = new Event("validationErrorsChanged", this);
this.hasChangesChanged = new Event("hasChangesChanged", this);
this.clear();
}
|
javascript
|
function EntityManager(config) {
if (arguments.length > 1) {
throw new Error("The EntityManager ctor has a single optional argument that is either a 'serviceName' or a configuration object.");
}
if (arguments.length === 0) {
config = { serviceName: "" };
} else if (typeof config === 'string') {
config = { serviceName: config };
}
updateWithConfig(this, config, true);
this.entityChanged = new Event("entityChanged", this);
this.validationErrorsChanged = new Event("validationErrorsChanged", this);
this.hasChangesChanged = new Event("hasChangesChanged", this);
this.clear();
}
|
[
"function",
"EntityManager",
"(",
"config",
")",
"{",
"if",
"(",
"arguments",
".",
"length",
">",
"1",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"The EntityManager ctor has a single optional argument that is either a 'serviceName' or a configuration object.\"",
")",
";",
"}",
"if",
"(",
"arguments",
".",
"length",
"===",
"0",
")",
"{",
"config",
"=",
"{",
"serviceName",
":",
"\"\"",
"}",
";",
"}",
"else",
"if",
"(",
"typeof",
"config",
"===",
"'string'",
")",
"{",
"config",
"=",
"{",
"serviceName",
":",
"config",
"}",
";",
"}",
"updateWithConfig",
"(",
"this",
",",
"config",
",",
"true",
")",
";",
"this",
".",
"entityChanged",
"=",
"new",
"Event",
"(",
"\"entityChanged\"",
",",
"this",
")",
";",
"this",
".",
"validationErrorsChanged",
"=",
"new",
"Event",
"(",
"\"validationErrorsChanged\"",
",",
"this",
")",
";",
"this",
".",
"hasChangesChanged",
"=",
"new",
"Event",
"(",
"\"hasChangesChanged\"",
",",
"this",
")",
";",
"this",
".",
"clear",
"(",
")",
";",
"}"
] |
Instances of the EntityManager contain and manage collections of entities, either retrieved from a backend datastore or created on the client.
@class EntityManager
At its most basic an EntityManager can be constructed with just a service name
@example
var entityManager = new EntityManager( "breeze/NorthwindIBModel");
This is the same as calling it with the following configuration object
@example
var entityManager = new EntityManager( {serviceName: "breeze/NorthwindIBModel" });
Usually however, configuration objects will contain more than just the 'serviceName';
@example
var metadataStore = new MetadataStore();
var entityManager = new EntityManager( {
serviceName: "breeze/NorthwindIBModel",
metadataStore: metadataStore
});
or
@example
return new QueryOptions({
mergeStrategy: obj,
fetchStrategy: this.fetchStrategy
});
var queryOptions = new QueryOptions({
mergeStrategy: MergeStrategy.OverwriteChanges,
fetchStrategy: FetchStrategy.FromServer
});
var validationOptions = new ValidationOptions({
validateOnAttach: true,
validateOnSave: true,
validateOnQuery: false
});
var entityManager = new EntityManager({
serviceName: "breeze/NorthwindIBModel",
queryOptions: queryOptions,
validationOptions: validationOptions
});
@method <ctor> EntityManager
@param [config] {Object|String} Configuration settings or a service name.
@param [config.serviceName] {String}
@param [config.dataService] {DataService} An entire DataService (instead of just the serviceName above).
@param [config.metadataStore=MetadataStore.defaultInstance] {MetadataStore}
@param [config.queryOptions] {QueryOptions}
@param [config.saveOptions] {SaveOptions}
@param [config.validationOptions=ValidationOptions.defaultInstance] {ValidationOptions}
@param [config.keyGeneratorCtor] {Function}
|
[
"Instances",
"of",
"the",
"EntityManager",
"contain",
"and",
"manage",
"collections",
"of",
"entities",
"either",
"retrieved",
"from",
"a",
"backend",
"datastore",
"or",
"created",
"on",
"the",
"client",
"."
] |
06b4919202bd20388847ce7d0cf57b6011cca158
|
https://github.com/Breeze/breeze.js/blob/06b4919202bd20388847ce7d0cf57b6011cca158/build/breeze.debug.js#L13015-L13034
|
16,199
|
Breeze/breeze.js
|
build/breeze.debug.js
|
checkEntityTypes
|
function checkEntityTypes(em, entityTypes) {
assertParam(entityTypes, "entityTypes").isString().isOptional().or().isNonEmptyArray().isString()
.or().isInstanceOf(EntityType).or().isNonEmptyArray().isInstanceOf(EntityType).check();
if (typeof entityTypes === "string") {
entityTypes = em.metadataStore._getEntityType(entityTypes, false);
} else if (Array.isArray(entityTypes) && typeof entityTypes[0] === "string") {
entityTypes = entityTypes.map(function (etName) {
return em.metadataStore._getEntityType(etName, false);
});
}
return entityTypes;
}
|
javascript
|
function checkEntityTypes(em, entityTypes) {
assertParam(entityTypes, "entityTypes").isString().isOptional().or().isNonEmptyArray().isString()
.or().isInstanceOf(EntityType).or().isNonEmptyArray().isInstanceOf(EntityType).check();
if (typeof entityTypes === "string") {
entityTypes = em.metadataStore._getEntityType(entityTypes, false);
} else if (Array.isArray(entityTypes) && typeof entityTypes[0] === "string") {
entityTypes = entityTypes.map(function (etName) {
return em.metadataStore._getEntityType(etName, false);
});
}
return entityTypes;
}
|
[
"function",
"checkEntityTypes",
"(",
"em",
",",
"entityTypes",
")",
"{",
"assertParam",
"(",
"entityTypes",
",",
"\"entityTypes\"",
")",
".",
"isString",
"(",
")",
".",
"isOptional",
"(",
")",
".",
"or",
"(",
")",
".",
"isNonEmptyArray",
"(",
")",
".",
"isString",
"(",
")",
".",
"or",
"(",
")",
".",
"isInstanceOf",
"(",
"EntityType",
")",
".",
"or",
"(",
")",
".",
"isNonEmptyArray",
"(",
")",
".",
"isInstanceOf",
"(",
"EntityType",
")",
".",
"check",
"(",
")",
";",
"if",
"(",
"typeof",
"entityTypes",
"===",
"\"string\"",
")",
"{",
"entityTypes",
"=",
"em",
".",
"metadataStore",
".",
"_getEntityType",
"(",
"entityTypes",
",",
"false",
")",
";",
"}",
"else",
"if",
"(",
"Array",
".",
"isArray",
"(",
"entityTypes",
")",
"&&",
"typeof",
"entityTypes",
"[",
"0",
"]",
"===",
"\"string\"",
")",
"{",
"entityTypes",
"=",
"entityTypes",
".",
"map",
"(",
"function",
"(",
"etName",
")",
"{",
"return",
"em",
".",
"metadataStore",
".",
"_getEntityType",
"(",
"etName",
",",
"false",
")",
";",
"}",
")",
";",
"}",
"return",
"entityTypes",
";",
"}"
] |
takes in entityTypes as either strings or entityTypes or arrays of either and returns either an entityType or an array of entityTypes or throws an error
|
[
"takes",
"in",
"entityTypes",
"as",
"either",
"strings",
"or",
"entityTypes",
"or",
"arrays",
"of",
"either",
"and",
"returns",
"either",
"an",
"entityType",
"or",
"an",
"array",
"of",
"entityTypes",
"or",
"throws",
"an",
"error"
] |
06b4919202bd20388847ce7d0cf57b6011cca158
|
https://github.com/Breeze/breeze.js/blob/06b4919202bd20388847ce7d0cf57b6011cca158/build/breeze.debug.js#L14667-L14678
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.