-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #450 from Tyriar/449_keep_span_pool
Keep row spans in an object pool to reduce garbage collection by reusing DOM nodes
- Loading branch information
Showing
5 changed files
with
235 additions
and
79 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
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,47 @@ | ||
import { assert } from 'chai'; | ||
import { DomElementObjectPool } from './DomElementObjectPool'; | ||
|
||
class MockDocument { | ||
private _attr: {[key: string]: string} = {}; | ||
constructor() {} | ||
public getAttribute(key: string): string { return this._attr[key]; }; | ||
public setAttribute(key: string, value: string): void { this._attr[key] = value; } | ||
} | ||
|
||
describe('DomElementObjectPool', () => { | ||
let pool: DomElementObjectPool; | ||
|
||
beforeEach(() => { | ||
pool = new DomElementObjectPool('span'); | ||
(<any>global).document = { | ||
createElement: () => new MockDocument() | ||
}; | ||
}); | ||
|
||
it('should acquire distinct elements', () => { | ||
const element1 = pool.acquire(); | ||
const element2 = pool.acquire(); | ||
assert.notEqual(element1, element2); | ||
}); | ||
|
||
it('should acquire released elements', () => { | ||
const element = pool.acquire(); | ||
pool.release(element); | ||
assert.equal(pool.acquire(), element); | ||
}); | ||
|
||
it('should handle a series of acquisitions and releases', () => { | ||
const element1 = pool.acquire(); | ||
const element2 = pool.acquire(); | ||
pool.release(element1); | ||
assert.equal(pool.acquire(), element1); | ||
pool.release(element1); | ||
pool.release(element2); | ||
assert.equal(pool.acquire(), element2); | ||
assert.equal(pool.acquire(), element1); | ||
}); | ||
|
||
it('should throw when releasing an element that was not acquired', () => { | ||
assert.throws(() => pool.release(document.createElement('span'))); | ||
}); | ||
}); |
Oops, something went wrong.