本文整理匯總了TypeScript中@phosphor/algorithm.ArrayExt.findFirstIndex方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript ArrayExt.findFirstIndex方法的具體用法?TypeScript ArrayExt.findFirstIndex怎麽用?TypeScript ArrayExt.findFirstIndex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@phosphor/algorithm.ArrayExt
的用法示例。
在下文中一共展示了ArrayExt.findFirstIndex方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: it
it('should remove a group from the menu', () => {
const group1 = [ { command: 'run1'}, { command: 'run2' }];
const group2 = [ { command: 'run3'}, { command: 'run4' }];
menu.addGroup(group1);
menu.addGroup(group2);
menu.removeGroup(group1);
let idx1 = ArrayExt.findFirstIndex(menu.menu.items,
m => m.command === 'run1');
let idx2 = ArrayExt.findFirstIndex(menu.menu.items,
m => m.command === 'run2');
let idx3 = ArrayExt.findFirstIndex(menu.menu.items,
m => m.command === 'run3');
let idx4 = ArrayExt.findFirstIndex(menu.menu.items,
m => m.command === 'run4');
expect(idx1).to.be(-1);
expect(idx2).to.be(-1);
expect(idx3 === -1).to.be(false);
expect(idx4 === -1).to.be(false);
});
示例2: _evtDragEnter
/**
* Handle the `'p-dragenter'` event for the widget.
*/
private _evtDragEnter(event: IDragEvent): void {
if (event.mimeData.hasData(CONTENTS_MIME)) {
let index = ArrayExt.findFirstIndex(this._crumbs, node => ElementExt.hitTest(node, event.clientX, event.clientY));
if (index !== -1) {
if (index !== Private.Crumb.Current) {
this._crumbs[index].classList.add(DROP_TARGET_CLASS);
event.preventDefault();
event.stopPropagation();
}
}
}
}
示例3: _evtDragOver
/**
* Handle the `'p-dragover'` event for the widget.
*/
private _evtDragOver(event: IDragEvent): void {
event.preventDefault();
event.stopPropagation();
event.dropAction = event.proposedAction;
let dropTarget = DOMUtils.findElement(this.node, DROP_TARGET_CLASS);
if (dropTarget) {
dropTarget.classList.remove(DROP_TARGET_CLASS);
}
let index = ArrayExt.findFirstIndex(this._crumbs, node => ElementExt.hitTest(node, event.clientX, event.clientY));
if (index !== -1) {
this._crumbs[index].classList.add(DROP_TARGET_CLASS);
}
}
示例4: it
it('should take a rank as an option', () => {
menu.addGroup([{ command: 'run1' }, { command: 'run2' }], 2);
menu.addGroup([{ command: 'run3' }, { command: 'run4' }], 1);
const idx1 = ArrayExt.findFirstIndex(
menu.menu.items,
m => m.command === 'run1'
);
const idx2 = ArrayExt.findFirstIndex(
menu.menu.items,
m => m.command === 'run2'
);
const idx3 = ArrayExt.findFirstIndex(
menu.menu.items,
m => m.command === 'run3'
);
const idx4 = ArrayExt.findFirstIndex(
menu.menu.items,
m => m.command === 'run4'
);
expect(idx3 < idx4).to.equal(true);
expect(idx4 < idx1).to.equal(true);
expect(idx1 < idx2).to.equal(true);
});
示例5: _evtDrop
/**
* Handle the `'p-drop'` event for the widget.
*/
private _evtDrop(event: IDragEvent): void {
event.preventDefault();
event.stopPropagation();
if (event.proposedAction === 'none') {
event.dropAction = 'none';
return;
}
if (!event.mimeData.hasData(CONTENTS_MIME)) {
return;
}
event.dropAction = event.proposedAction;
let target = event.target as HTMLElement;
while (target && target.parentElement) {
if (target.classList.contains(DROP_TARGET_CLASS)) {
target.classList.remove(DROP_TARGET_CLASS);
break;
}
target = target.parentElement;
}
// Get the path based on the target node.
let index = ArrayExt.findFirstIndex(this._crumbs, node => node === target);
if (index === -1) {
return;
}
const model = this._model;
const path = PathExt.resolve(model.path, BREAD_CRUMB_PATHS[index]);
const manager = model.manager;
// Move all of the items.
let promises: Promise<any>[] = [];
let oldPaths = event.mimeData.getData(CONTENTS_MIME) as string[];
for (let oldPath of oldPaths) {
let localOldPath = manager.services.contents.localPath(oldPath);
let name = PathExt.basename(localOldPath);
let newPath = PathExt.join(path, name);
promises.push(renameFile(manager, oldPath, newPath));
}
Promise.all(promises).catch(err => {
showErrorMessage('Move Error', err);
});
}
示例6: _evtClick
/**
* Handle the `'click'` event for the widget.
*/
private _evtClick(event: MouseEvent): void {
// Do nothing if it's not a left mouse press.
if (event.button !== 0) {
return;
}
// Find a valid click target.
let node = event.target as HTMLElement;
while (node && node !== this.node) {
if (node.classList.contains(BREADCRUMB_ITEM_CLASS)) {
let index = ArrayExt.findFirstIndex(this._crumbs, value => value === node);
this._model.cd(BREAD_CRUMB_PATHS[index]).catch(error =>
utils.showErrorMessage('Open Error', error)
);
// Stop the event propagation.
event.preventDefault();
event.stopPropagation();
return;
}
node = node.parentElement as HTMLElement;
}
}
示例7: it
it('should wrap around if stop < start', () => {
let data = [1, 2, 3, 4, 5];
let i = ArrayExt.findFirstIndex(data, v => v % 2 === 0, 4, 2);
expect(i).to.equal(1);
});