You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
svelte/test/js/samples/window-binding-scroll/expected.js

89 lines
1.9 KiB

/* generated by Svelte vX.Y.Z */
import { SvelteComponent as SvelteComponent_1, add_render_callback, append, createElement, createText, detachNode, flush, init, insert, run, safe_not_equal, setData } from "svelte/internal.js";
function create_fragment(component, ctx) {
var window_updating = false, clear_window_updating = function() { window_updating = false; }, window_updating_timeout, p, text0, text1, current;
window.addEventListener("scroll", ctx.onwindowscroll);
add_render_callback(ctx.onwindowscroll);
component.$on("state", ({ changed, current }) => {
if (changed["y"] && !window_updating) {
window_updating = true;
clearTimeout(window_updating_timeout);
window.scrollTo(window.pageXOffset, current["y"]);
window_updating_timeout = setTimeout(clear_window_updating, 100);
}
});
return {
c() {
p = createElement("p");
text0 = createText("scrolled to ");
text1 = createText(ctx.y);
},
m(target, anchor) {
insert(target, p, anchor);
append(p, text0);
append(p, text1);
current = true;
},
p(changed, ctx) {
if (changed.y) {
setData(text1, ctx.y);
}
},
i(target, anchor) {
if (current) return;
this.m(target, anchor);
},
o: run,
d(detach) {
window.removeEventListener("scroll", ctx.onwindowscroll);
if (detach) {
detachNode(p);
}
}
};
}
function define($$self, $$props, $$make_dirty) {
let { y } = $$props;
function onwindowscroll() {
if (window_updating) return;
window_updating = true;
y = window.pageYOffset; $$make_dirty('y');
window_updating = false;
}
$$self.$$.get = () => ({ y, onwindowscroll });
$$self.$$.set = $$props => {
if ('y' in $$props) y = $$props.y;
};
}
class SvelteComponent extends SvelteComponent_1 {
constructor(options) {
super();
init(this, options, define, create_fragment, safe_not_equal);
}
get y() {
return this.$$.get().y;
}
set y(value) {
this.$set({ y: value });
flush();
}
}
export default SvelteComponent;