type
stringclasses 7
values | content
stringlengths 4
9.55k
| repo
stringlengths 7
96
| path
stringlengths 4
178
| language
stringclasses 1
value |
|---|---|---|---|---|
ArrowFunction
|
_type => NullableStringFieldUpdateOperationsInput
|
ayushpandey8439/backend
|
graphql/generated/resolvers/inputs/Instructor_screeningUpdateWithoutScreenerInput.ts
|
TypeScript
|
ArrowFunction
|
_type => DateTimeFieldUpdateOperationsInput
|
ayushpandey8439/backend
|
graphql/generated/resolvers/inputs/Instructor_screeningUpdateWithoutScreenerInput.ts
|
TypeScript
|
ArrowFunction
|
_type => StudentUpdateOneWithoutInstructor_screeningInput
|
ayushpandey8439/backend
|
graphql/generated/resolvers/inputs/Instructor_screeningUpdateWithoutScreenerInput.ts
|
TypeScript
|
ClassDeclaration
|
@TypeGraphQL.InputType({
isAbstract: true
})
export class Instructor_screeningUpdateWithoutScreenerInput {
@TypeGraphQL.Field(_type => BoolFieldUpdateOperationsInput, {
nullable: true
})
success?: BoolFieldUpdateOperationsInput | undefined;
@TypeGraphQL.Field(_type => NullableStringFieldUpdateOperationsInput, {
nullable: true
})
comment?: NullableStringFieldUpdateOperationsInput | undefined;
@TypeGraphQL.Field(_type => NullableStringFieldUpdateOperationsInput, {
nullable: true
})
knowsCoronaSchoolFrom?: NullableStringFieldUpdateOperationsInput | undefined;
@TypeGraphQL.Field(_type => DateTimeFieldUpdateOperationsInput, {
nullable: true
})
createdAt?: DateTimeFieldUpdateOperationsInput | undefined;
@TypeGraphQL.Field(_type => DateTimeFieldUpdateOperationsInput, {
nullable: true
})
updatedAt?: DateTimeFieldUpdateOperationsInput | undefined;
@TypeGraphQL.Field(_type => StudentUpdateOneWithoutInstructor_screeningInput, {
nullable: true
})
student?: StudentUpdateOneWithoutInstructor_screeningInput | undefined;
}
|
ayushpandey8439/backend
|
graphql/generated/resolvers/inputs/Instructor_screeningUpdateWithoutScreenerInput.ts
|
TypeScript
|
ArrowFunction
|
v => v.version === this.version
|
angie1148/node-launcher
|
src/types/fuse/fuse.ts
|
TypeScript
|
ArrowFunction
|
key => !/^_/.test(key)
|
angie1148/node-launcher
|
src/types/fuse/fuse.ts
|
TypeScript
|
ArrowFunction
|
key => typeof this[key] !== 'function' && typeof this[key] !== 'undefined'
|
angie1148/node-launcher
|
src/types/fuse/fuse.ts
|
TypeScript
|
ArrowFunction
|
(obj: any, key) => ({...obj, [key]: this[key]})
|
angie1148/node-launcher
|
src/types/fuse/fuse.ts
|
TypeScript
|
ArrowFunction
|
({ version }) => version === this.version
|
angie1148/node-launcher
|
src/types/fuse/fuse.ts
|
TypeScript
|
ArrowFunction
|
str => this._logOutput(str)
|
angie1148/node-launcher
|
src/types/fuse/fuse.ts
|
TypeScript
|
ArrowFunction
|
resolve => {
this._docker.run(
this.dockerImage + ` account import ${accountPath}${versionData.generateRuntimeArgs(this)}`,
newArgs,
output => this._logOutput(output),
err => this._logError(err),
() => resolve(),
);
}
|
angie1148/node-launcher
|
src/types/fuse/fuse.ts
|
TypeScript
|
ArrowFunction
|
output => this._logOutput(output)
|
angie1148/node-launcher
|
src/types/fuse/fuse.ts
|
TypeScript
|
ArrowFunction
|
err => this._logError(err)
|
angie1148/node-launcher
|
src/types/fuse/fuse.ts
|
TypeScript
|
ArrowFunction
|
code => this._logClose(code)
|
angie1148/node-launcher
|
src/types/fuse/fuse.ts
|
TypeScript
|
ArrowFunction
|
() => this._logOutput(`${this.validatorAppContainerName()} closed`)
|
angie1148/node-launcher
|
src/types/fuse/fuse.ts
|
TypeScript
|
ArrowFunction
|
() => this._logOutput(`${this.netstatContainerName()} closed`)
|
angie1148/node-launcher
|
src/types/fuse/fuse.ts
|
TypeScript
|
ArrowFunction
|
resolve => {
if(this._instance) {
const { exitCode } = this._instance;
if(typeof exitCode === 'number') {
resolve();
} else {
this._instance.on('exit', () => {
clearTimeout(timeout);
setTimeout(() => {
resolve();
}, 1000);
});
this._instance.kill();
const timeout = setTimeout(() => {
this._docker.stop(this.id)
.then(() => {
setTimeout(() => {
resolve();
}, 1000);
})
.catch(err => {
this._logError(err);
resolve();
});
}, 30000);
}
} else {
resolve();
}
}
|
angie1148/node-launcher
|
src/types/fuse/fuse.ts
|
TypeScript
|
ArrowFunction
|
() => {
clearTimeout(timeout);
setTimeout(() => {
resolve();
}, 1000);
}
|
angie1148/node-launcher
|
src/types/fuse/fuse.ts
|
TypeScript
|
ArrowFunction
|
() => {
resolve();
}
|
angie1148/node-launcher
|
src/types/fuse/fuse.ts
|
TypeScript
|
ArrowFunction
|
() => {
this._docker.stop(this.id)
.then(() => {
setTimeout(() => {
resolve();
}, 1000);
})
.catch(err => {
this._logError(err);
resolve();
});
}
|
angie1148/node-launcher
|
src/types/fuse/fuse.ts
|
TypeScript
|
ArrowFunction
|
() => {
setTimeout(() => {
resolve();
}, 1000);
}
|
angie1148/node-launcher
|
src/types/fuse/fuse.ts
|
TypeScript
|
ArrowFunction
|
() => {
resolve();
}
|
angie1148/node-launcher
|
src/types/fuse/fuse.ts
|
TypeScript
|
ArrowFunction
|
err => {
this._logError(err);
resolve();
}
|
angie1148/node-launcher
|
src/types/fuse/fuse.ts
|
TypeScript
|
InterfaceDeclaration
|
interface FuseVersionDockerImage extends VersionDockerImage {
passwordPath: string
imageValidatorApp: string
imageNetstat: string
}
|
angie1148/node-launcher
|
src/types/fuse/fuse.ts
|
TypeScript
|
MethodDeclaration
|
static versions(client: string, networkType: string): FuseVersionDockerImage[] {
client = client || Fuse.clients[0];
let versions: FuseVersionDockerImage[];
switch(client) {
case NodeClient.OPEN_ETHEREUM:
versions = [
{
version: '2.0.2',
clientVersion: '3.2.6',
image: 'fusenet/spark-node:2.0.2',
imageValidatorApp: 'fusenet/spark-validator-app:1.0.0',
imageNetstat: 'fusenet/spark-netstat:1.0.0',
dataDir: '/root/data',
walletDir: '/root/keystore',
configDir: '/root/config',
passwordPath: '/root/pass.pwd',
networks: [NetworkType.TESTNET],
breaking: false,
generateRuntimeArgs(data: CryptoNodeData): string {
return ` --no-warp --config=${path.join(this.configDir, Fuse.configName(data))}`;
},
},
{
version: '2.0.1',
clientVersion: '3.2.6',
image: 'fusenet/spark-node:2.0.1_OE',
imageValidatorApp: '',
imageNetstat: '',
dataDir: '/root/data',
walletDir: '/root/keystore',
configDir: '/root/config',
passwordPath: '/root/pass.pwd',
networks: [NetworkType.TESTNET],
breaking: false,
generateRuntimeArgs(data: CryptoNodeData): string {
return ` --no-warp --config=${path.join(this.configDir, Fuse.configName(data))} --bootnodes ${testnetBootnodes}`;
},
},
{
version: '2.0.1',
clientVersion: '3.2.6',
image: 'fusenet/node:2.0.1',
imageValidatorApp: '',
imageNetstat: '',
dataDir: '/root/data',
walletDir: '/root/keystore',
configDir: '/root/config',
passwordPath: '/root/pass.pwd',
networks: [NetworkType.MAINNET],
breaking: false,
generateRuntimeArgs(data: CryptoNodeData): string {
return ` --no-warp --config=${path.join(this.configDir, Fuse.configName(data))}`;
},
},
{
version: '2.5.13',
clientVersion: '2.5.13',
image: 'fusenet/node:1.0.0',
imageValidatorApp: '',
imageNetstat: '',
dataDir: '/root/data',
walletDir: '/root/keystore',
configDir: '/root/config',
passwordPath: '/root/pass.pwd',
networks: [NetworkType.MAINNET],
breaking: false,
generateRuntimeArgs(data: CryptoNodeData): string {
return ` --config=${path.join(this.configDir, Fuse.configName(data))}`;
},
},
];
break;
default:
versions = [];
}
return filterVersionsByNetworkType(networkType, versions) as FuseVersionDockerImage[];
}
|
angie1148/node-launcher
|
src/types/fuse/fuse.ts
|
TypeScript
|
MethodDeclaration
|
generateRuntimeArgs(data: CryptoNodeData): string {
return ` --no-warp --config=${path.join(this.configDir, Fuse.configName(data))}`;
}
|
angie1148/node-launcher
|
src/types/fuse/fuse.ts
|
TypeScript
|
MethodDeclaration
|
generateRuntimeArgs(data: CryptoNodeData): string {
return ` --no-warp --config=${path.join(this.configDir, Fuse.configName(data))} --bootnodes ${testnetBootnodes}`;
}
|
angie1148/node-launcher
|
src/types/fuse/fuse.ts
|
TypeScript
|
MethodDeclaration
|
generateRuntimeArgs(data: CryptoNodeData): string {
return ` --config=${path.join(this.configDir, Fuse.configName(data))}`;
}
|
angie1148/node-launcher
|
src/types/fuse/fuse.ts
|
TypeScript
|
MethodDeclaration
|
static generateConfig(client: string|Fuse = Fuse.clients[0], network = NetworkType.MAINNET, peerPort = Fuse.defaultPeerPort[NetworkType.MAINNET], rpcPort = Fuse.defaultRPCPort[NetworkType.MAINNET]): string {
let baseConfig = coreConfig;
let address = '';
if(typeof client !== 'string') { // node was passed in rather than client string
const node = client;
client = node.client;
network = node.network;
peerPort = node.peerPort;
rpcPort = node.rpcPort;
address = node.address;
if(node.role === Role.VALIDATOR)
baseConfig = coreValidatorConfig;
}
switch(client) {
case NodeClient.OPEN_ETHEREUM:
return baseConfig
.replace('{{address}}', address)
.replace('{{PEER_PORT}}', peerPort.toString(10))
.replace(/{{RPC_PORT}}/g, rpcPort.toString(10))
.trim();
case NodeClient.PARITY:
return baseConfig
.replace('{{PEER_PORT}}', peerPort.toString(10))
.replace(/{{RPC_PORT}}/g, rpcPort.toString(10))
.trim();
default:
return '';
}
}
|
angie1148/node-launcher
|
src/types/fuse/fuse.ts
|
TypeScript
|
MethodDeclaration
|
static configName(data: CryptoNodeData): string {
return 'config.toml';
}
|
angie1148/node-launcher
|
src/types/fuse/fuse.ts
|
TypeScript
|
MethodDeclaration
|
toObject(): CryptoNodeData {
let keys = Object
.keys(this)
.filter(key => !/^_/.test(key));
// @ts-ignore
keys = keys.filter(key => typeof this[key] !== 'function' && typeof this[key] !== 'undefined');
// @ts-ignore
const dataObj = keys.reduce((obj: any, key) => ({...obj, [key]: this[key]}), {});
return dataObj as CryptoNodeData;
}
|
angie1148/node-launcher
|
src/types/fuse/fuse.ts
|
TypeScript
|
MethodDeclaration
|
async start(): Promise<ChildProcess[]> {
const fs = this._fs;
const versions = Fuse.versions(this.client, this.network);
const versionData = versions.find(({ version }) => version === this.version) || versions[0];
if(!versionData)
throw new Error(`Unknown ${this.ticker} version ${this.version}`);
const {
dataDir: containerDataDir,
walletDir: containerWalletDir,
configDir: containerConfigDir,
passwordPath: containerPasswordPath,
} = versionData;
let args = [
'-i',
'--rm',
'--memory', this.dockerMem.toString(10) + 'MB',
'--cpus', this.dockerCPUs.toString(10),
'--name', this.id,
'--network', this.dockerNetwork,
'-p', `${this.rpcPort}:${this.rpcPort}`,
'-p', `${this.peerPort}:${this.peerPort}/tcp`,
'-p', `${this.peerPort}:${this.peerPort}/udp`,
'--entrypoint', '/usr/local/bin/parity',
];
const tmpdir = os.tmpdir();
const dataDir = this.dataDir || path.join(tmpdir, uuid());
args = [...args, '-v', `${dataDir}:${containerDataDir}`];
await fs.ensureDir(dataDir);
const walletDir = this.walletDir || path.join(tmpdir, uuid());
args = [...args, '-v', `${walletDir}:${containerWalletDir}`];
await fs.ensureDir(walletDir);
const configDir = this.configDir || path.join(tmpdir, uuid());
await fs.ensureDir(configDir);
const configPath = path.join(configDir, Fuse.configName(this));
const configExists = await fs.pathExists(configPath);
if(!configExists)
await fs.writeFile(configPath, this.generateConfig(), 'utf8');
args = [...args, '-v', `${configDir}:${containerConfigDir}`];
await this._docker.pull(this.dockerImage, str => this._logOutput(str));
if(this.key) {
const passwordPath = this.passwordPath || path.join(tmpdir, uuid());
const passwordFileExists = await fs.pathExists(passwordPath);
if(!passwordFileExists)
await fs.writeFile(passwordPath, this.keyPass, 'utf8');
args = [...args, '-v', `${passwordPath}:${containerPasswordPath}`];
if((await fs.readdir(walletDir)).length === 0) {
const keyFilePath = path.join(os.tmpdir(), uuid());
await fs.writeJson(keyFilePath, this.key);
const accountPath = `/UTC--${new Date().toISOString().replace(/:/g, '-')}--${this.address}.json`;
const newArgs = [
...args,
'-v', `${keyFilePath}:${accountPath}`,
];
await new Promise<void>(resolve => {
this._docker.run(
this.dockerImage + ` account import ${accountPath}${versionData.generateRuntimeArgs(this)}`,
newArgs,
output => this._logOutput(output),
err => this._logError(err),
() => resolve(),
);
});
await fs.remove(keyFilePath);
}
}
await this._docker.createNetwork(this.dockerNetwork);
const instance = this._docker.run(
this.dockerImage + versionData.generateRuntimeArgs(this),
args,
output => this._logOutput(output),
err => this._logError(err),
code => this._logClose(code),
);
if(this.role === Role.VALIDATOR) {
await new Promise(resolve => setTimeout(resolve, 1000));
// start validator app
const validatorAppArgs = [
'--rm',
'-i',
'--memory', '250m',
'-v', `${path.resolve(walletDir, '..')}:/config`,
'-e', 'CONFIG_DIR=/config',
'-e', `RPC=http://${this.id}:${this.rpcPort}`,
'--network', this.dockerNetwork,
'--name', this.validatorAppContainerName(),
];
try {
const validatorAppExists = await this._docker.containerExists(this.validatorAppContainerName());
if(!validatorAppExists) {
this._docker.run(
versionData.imageValidatorApp,
validatorAppArgs,
() => {},
err => this._logError(err),
() => this._logOutput(`${this.validatorAppContainerName()} closed`),
);
}
} catch(err) {
this._logError(err);
}
// start netstats
const netstatConfig = `
[
{
"name" : "netstat_daemon",
"script" : "app.js",
"log_date_format" : "YYYY-MM-DD HH:mm Z",
"merge_logs" : false,
"watch" : false,
"max_restarts" : 100,
"exec_interpreter" : "node",
"exec_mode" : "fork_mode",
"env":
{
"NODE_ENV" : "production",
"INSTANCE_NAME" : "",
"BRIDGE_VERSION" : "",
"ROLE" : "",
"FUSE_APP_VERSION": "",
"PARITY_VERSION" : "",
"NETSTATS_VERSION": "",
"CONTACT_DETAILS" : "",
"WS_SECRET" : "see http://forum.ethereum.org/discussion/2112/how-to-add-yourself-to-the-stats-dashboard-its-not-automatic",
"WS_SERVER" : "https://health.fuse.io",
"VERBOSITY" : 2
}
}
]`;
const netstatConfigPath = path.join(tmpdir, uuid());
await fs.writeJson(netstatConfigPath, JSON.parse(netstatConfig), {spaces: 2});
const netstatArgs = [
'--rm',
'-i',
'--memory', '250m',
'--name', this.netstatContainerName(),
'--network', this.dockerNetwork,
'--user', 'root',
'-e', `RPC_HOST=${this.id}`,
'-e', `RPC_PORT=${this.rpcPort}`,
'-e', `LISTENING_PORT=${this.peerPort}`,
'-v', `${netstatConfigPath}:/home/ethnetintel/eth-net-intelligence-api/app.json.example`,
];
try {
const netstatExists = await this._docker.containerExists(this.netstatContainerName());
if(!netstatExists) {
this._docker.run(
`${versionData.imageNetstat} --instance-name ${this.address} --role validator --parity-version ${versionData.version} --fuseapp-version ${this.validatorAppContainerName().split(':')[1]} --netstats-version ${this.netstatContainerName().split(':')[1]}`,
netstatArgs,
() => {},
err => this._logError(err),
() => this._logOutput(`${this.netstatContainerName()} closed`),
);
}
} catch(err) {
this._logError(err);
}
}
this._instance = instance;
this._instances = [
instance,
];
return this.instances();
}
|
angie1148/node-launcher
|
src/types/fuse/fuse.ts
|
TypeScript
|
MethodDeclaration
|
validatorAppContainerName(): string {
return `${this.id}-validator-app`;
}
|
angie1148/node-launcher
|
src/types/fuse/fuse.ts
|
TypeScript
|
MethodDeclaration
|
netstatContainerName(): string {
return `${this.id}-netstat`;
}
|
angie1148/node-launcher
|
src/types/fuse/fuse.ts
|
TypeScript
|
MethodDeclaration
|
async stop(): Promise<void> {
if(this.role === Role.VALIDATOR) {
try {
await this._docker.kill(this.validatorAppContainerName());
} catch(err) {
this._logError(err);
}
try {
await this._docker.kill(this.netstatContainerName());
} catch(err) {
this._logError(err);
}
}
await new Promise<void>(resolve => {
if(this._instance) {
const { exitCode } = this._instance;
if(typeof exitCode === 'number') {
resolve();
} else {
this._instance.on('exit', () => {
clearTimeout(timeout);
setTimeout(() => {
resolve();
}, 1000);
});
this._instance.kill();
const timeout = setTimeout(() => {
this._docker.stop(this.id)
.then(() => {
setTimeout(() => {
resolve();
}, 1000);
})
.catch(err => {
this._logError(err);
resolve();
});
}, 30000);
}
} else {
resolve();
}
});
}
|
angie1148/node-launcher
|
src/types/fuse/fuse.ts
|
TypeScript
|
MethodDeclaration
|
generateConfig(): string {
return Fuse.generateConfig(this);
}
|
angie1148/node-launcher
|
src/types/fuse/fuse.ts
|
TypeScript
|
MethodDeclaration
|
createAccount(): void {
const web3 = new Web3();
const keyPass = this.keyPass || uuid();
const { address, privateKey } = web3.eth.accounts.create();
this.keyPass = keyPass;
this.address = address;
this.key = web3.eth.accounts.encrypt(privateKey, keyPass);
}
|
angie1148/node-launcher
|
src/types/fuse/fuse.ts
|
TypeScript
|
MethodDeclaration
|
async rpcGetBalance(): Promise<string> {
try {
const web3 = new Web3(`http://localhost:${this.rpcPort}`);
return await web3.eth.getBalance(this.address);
} catch(err) {
return '';
}
}
|
angie1148/node-launcher
|
src/types/fuse/fuse.ts
|
TypeScript
|
ArrowFunction
|
(prototype, property) => {
const attributes: IObject<any> = {
enumerable: true,
configurable: true,
get() {
return this.options[property];
},
};
const setter = camelize(`set ${property}`);
if (prototype[setter]) {
attributes.set = function(value) {
this[setter](value);
};
} else {
attributes.set = function(value) {
this.options[property] = value;
};
}
Object.defineProperty(prototype, property, attributes);
}
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
ArrowFunction
|
() => {
options.keyContainer = keyContainer;
this.setKeyController();
}
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
ArrowFunction
|
() => {
options.toggleContinueSelect = toggleContinueSelect;
this.setKeyEvent();
}
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
ArrowFunction
|
(rect, i) => {
const {
left: rectLeft,
top: rectTop,
right: rectRight,
bottom: rectBottom,
} = rect;
const isStart
= rectLeft <= clientX
&& clientX <= rectRight
&& rectTop <= clientY
&& clientY <= rectBottom;
const rectSize = (rectRight - rectLeft) * (rectBottom - rectTop);
const testLeft = Math.max(rectLeft, left);
const testRight = Math.min(rectRight, right);
const testTop = Math.max(rectTop, top);
const testBottom = Math.min(rectBottom, bottom);
if (selectByClick && isStart) {
passedTargets.push(targets[i]);
return;
}
if (testRight < testLeft || testBottom < testTop) {
return;
}
const rate = Math.round((testRight - testLeft) * (testBottom - testTop) / rectSize * 100);
if (rate >= hitRate) {
passedTargets.push(targets[i]);
}
}
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
ArrowFunction
|
({ container, direction }) => {
this.trigger("scroll", {
container,
direction,
});
}
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
ArrowFunction
|
({ offsetX, offsetY, inputEvent }) => {
const datas = inputEvent.datas;
datas.startX -= offsetX;
datas.startY -= offsetY;
datas.selectableRects.forEach(rect => {
rect.top -= offsetY;
rect.bottom -= offsetY;
rect.left -= offsetX;
rect.right -= offsetX;
});
this.dragger.scrollBy(offsetX, offsetY, inputEvent.inputEvent, false);
inputEvent.distX += offsetX;
inputEvent.distY += offsetY;
this.check(inputEvent);
}
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
ArrowFunction
|
rect => {
rect.top -= offsetY;
rect.bottom -= offsetY;
rect.left -= offsetX;
rect.right -= offsetX;
}
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
ArrowFunction
|
target => {
if (isObject(target)) {
selectableTargets.push(target);
} else {
const elements = [].slice.call(document.querySelectorAll(target));
elements.forEach(el => {
selectableTargets.push(el);
});
}
}
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
ArrowFunction
|
el => {
selectableTargets.push(el);
}
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
ArrowFunction
|
index => list[index]
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
ArrowFunction
|
index => prevList[index]
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
ArrowFunction
|
index => afterList[index]
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
ArrowFunction
|
index => afterPrevList[index]
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
ArrowFunction
|
(e: OnDragEvent, clickedTarget?: Element) => {
const { datas, clientX, clientY, inputEvent } = e;
const { continueSelect, selectFromInside, selectByClick } = this.options;
const selectableTargets = this.getSelectableTargets();
const selectableRects = selectableTargets.map(target => {
const rect = target.getBoundingClientRect();
const { left, top, width, height } = rect;
return {
left,
top,
right: left + width,
bottom: top + height,
width,
height,
};
});
datas.selectableTargets = selectableTargets;
datas.selectableRects = selectableRects;
datas.startSelectedTargets = this.selectedTargets;
const pointTarget = clickedTarget || document.elementFromPoint(clientX, clientY);
const hitRect = {
left: clientX,
top: clientY,
right: clientX,
bottom: clientY,
width: 0,
height: 0,
};
let firstPassedTargets = this.hitTest(
hitRect, clientX, clientY, selectableTargets, selectableRects).filter(
target => target === pointTarget || target.contains(pointTarget),
);
const hasInsideTargets = firstPassedTargets.length > 0;
const isPreventSelect = !selectFromInside && hasInsideTargets;
if (isPreventSelect && !selectByClick) {
return false;
}
if (!continueSelect) {
this.selectedTargets = [];
} else {
firstPassedTargets = this.getSelectedTargets(firstPassedTargets);
}
const type = inputEvent.type;
const isTrusted = type === "mousedown" || type === "touchstart";
/**
* When the drag starts, the dragStart event is called.
* Call the stop () function if you have a specific element or don't want to raise a select
* @memberof Selecto
* @event dragStart
* @param {OnDragStart} - Parameters for the dragStart event
* @example
* import Selecto from "selecto";
*
* const selecto = new Selecto({
* container: document.body,
* selectByClick: true,
* selectFromInside: false,
* });
*
* selecto.on("dragStart", e => {
* if (e.inputEvent.target.tagName === "SPAN") {
* e.stop();
* }
* }).on("select", e => {
* e.added.forEach(el => {
* el.classList.add("selected");
* });
* e.removed.forEach(el => {
* el.classList.remove("selected");
* });
* });
*/
const result = isTrusted ? this.trigger("dragStart", e) : true;
if (!result) {
return false;
}
this.select(firstPassedTargets, hitRect, inputEvent, true);
datas.startX = clientX;
datas.startY = clientY;
datas.selectedTargets = firstPassedTargets;
this.target.style.cssText
+= `left:0px;top:0px;transform: translate(${clientX}px, ${clientY}px)`;
if (isPreventSelect && selectByClick) {
this.onDragEnd(e);
inputEvent.preventDefault();
return false;
} else {
if (type === "touchstart") {
inputEvent.preventDefault();
}
const { scrollOptions } = this.options;
if (scrollOptions && scrollOptions.container) {
this.dragScroll.dragStart(e, scrollOptions);
}
return true;
}
}
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
ArrowFunction
|
target => {
const rect = target.getBoundingClientRect();
const { left, top, width, height } = rect;
return {
left,
top,
right: left + width,
bottom: top + height,
width,
height,
};
}
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
ArrowFunction
|
target => target === pointTarget || target.contains(pointTarget)
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
ArrowFunction
|
(e: OnDrag) => {
const { scrollOptions } = this.options;
if (scrollOptions && scrollOptions.container) {
if (this.dragScroll.drag(e, scrollOptions)) {
return;
}
}
this.check(e);
}
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
ArrowFunction
|
(e: OnDragEvent) => {
const { datas } = e;
const rect = getRect(e);
this.dragScroll.dragEnd();
this.target.style.cssText += "display: none;";
this.trigger("dragEnd", {
...e,
rect,
});
this.selectEnd(
datas.startSelectedTargets, datas.selectedTargets, rect, e);
this.selectedTargets = datas.selectedTargets;
}
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
ArrowFunction
|
key => combi.indexOf(key) > -1
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
ArrowFunction
|
(e: any) => {
if (!this.sameCombiKey(e)) {
return;
}
this.continueSelect = true;
/**
* When you keydown the key you specified in toggleContinueSelect, the keydown event is called.
* @memberof Selecto
* @event keydown
* @example
* import Selecto from "selecto";
*
* const selecto = new Selecto({
* container: document.body,
* toggleContinueSelect: "shift";
* keyContainer: window,
* });
*
* selecto.on("keydown", () => {
* document.querySelector(".button").classList.add("selected");
* }).on("keyup", () => {
* document.querySelector(".button").classList.remove("selected");
* }).on("select", e => {
* e.added.forEach(el => {
* el.classList.add("selected");
* });
* e.removed.forEach(el => {
* el.classList.remove("selected");
* });
* });
*/
this.trigger("keydown", {});
}
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
ArrowFunction
|
(e: any) => {
if (!this.sameCombiKey(e)) {
return;
}
this.continueSelect = false;
/**
* When you keyup the key you specified in toggleContinueSelect, the keyup event is called.
* @memberof Selecto
* @event keyup
* @example
* import Selecto from "selecto";
*
* const selecto = new Selecto({
* container: document.body,
* toggleContinueSelect: "shift";
* keyContainer: window,
* });
*
* selecto.on("keydown", () => {
* document.querySelector(".button").classList.add("selected");
* }).on("keyup", () => {
* document.querySelector(".button").classList.remove("selected");
* }).on("select", e => {
* e.added.forEach(el => {
* el.classList.add("selected");
* });
* e.removed.forEach(el => {
* el.classList.remove("selected");
* });
* });
*/
this.trigger("keyup", {});
}
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
ArrowFunction
|
() => {
if (this.toggleContinueSelect && this.continueSelect) {
this.trigger("keyup", {});
}
}
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
ArrowFunction
|
(e: any) => {
if (!this.dragger.isFlag()) {
return;
}
let dragContainer = this.dragContainer;
if (dragContainer === window) {
dragContainer = document.documentElement;
}
const containers = dragContainer instanceof Element
? [dragContainer] : [].slice.call(dragContainer) as Element[];
const target = e.target;
containers.some(container => {
if (container === target || container.contains(target)) {
e.preventDefault();
return true;
}
});
}
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
ArrowFunction
|
container => {
if (container === target || container.contains(target)) {
e.preventDefault();
return true;
}
}
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
InterfaceDeclaration
|
interface Selecto extends Component, SelectoProperties {
on<T extends keyof SelectoEvents>(eventName: T, handlerToAttach: (event: SelectoEvents[T]) => any): this;
on(eventName: string, handlerToAttach: (event: { [key: string]: any }) => any): this;
on(events: { [key: string]: (event: { [key: string]: any }) => any }): this;
}
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
MethodDeclaration
|
get() {
return this.options[property];
}
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
MethodDeclaration
|
/**
* You can set the currently selected targets.
*/
public setSelectedTargets(selectedTargets: Array<HTMLElement | SVGElement>): this {
this.selectedTargets = selectedTargets;
this.differ = new ChildrenDiffer(selectedTargets);
return this;
}
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
MethodDeclaration
|
public setKeyContainer(keyContainer: HTMLElement | Document | Window) {
const options = this.options;
diffValue(options.keyContainer, keyContainer, () => {
options.keyContainer = keyContainer;
this.setKeyController();
});
}
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
MethodDeclaration
|
public setToggleContinueSelect(toggleContinueSelect: string[] | string) {
const options = this.options;
diffValue(options.toggleContinueSelect, toggleContinueSelect, () => {
options.toggleContinueSelect = toggleContinueSelect;
this.setKeyEvent();
});
}
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
MethodDeclaration
|
public setPreventDefault(value: boolean) {
this.dragger.options.preventDefault = value;
}
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
MethodDeclaration
|
public setCheckInput(value: boolean) {
this.dragger.options.checkInput = value;
}
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
MethodDeclaration
|
/**
* `OnDragStart` is triggered by an external event.
* @param - external event
* @example
* import Selecto from "selecto";
*
* const selecto = new Selecto();
*
* window.addEventListener("mousedown", e => {
* selecto.triggerDragStart(e);
* });
*/
public triggerDragStart(e: MouseEvent | TouchEvent) {
this.dragger.triggerDragStart(e);
return this;
}
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
MethodDeclaration
|
/**
* Destroy elements, properties, and events.
*/
public destroy(): void {
this.off();
this.keycon && this.keycon.destroy();
this.dragger.unset();
this.injectResult.destroy();
removeEvent(document, "selectstart", this.onDocumentSelectStart);
this.keycon = null;
this.dragger = null;
this.injectResult = null;
this.target = null;
this.container = null;
this.options = null;
}
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
MethodDeclaration
|
/**
* External click or mouse events can be applied to the selecto.
* @params - Extenal click or mouse event
* @params - Specify the clicked target directly.
*/
public clickTarget(e: MouseEvent | TouchEvent, clickedTarget?: Element): this {
const { clientX, clientY } = getClient(e);
const dragEvent: OnDragEvent = {
datas: {},
clientX,
clientY,
inputEvent: e,
};
if (this.onDragStart(dragEvent, clickedTarget)) {
this.onDragEnd(dragEvent);
}
return this;
}
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
MethodDeclaration
|
private setKeyController() {
const { keyContainer, toggleContinueSelect } = this.options;
if (this.keycon) {
this.keycon.destroy();
this.keycon = null;
}
if (toggleContinueSelect) {
this.keycon = new KeyController(keyContainer || window);
this.keycon.keydown(this.onKeyDown).keyup(this.onKeyUp).on("blur", this.onBlur);
}
}
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
MethodDeclaration
|
private setKeyEvent() {
const { toggleContinueSelect } = this.options;
if (!toggleContinueSelect || this.keycon) {
return;
}
this.setKeyController();
}
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
MethodDeclaration
|
private initElement() {
this.target = createElement(
<div className={CLASS_NAME}></div> as any,
this.target,
this.container,
);
const target = this.target;
const { dragContainer, checkInput, preventDefault } = this.options;
this.dragContainer = typeof dragContainer === "string"
? [].slice.call(document.querySelectorAll(dragContainer))
: (this.options.dragContainer || this.target.parentNode as any);
this.dragger = new Dragger(this.dragContainer, {
container: window,
checkInput,
preventDefault,
dragstart: this.onDragStart,
drag: this.onDrag,
dragend: this.onDragEnd,
});
addEvent(document, "selectstart", this.onDocumentSelectStart);
this.injectResult = injector.inject(target, {
nonce: this.options.cspNonce,
});
}
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
MethodDeclaration
|
private hitTest(
selectRect: Rect,
clientX: number,
clientY: number,
targets: Array<HTMLElement | SVGElement>,
rects: Rect[],
) {
const { hitRate, selectByClick } = this.options;
const { left, top, right, bottom } = selectRect;
const passedTargets: Array<HTMLElement | SVGElement> = [];
rects.forEach((rect, i) => {
const {
left: rectLeft,
top: rectTop,
right: rectRight,
bottom: rectBottom,
} = rect;
const isStart
= rectLeft <= clientX
&& clientX <= rectRight
&& rectTop <= clientY
&& clientY <= rectBottom;
const rectSize = (rectRight - rectLeft) * (rectBottom - rectTop);
const testLeft = Math.max(rectLeft, left);
const testRight = Math.min(rectRight, right);
const testTop = Math.max(rectTop, top);
const testBottom = Math.min(rectBottom, bottom);
if (selectByClick && isStart) {
passedTargets.push(targets[i]);
return;
}
if (testRight < testLeft || testBottom < testTop) {
return;
}
const rate = Math.round((testRight - testLeft) * (testBottom - testTop) / rectSize * 100);
if (rate >= hitRate) {
passedTargets.push(targets[i]);
}
});
return passedTargets;
}
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
MethodDeclaration
|
private initDragScroll() {
this.dragScroll.on("scroll", ({ container, direction }) => {
this.trigger("scroll", {
container,
direction,
});
}).on("move", ({ offsetX, offsetY, inputEvent }) => {
const datas = inputEvent.datas;
datas.startX -= offsetX;
datas.startY -= offsetY;
datas.selectableRects.forEach(rect => {
rect.top -= offsetY;
rect.bottom -= offsetY;
rect.left -= offsetX;
rect.right -= offsetX;
});
this.dragger.scrollBy(offsetX, offsetY, inputEvent.inputEvent, false);
inputEvent.distX += offsetX;
inputEvent.distY += offsetY;
this.check(inputEvent);
});
}
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
MethodDeclaration
|
private getSelectableTargets() {
const selectableTargets: Array<HTMLElement | SVGElement> = [];
this.options.selectableTargets.forEach(target => {
if (isObject(target)) {
selectableTargets.push(target);
} else {
const elements = [].slice.call(document.querySelectorAll(target));
elements.forEach(el => {
selectableTargets.push(el);
});
}
});
return selectableTargets;
}
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
MethodDeclaration
|
private getSelectedTargets(passedTargets: Array<HTMLElement | SVGElement>) {
const {
list,
prevList,
added,
removed,
} = diff(this.selectedTargets, passedTargets) as ChildrenDiffResult<HTMLElement | SVGElement>;
return added.map(index => list[index]).concat(removed.map(index => prevList[index]));
}
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
MethodDeclaration
|
private select(
selectedTargets: Array<HTMLElement | SVGElement>, rect: Rect, inputEvent: any, isStart?: boolean) {
const {
added,
removed,
prevList,
list,
} = this.differ.update(selectedTargets);
if (isStart) {
/**
* When the select(drag) starts, the selectStart event is called.
* @memberof Selecto
* @event selectStart
* @param {Selecto.OnSelect} - Parameters for the selectStart event
* @example
* import Selecto from "selecto";
*
* const selecto = new Selecto({
* container: document.body,
* selectByClick: true,
* selectFromInside: false,
* });
*
* selecto.on("selectStart", e => {
* e.added.forEach(el => {
* el.classList.add("selected");
* });
* e.removed.forEach(el => {
* el.classList.remove("selected");
* });
* }).on("selectEnd", e => {
* e.afterAdded.forEach(el => {
* el.classList.add("selected");
* });
* e.afterRemoved.forEach(el => {
* el.classList.remove("selected");
* });
* });
*/
this.trigger("selectStart", {
selected: selectedTargets,
added: added.map(index => list[index]),
removed: removed.map(index => prevList[index]),
rect,
inputEvent,
});
}
if (added.length || removed.length) {
/**
* When the select in real time, the select event is called.
* @memberof Selecto
* @event select
* @param {Selecto.OnSelect} - Parameters for the select event
* @example
* import Selecto from "selecto";
*
* const selecto = new Selecto({
* container: document.body,
* selectByClick: true,
* selectFromInside: false,
* });
*
* selecto.on("select", e => {
* e.added.forEach(el => {
* el.classList.add("selected");
* });
* e.removed.forEach(el => {
* el.classList.remove("selected");
* });
* });
*/
this.trigger("select", {
selected: selectedTargets,
added: added.map(index => list[index]),
removed: removed.map(index => prevList[index]),
rect,
inputEvent,
});
}
}
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
MethodDeclaration
|
private selectEnd(
startSelectedTargets: Array<HTMLElement | SVGElement>,
selectedTargets: Array<HTMLElement | SVGElement>,
rect: Rect,
e: OnDragEvent,
) {
const { inputEvent, isDouble } = e;
const {
added,
removed,
prevList,
list,
} = diff(startSelectedTargets, selectedTargets);
const {
added: afterAdded,
removed: afterRemoved,
prevList: afterPrevList,
list: afterList,
} = diff(this.selectedTargets, selectedTargets);
const type = inputEvent.type;
const isDragStart = type === "mousedown" || type === "touchstart";
/**
* When the select(dragEnd or click) ends, the selectEnd event is called.
* @memberof Selecto
* @event selectEnd
* @param {Selecto.OnSelectEnd} - Parameters for the selectEnd event
* @example
* import Selecto from "selecto";
*
* const selecto = new Selecto({
* container: document.body,
* selectByClick: true,
* selectFromInside: false,
* });
*
* selecto.on("selectStart", e => {
* e.added.forEach(el => {
* el.classList.add("selected");
* });
* e.removed.forEach(el => {
* el.classList.remove("selected");
* });
* }).on("selectEnd", e => {
* e.afterAdded.forEach(el => {
* el.classList.add("selected");
* });
* e.afterRemoved.forEach(el => {
* el.classList.remove("selected");
* });
* });
*/
this.trigger("selectEnd", {
selected: selectedTargets,
added: added.map(index => list[index]),
removed: removed.map(index => prevList[index]),
afterAdded: afterAdded.map(index => afterList[index]),
afterRemoved: afterRemoved.map(index => afterPrevList[index]),
isDragStart,
isDouble: !!isDouble,
rect,
inputEvent,
});
}
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
MethodDeclaration
|
private check(e: any) {
const {
datas,
inputEvent,
} = e;
const rect = getRect(e);
const {
top,
left,
width,
height,
} = rect;
this.target.style.cssText
+= `display: block;`
+ `left:0px;top:0px;`
+ `transform: translate(${left}px, ${top}px);`
+ `width:${width}px;height:${height}px;`;
const passedTargets = this.hitTest(
rect, datas.startX, datas.startY, datas.selectableTargets, datas.selectableRects);
const selectedTargets = this.getSelectedTargets(passedTargets);
this.trigger("drag", {
...e,
rect,
});
this.select(selectedTargets, rect, inputEvent);
datas.selectedTargets = selectedTargets;
}
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
MethodDeclaration
|
private sameCombiKey(e: any) {
const toggleContinueSelect = [].concat(this.options.toggleContinueSelect);
const combi = getCombi(e.inputEvent, e.key);
return toggleContinueSelect.every(key => combi.indexOf(key) > -1);
}
|
sibbngheid/selecto
|
src/Selecto.tsx
|
TypeScript
|
ClassDeclaration
|
@NgModule({
imports: [CommonModule, FormsModule, IonicModule, MyViewPerDiemPageRoutingModule, MatIconModule, SharedModule],
declarations: [MyViewPerDiemPage],
})
export class MyViewPerDiemPageModule {}
|
Aaditya-Dhanraj/fyle-mobile-app2
|
src/app/fyle/my-view-per-diem/my-view-per-diem.module.ts
|
TypeScript
|
ArrowFunction
|
(userId: string) => connection.get(`${table}.${userId}`).value()
|
ABeltramo/discord-soundbot
|
src/util/db/Exits.ts
|
TypeScript
|
ArrowFunction
|
(userId: string) => !!get(userId)
|
ABeltramo/discord-soundbot
|
src/util/db/Exits.ts
|
TypeScript
|
ArrowFunction
|
(userId: string, sound: string) => {
connection.set(`${table}.${userId}`, sound).write();
}
|
ABeltramo/discord-soundbot
|
src/util/db/Exits.ts
|
TypeScript
|
ArrowFunction
|
(userId: string) => {
connection.unset(`${table}.${userId}`).write();
}
|
ABeltramo/discord-soundbot
|
src/util/db/Exits.ts
|
TypeScript
|
ArrowFunction
|
async () => {
try {
const argv = parser(process.argv.slice(2), yarnYargsOpts);
const cacheDir = cachedir('larix');
const registryUrl = await runYarnAndGetLastLine(['config', 'get', 'registry']);
const projectRoot = path.resolve('.');
await checkNewVersion(registryUrl, cacheDir);
if (argv.v) {
console.log(require('../package.json').version);
} else {
if (argv._.length >= 1 && argv._[0] === 'remove') {
const packageNames = argv._.slice(1);
await removePrefabs({ projectRoot, packageNames, registryUrl, cacheDir });
}
await runYarn(process.argv.slice(2));
if (argv._.length === 0 || (argv._.length >= 1 && ['add', 'install'].indexOf(argv._[0]) >= 0 && !argv.v)) {
await addPrefabs({ projectRoot, registryUrl, cacheDir });
}
}
} catch (e) {
console.error(e);
process.exit(1);
}
}
|
Acidburn0zzz/larix
|
packages/larix/src/index.ts
|
TypeScript
|
ArrowFunction
|
() => {
// AbstractControl.eventId(0);
}
|
jorroll/rx-controls
|
projects/rx-controls/src/lib/abstract-control/abstract-control-base-tests.ts
|
TypeScript
|
ArrowFunction
|
() => {
it('defaults', () => {
testAllDefaultsExcept(createControlBase());
});
describe('options', () => {
it('id', () => {
a = createControlBase({ options: { id: 'one' } });
expect(a.id).toEqual('one');
testAllDefaultsExcept(a, 'id');
});
it('data', () => {
a = createControlBase({ options: { data: 'one' } });
expect(a.data).toEqual('one');
testAllDefaultsExcept(a, 'data');
});
it('disabled', () => {
a = createControlBase({ options: { disabled: true } });
expect(a).toImplementObject({
enabled: false,
selfEnabled: false,
disabled: true,
selfDisabled: true,
status: 'DISABLED',
});
testAllDefaultsExcept(
a,
'enabled',
'selfEnabled',
'disabled',
'selfDisabled',
'status'
);
a = createControlBase({ options: { disabled: false } });
testAllDefaultsExcept(a);
});
it('dirty', () => {
a = createControlBase({ options: { dirty: true } });
expect(a).toImplementObject({
dirty: true,
selfDirty: true,
});
testAllDefaultsExcept(a, 'dirty', 'selfDirty');
a = createControlBase({ options: { dirty: false } });
testAllDefaultsExcept(a);
});
it('readonly', () => {
a = createControlBase({ options: { readonly: true } });
expect(a).toImplementObject({
readonly: true,
selfReadonly: true,
});
testAllDefaultsExcept(a, 'readonly', 'selfReadonly');
a = createControlBase({ options: { readonly: false } });
testAllDefaultsExcept(a);
});
it('submitted', () => {
a = createControlBase({ options: { submitted: true } });
expect(a).toImplementObject({
submitted: true,
selfSubmitted: true,
});
testAllDefaultsExcept(a, 'submitted', 'selfSubmitted');
a = createControlBase({ options: { submitted: false } });
testAllDefaultsExcept(a);
});
it('errors', () => {
a = createControlBase({ options: { errors: { anError: true } } });
expect(a).toImplementObject({
errors: { anError: true },
selfErrors: { anError: true },
errorsStore: new Map([[CONTROL_SELF_ID, { anError: true }]]),
valid: false,
selfValid: false,
invalid: true,
selfInvalid: true,
status: 'INVALID',
});
testAllDefaultsExcept(
a,
'errors',
'selfErrors',
'errorsStore',
'valid',
'selfValid',
'invalid',
'selfInvalid',
'status'
);
const errors = new Map([['one', { secondError: true }]]);
a = createControlBase({ options: { errors } });
expect(a).toImplementObject({
errors: errors.get('one'),
selfErrors: errors.get('one'),
errorsStore: errors,
valid: false,
selfValid: false,
invalid: true,
selfInvalid: true,
status: 'INVALID',
});
testAllDefaultsExcept(
a,
'errors',
'selfErrors',
'errorsStore',
'valid',
'selfValid',
'invalid',
'selfInvalid',
'status'
);
a = createControlBase({ options: { errors: null } });
testAllDefaultsExcept(a);
});
it('validator', () => {
let validators:
| ValidatorFn
| ValidatorFn[]
| Map<ControlId, ValidatorFn> = (a) => null;
a = createControlBase({ options: { validators } });
expect(a).toImplementObject({
validator: expect.any(Function),
validatorStore: new Map([[CONTROL_SELF_ID, validators]]),
});
testAllDefaultsExcept(a, 'validator', 'validatorStore');
validators = [() => null, () => ({ error: true })];
a = createControlBase({ options: { validators } });
expect(a).toImplementObject({
validator: expect.any(Function),
validatorStore: new Map([[CONTROL_SELF_ID, expect.any(Function)]]),
valid: false,
selfValid: false,
invalid: true,
selfInvalid: true,
errors: { error: true },
selfErrors: { error: true },
errorsStore: new Map([[CONTROL_SELF_ID, { error: true }]]),
status: 'INVALID',
});
testAllDefaultsExcept(
a,
'validator',
'validatorStore',
'valid',
'selfValid',
'invalid',
'selfInvalid',
'errors',
'selfErrors',
'errorsStore',
'status'
);
const fn1 = (() => null) as ValidatorFn;
const fn2 = (() => ({ error: true })) as ValidatorFn;
validators = new Map([
['one', fn1],
['two', fn2],
]);
a = createControlBase({ options: { validators } });
expect(a).toImplementObject({
validator: expect.any(Function),
validatorStore: new Map([
['one', fn1],
['two', fn2],
]),
valid: false,
selfValid: false,
invalid: true,
selfInvalid: true,
errors: { error: true },
selfErrors: { error: true },
errorsStore: new Map([[CONTROL_SELF_ID, { error: true }]]),
status: 'INVALID',
});
testAllDefaultsExcept(
a,
'validator',
'validatorStore',
'valid',
'selfValid',
'invalid',
'selfInvalid',
'errors',
'selfErrors',
'errorsStore',
'status'
);
a = createControlBase({ options: { validators: null } });
testAllDefaultsExcept(a);
});
it('pending', () => {
a = createControlBase({ options: { pending: true } });
expect(a).toImplementObject({
pending: true,
selfPending: true,
pendingStore: new Set([CONTROL_SELF_ID]),
status: 'PENDING',
});
testAllDefaultsExcept(
a,
'pending',
'selfPending',
'pendingStore',
'status'
);
a = createControlBase({ options: { pending: new Set(['one']) } });
expect(a).toImplementObject({
pending: true,
selfPending: true,
pendingStore: new Set(['one']),
status: 'PENDING',
});
testAllDefaultsExcept(
a,
'pending',
'selfPending',
'pendingStore',
'status'
);
a = createControlBase({ options: { pending: false } });
testAllDefaultsExcept(a);
});
});
}
|
jorroll/rx-controls
|
projects/rx-controls/src/lib/abstract-control/abstract-control-base-tests.ts
|
TypeScript
|
ArrowFunction
|
() => {
testAllDefaultsExcept(createControlBase());
}
|
jorroll/rx-controls
|
projects/rx-controls/src/lib/abstract-control/abstract-control-base-tests.ts
|
TypeScript
|
ArrowFunction
|
() => {
it('id', () => {
a = createControlBase({ options: { id: 'one' } });
expect(a.id).toEqual('one');
testAllDefaultsExcept(a, 'id');
});
it('data', () => {
a = createControlBase({ options: { data: 'one' } });
expect(a.data).toEqual('one');
testAllDefaultsExcept(a, 'data');
});
it('disabled', () => {
a = createControlBase({ options: { disabled: true } });
expect(a).toImplementObject({
enabled: false,
selfEnabled: false,
disabled: true,
selfDisabled: true,
status: 'DISABLED',
});
testAllDefaultsExcept(
a,
'enabled',
'selfEnabled',
'disabled',
'selfDisabled',
'status'
);
a = createControlBase({ options: { disabled: false } });
testAllDefaultsExcept(a);
});
it('dirty', () => {
a = createControlBase({ options: { dirty: true } });
expect(a).toImplementObject({
dirty: true,
selfDirty: true,
});
testAllDefaultsExcept(a, 'dirty', 'selfDirty');
a = createControlBase({ options: { dirty: false } });
testAllDefaultsExcept(a);
});
it('readonly', () => {
a = createControlBase({ options: { readonly: true } });
expect(a).toImplementObject({
readonly: true,
selfReadonly: true,
});
testAllDefaultsExcept(a, 'readonly', 'selfReadonly');
a = createControlBase({ options: { readonly: false } });
testAllDefaultsExcept(a);
});
it('submitted', () => {
a = createControlBase({ options: { submitted: true } });
expect(a).toImplementObject({
submitted: true,
selfSubmitted: true,
});
testAllDefaultsExcept(a, 'submitted', 'selfSubmitted');
a = createControlBase({ options: { submitted: false } });
testAllDefaultsExcept(a);
});
it('errors', () => {
a = createControlBase({ options: { errors: { anError: true } } });
expect(a).toImplementObject({
errors: { anError: true },
selfErrors: { anError: true },
errorsStore: new Map([[CONTROL_SELF_ID, { anError: true }]]),
valid: false,
selfValid: false,
invalid: true,
selfInvalid: true,
status: 'INVALID',
});
testAllDefaultsExcept(
a,
'errors',
'selfErrors',
'errorsStore',
'valid',
'selfValid',
'invalid',
'selfInvalid',
'status'
);
const errors = new Map([['one', { secondError: true }]]);
a = createControlBase({ options: { errors } });
expect(a).toImplementObject({
errors: errors.get('one'),
selfErrors: errors.get('one'),
errorsStore: errors,
valid: false,
selfValid: false,
invalid: true,
selfInvalid: true,
status: 'INVALID',
});
testAllDefaultsExcept(
a,
'errors',
'selfErrors',
'errorsStore',
'valid',
'selfValid',
'invalid',
'selfInvalid',
'status'
);
a = createControlBase({ options: { errors: null } });
testAllDefaultsExcept(a);
});
it('validator', () => {
let validators:
| ValidatorFn
| ValidatorFn[]
| Map<ControlId, ValidatorFn> = (a) => null;
a = createControlBase({ options: { validators } });
expect(a).toImplementObject({
validator: expect.any(Function),
validatorStore: new Map([[CONTROL_SELF_ID, validators]]),
});
testAllDefaultsExcept(a, 'validator', 'validatorStore');
validators = [() => null, () => ({ error: true })];
a = createControlBase({ options: { validators } });
expect(a).toImplementObject({
validator: expect.any(Function),
validatorStore: new Map([[CONTROL_SELF_ID, expect.any(Function)]]),
valid: false,
selfValid: false,
invalid: true,
selfInvalid: true,
errors: { error: true },
selfErrors: { error: true },
errorsStore: new Map([[CONTROL_SELF_ID, { error: true }]]),
status: 'INVALID',
});
testAllDefaultsExcept(
a,
'validator',
'validatorStore',
'valid',
'selfValid',
'invalid',
'selfInvalid',
'errors',
'selfErrors',
'errorsStore',
'status'
);
const fn1 = (() => null) as ValidatorFn;
const fn2 = (() => ({ error: true })) as ValidatorFn;
validators = new Map([
['one', fn1],
['two', fn2],
]);
a = createControlBase({ options: { validators } });
expect(a).toImplementObject({
validator: expect.any(Function),
validatorStore: new Map([
['one', fn1],
['two', fn2],
]),
valid: false,
selfValid: false,
invalid: true,
selfInvalid: true,
errors: { error: true },
selfErrors: { error: true },
errorsStore: new Map([[CONTROL_SELF_ID, { error: true }]]),
status: 'INVALID',
});
testAllDefaultsExcept(
a,
'validator',
'validatorStore',
'valid',
'selfValid',
'invalid',
'selfInvalid',
'errors',
'selfErrors',
'errorsStore',
'status'
);
a = createControlBase({ options: { validators: null } });
testAllDefaultsExcept(a);
});
it('pending', () => {
a = createControlBase({ options: { pending: true } });
expect(a).toImplementObject({
pending: true,
selfPending: true,
pendingStore: new Set([CONTROL_SELF_ID]),
status: 'PENDING',
});
testAllDefaultsExcept(
a,
'pending',
'selfPending',
'pendingStore',
'status'
);
a = createControlBase({ options: { pending: new Set(['one']) } });
expect(a).toImplementObject({
pending: true,
selfPending: true,
pendingStore: new Set(['one']),
status: 'PENDING',
});
testAllDefaultsExcept(
a,
'pending',
'selfPending',
'pendingStore',
'status'
);
a = createControlBase({ options: { pending: false } });
testAllDefaultsExcept(a);
});
}
|
jorroll/rx-controls
|
projects/rx-controls/src/lib/abstract-control/abstract-control-base-tests.ts
|
TypeScript
|
ArrowFunction
|
() => {
a = createControlBase({ options: { id: 'one' } });
expect(a.id).toEqual('one');
testAllDefaultsExcept(a, 'id');
}
|
jorroll/rx-controls
|
projects/rx-controls/src/lib/abstract-control/abstract-control-base-tests.ts
|
TypeScript
|
ArrowFunction
|
() => {
a = createControlBase({ options: { data: 'one' } });
expect(a.data).toEqual('one');
testAllDefaultsExcept(a, 'data');
}
|
jorroll/rx-controls
|
projects/rx-controls/src/lib/abstract-control/abstract-control-base-tests.ts
|
TypeScript
|
ArrowFunction
|
() => {
a = createControlBase({ options: { disabled: true } });
expect(a).toImplementObject({
enabled: false,
selfEnabled: false,
disabled: true,
selfDisabled: true,
status: 'DISABLED',
});
testAllDefaultsExcept(
a,
'enabled',
'selfEnabled',
'disabled',
'selfDisabled',
'status'
);
a = createControlBase({ options: { disabled: false } });
testAllDefaultsExcept(a);
}
|
jorroll/rx-controls
|
projects/rx-controls/src/lib/abstract-control/abstract-control-base-tests.ts
|
TypeScript
|
ArrowFunction
|
() => {
a = createControlBase({ options: { dirty: true } });
expect(a).toImplementObject({
dirty: true,
selfDirty: true,
});
testAllDefaultsExcept(a, 'dirty', 'selfDirty');
a = createControlBase({ options: { dirty: false } });
testAllDefaultsExcept(a);
}
|
jorroll/rx-controls
|
projects/rx-controls/src/lib/abstract-control/abstract-control-base-tests.ts
|
TypeScript
|
ArrowFunction
|
() => {
a = createControlBase({ options: { readonly: true } });
expect(a).toImplementObject({
readonly: true,
selfReadonly: true,
});
testAllDefaultsExcept(a, 'readonly', 'selfReadonly');
a = createControlBase({ options: { readonly: false } });
testAllDefaultsExcept(a);
}
|
jorroll/rx-controls
|
projects/rx-controls/src/lib/abstract-control/abstract-control-base-tests.ts
|
TypeScript
|
ArrowFunction
|
() => {
a = createControlBase({ options: { submitted: true } });
expect(a).toImplementObject({
submitted: true,
selfSubmitted: true,
});
testAllDefaultsExcept(a, 'submitted', 'selfSubmitted');
a = createControlBase({ options: { submitted: false } });
testAllDefaultsExcept(a);
}
|
jorroll/rx-controls
|
projects/rx-controls/src/lib/abstract-control/abstract-control-base-tests.ts
|
TypeScript
|
ArrowFunction
|
() => {
a = createControlBase({ options: { errors: { anError: true } } });
expect(a).toImplementObject({
errors: { anError: true },
selfErrors: { anError: true },
errorsStore: new Map([[CONTROL_SELF_ID, { anError: true }]]),
valid: false,
selfValid: false,
invalid: true,
selfInvalid: true,
status: 'INVALID',
});
testAllDefaultsExcept(
a,
'errors',
'selfErrors',
'errorsStore',
'valid',
'selfValid',
'invalid',
'selfInvalid',
'status'
);
const errors = new Map([['one', { secondError: true }]]);
a = createControlBase({ options: { errors } });
expect(a).toImplementObject({
errors: errors.get('one'),
selfErrors: errors.get('one'),
errorsStore: errors,
valid: false,
selfValid: false,
invalid: true,
selfInvalid: true,
status: 'INVALID',
});
testAllDefaultsExcept(
a,
'errors',
'selfErrors',
'errorsStore',
'valid',
'selfValid',
'invalid',
'selfInvalid',
'status'
);
a = createControlBase({ options: { errors: null } });
testAllDefaultsExcept(a);
}
|
jorroll/rx-controls
|
projects/rx-controls/src/lib/abstract-control/abstract-control-base-tests.ts
|
TypeScript
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.