-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
1,861 additions
and
543 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
src/EventListenersOptionUnstoppableScoped.js → .../EventListenersOptionUnstoppableScoped.js
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,163 @@ | ||
<script> | ||
|
||
function nextTick2(cb) { | ||
let r; | ||
const p = new Promise(function (resolve) { | ||
r = resolve; | ||
}); | ||
setTimeout(function () { | ||
cb(); | ||
setTimeout(function () { | ||
r(); | ||
})//todo i need setTimeout(..., 1) for this to work in ff? | ||
}); //todo i need 1 for this to work in ff? | ||
return p; | ||
} | ||
|
||
function setValue(obj, a, b, value) { | ||
!obj[a] && (obj[a] = {}); | ||
!obj[a][b] && (obj[a][b] = {}); | ||
obj[a][b] = value; | ||
} | ||
|
||
function printResults(results) { | ||
for (let [testName, testResults] of Object.entries(results)) { | ||
const expected = testResults.expected; | ||
delete testResults.expected; | ||
const native = testResults.NATIVE; | ||
for (let [systemName, result] of Object.entries(testResults)) { | ||
if (systemName === "NATIVE") | ||
testResults[systemName] = result === expected ? 1 : result; | ||
else | ||
testResults[systemName] = | ||
(result === expected && result === native) ? null : | ||
(result === expected) ? 1 : | ||
(result === native) ? undefined : | ||
result; | ||
} | ||
} | ||
console.table(results); | ||
} | ||
|
||
async function runTests(eventSystems, tests) { | ||
const results = {}; | ||
for (let [system, reset] of eventSystems) { | ||
system(); | ||
for (const {name: testName, fun, expect} of tests) { | ||
|
||
const expected = expect instanceof Function ? expect() : expect; | ||
setValue(results, testName, "expected", expected); | ||
|
||
let result = []; | ||
fun(result); | ||
await nextTick2(() => 1); //just wait a t1ck, for any queued propagation to complete | ||
setValue(results, testName, system.name, result.join("")); | ||
await nextTick2(() => 1); //just wait a t0ck, for any queued tasks of the propagation to complete | ||
} | ||
reset(); | ||
} | ||
return nextTick2(function () { | ||
printResults(results); | ||
}); | ||
} | ||
</script> | ||
|
||
<script type="module"> | ||
import { | ||
addEventTargetRegistry as addEventTargetRegistry1, | ||
removeEventTargetRegistry as removeEventTargetRegistry1 | ||
} from "./getEventListeners.js"; | ||
import { | ||
addEventTargetRegistry as addEventTargetRegistry2, | ||
removeEventTargetRegistry as removeEventTargetRegistry2 | ||
} from "./getEventListeners_once.js"; | ||
import { | ||
addEventTargetRegistry as addEventTargetRegistry3, | ||
removeEventTargetRegistry as removeEventTargetRegistry3 | ||
} from "./getEventListeners_once_last.js"; | ||
import {addEventTargetRegistry, removeEventTargetRegistry} from "./getEventListeners_once_last_first.js"; | ||
import { | ||
addEventListenerOptionScopedUnstoppable, | ||
removeEventListenerOptionScopedUnstoppable | ||
} from "./EventListenersOptionUnstoppableScoped.js"; | ||
import {addEventIsStoppedScoped, removeEventIsStoppedScoped} from "./ScopedStopPropagation.js"; | ||
import { | ||
addGetEventListeners_allOptions, | ||
removeGetEventListeners_allOptions | ||
} from "./getEventListeners_allOptions.js" | ||
|
||
/** | ||
* @param byDefault, if true, then all events are isScoped=true by default/globally | ||
*/ | ||
function NATIVE() { | ||
} | ||
|
||
function REGISTER_once_last_first() {//once, last, first | ||
window.getEventListeners = addEventTargetRegistry(); | ||
} | ||
|
||
function REGISTER_no_options() { | ||
window.getEventListeners = addEventTargetRegistry1(); | ||
} | ||
|
||
function REGISTER_once() { | ||
window.getEventListeners = addEventTargetRegistry2(); | ||
} | ||
|
||
function REGISTER_once_last() { | ||
window.getEventListeners = addEventTargetRegistry3(); | ||
} | ||
|
||
function SCOPED_STOP(byDefault) { | ||
const isStopped = addEventIsStoppedScoped(); | ||
addEventListenerOptionScopedUnstoppable(isStopped); | ||
byDefault && Object.defineProperty(Event.prototype, "isScoped", {value: true}); | ||
} | ||
|
||
function REMOVE_SCOPED_STOP() { | ||
Object.defineProperty(Event.prototype, "isScoped", {value: undefined}); | ||
removeEventListenerOptionScopedUnstoppable(); | ||
removeEventIsStoppedScoped(); | ||
} | ||
|
||
function SCOPED_STOP_REGISTER() { | ||
window.getEventListeners = addGetEventListeners_allOptions(); | ||
} | ||
|
||
const registers = [ | ||
[REGISTER_once_last_first, removeEventTargetRegistry], | ||
[REGISTER_no_options, removeEventTargetRegistry1], | ||
[REGISTER_once, removeEventTargetRegistry2], | ||
[REGISTER_once_last, removeEventTargetRegistry3] | ||
]; | ||
|
||
const eventSystems = [ | ||
[NATIVE, NATIVE], | ||
[REGISTER_once_last_first, removeEventTargetRegistry], | ||
[SCOPED_STOP, REMOVE_SCOPED_STOP], | ||
[SCOPED_STOP_REGISTER, removeGetEventListeners_allOptions] | ||
]; | ||
|
||
import {testBasic} from "./unitTests/testBasic.js"; | ||
import {dynamicTest} from "./unitTests/testDynamic.js"; | ||
import {testRegistry} from "./unitTests/testRegistry.js"; | ||
import {testOnce} from "./unitTests/testOnce.js"; | ||
import {lastTest, lastErrorsTest, last2} from "./unitTests/testLast.js"; | ||
import {firstTest, firstErrorsTest, first2} from "./unitTests/testFirst.js"; | ||
|
||
(async function () { | ||
await runTests(eventSystems, testBasic); | ||
await runTests(eventSystems, dynamicTest); | ||
await runTests(registers, testRegistry); | ||
await runTests(eventSystems, testOnce); | ||
await runTests(eventSystems, lastTest); | ||
await runTests(eventSystems, last2); | ||
await runTests(eventSystems, lastErrorsTest); | ||
await runTests(eventSystems, firstTest); | ||
await runTests(eventSystems, first2); | ||
await runTests(eventSystems, firstErrorsTest); | ||
// // await runTests(eventSystems, testIsStopped); | ||
})(); | ||
//todo | ||
// 1. test stopPropagation thoroughly | ||
</script> |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
Oops, something went wrong.