-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 抽象元素和实例关系管理功能, 防止同一个元素上多次调用同一个指令, 会生成多个anyTouch实例
- Loading branch information
Showing
7 changed files
with
82 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import InstanceManage from '../../src/vueDirective/InstanceManage'; | ||
class ABC { | ||
a: number; | ||
|
||
constructor() { | ||
this.a = 1; | ||
}; | ||
|
||
setA(v: number) { | ||
this.a = v; | ||
} | ||
|
||
getA() { | ||
return this.a; | ||
} | ||
}; | ||
|
||
|
||
const el = document.createElement('div'); | ||
const im = new InstanceManage(ABC); | ||
|
||
test('getInstanceByIndex', () => { | ||
im.getOrCreateInstanceByEl(el); | ||
const instance = im.getInstanceByIndex(0); | ||
expect(instance).toBeDefined(); | ||
expect(instance instanceof ABC).toBeTruthy(); | ||
}); | ||
|
||
test('removeInstanceByIndex', () => { | ||
im.removeInstanceByIndex(0); | ||
expect(im.stock.length).toBe(0); | ||
}); | ||
|
||
test('getIndexByEl, 如果元素存在返回索引, 不存在返回-1', () => { | ||
const index = im.getIndexByEl(el); | ||
expect(index).toBe(-1); | ||
|
||
// 新建 | ||
im.getOrCreateInstanceByEl(el); | ||
expect(im.getIndexByEl(el)).toBe(0); | ||
expect(im.stock.length).toBe(1); | ||
|
||
// get | ||
im.getOrCreateInstanceByEl(el); | ||
expect(im.stock.length).toBe(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters