Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use initCustomEvent instead of new CustomEvent #2101

Merged
merged 1 commit into from
Feb 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/internal/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,9 @@ export function addResizeListener(element, fn) {
export function toggleClass(element, name, toggle) {
element.classList[toggle ? 'add' : 'remove'](name);
}

export function custom_event(type, detail) {
const e = document.createEvent('CustomEvent');
e.initCustomEvent(type, false, false, detail);
return e;
}
4 changes: 3 additions & 1 deletion src/internal/lifecycle.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { custom_event } from './dom';

export let current_component;

export function set_current_component(component) {
Expand Down Expand Up @@ -34,7 +36,7 @@ export function createEventDispatcher() {
if (callbacks) {
// TODO are there situations where events could be dispatched
// in a server (non-DOM) environment?
const event = new window.CustomEvent(type, { detail });
const event = custom_event(type, detail);
callbacks.slice().forEach(fn => {
fn.call(component, event);
});
Expand Down
7 changes: 4 additions & 3 deletions src/internal/transitions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { identity as linear, noop, run_all } from './utils.js';
import { loop } from './loop.js';
import { create_rule, delete_rule } from './style_manager.js';
import { custom_event } from './dom.js';

let promise;

Expand Down Expand Up @@ -238,14 +239,14 @@ export function create_bidirectional_transition(node, fn, params, intro) {
if (b) tick(0, 1);

running_program = init(program, duration);
node.dispatchEvent(new window.CustomEvent(`${running_program.b ? 'intro' : 'outro'}start`));
node.dispatchEvent(custom_event(`${running_program.b ? 'intro' : 'outro'}start`));

loop(now => {
if (pending_program && now > pending_program.start) {
running_program = init(pending_program, duration);
pending_program = null;

node.dispatchEvent(new window.CustomEvent(`${running_program.b ? 'intro' : 'outro'}start`));
node.dispatchEvent(custom_event(`${running_program.b ? 'intro' : 'outro'}start`));

if (css) {
clear_animation();
Expand All @@ -256,7 +257,7 @@ export function create_bidirectional_transition(node, fn, params, intro) {
if (running_program) {
if (now >= running_program.end) {
tick(t = running_program.b, 1 - t);
node.dispatchEvent(new window.CustomEvent(`${running_program.b ? 'intro' : 'outro'}end`));
node.dispatchEvent(custom_event(`${running_program.b ? 'intro' : 'outro'}end`));

if (!pending_program) {
// we're done
Expand Down