Skip to content

Commit

Permalink
Added bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
duart38 committed Aug 3, 2020
1 parent b0e221a commit 06505e3
Showing 1 changed file with 174 additions and 0 deletions.
174 changes: 174 additions & 0 deletions Observe.bundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.

// This is a specialised implementation of a System module loader.

"use strict";

// @ts-nocheck
/* eslint-disable */
let System, __instantiate;
(() => {
const r = new Map();

System = {
register(id, d, f) {
r.set(id, { d, f, exp: {} });
},
};
async function dI(mid, src) {
let id = mid.replace(/\.\w+$/i, "");
if (id.includes("./")) {
const [o, ...ia] = id.split("/").reverse(),
[, ...sa] = src.split("/").reverse(),
oa = [o];
let s = 0,
i;
while ((i = ia.shift())) {
if (i === "..") s++;
else if (i === ".") break;
else oa.push(i);
}
if (s < sa.length) oa.push(...sa.slice(s));
id = oa.reverse().join("/");
}
return r.has(id) ? gExpA(id) : import(mid);
}

function gC(id, main) {
return {
id,
import: (m) => dI(m, id),
meta: { url: id, main },
};
}

function gE(exp) {
return (id, v) => {
v = typeof id === "string" ? { [id]: v } : id;
for (const [id, value] of Object.entries(v)) {
Object.defineProperty(exp, id, {
value,
writable: true,
enumerable: true,
});
}
};
}

function rF(main) {
for (const [id, m] of r.entries()) {
const { f, exp } = m;
const { execute: e, setters: s } = f(gE(exp), gC(id, id === main));
delete m.f;
m.e = e;
m.s = s;
}
}

async function gExpA(id) {
if (!r.has(id)) return;
const m = r.get(id);
if (m.s) {
const { d, e, s } = m;
delete m.s;
delete m.e;
for (let i = 0; i < s.length; i++) s[i](await gExpA(d[i]));
const r = e();
if (r) await r;
}
return m.exp;
}

function gExp(id) {
if (!r.has(id)) return;
const m = r.get(id);
if (m.s) {
const { d, e, s } = m;
delete m.s;
delete m.e;
for (let i = 0; i < s.length; i++) s[i](gExp(d[i]));
e();
}
return m.exp;
}
__instantiate = (m, a) => {
System = __instantiate = undefined;
rF(m);
return a ? gExpA(m) : gExp(m);
};
})();

System.register("Observe", [], function (exports_1, context_1) {
"use strict";
var Observe;
var __moduleName = context_1 && context_1.id;
return {
setters: [],
execute: function () {
Observe = class Observe {
constructor(defaultValue) {
this.history = [];
this.currentEvent = new CustomEvent("");
this.maxHistorySize = 1000;
this.lastNestedBound = () => { };
this.eventID = "Observed_" +
crypto.getRandomValues(new Uint32Array(2)).toString().replace(",", "_");
this.history.push(defaultValue);
if (defaultValue instanceof Observe) {
this.lastNestedBound = defaultValue.bind((d) => this.emit(defaultValue));
}
}
getValue() {
return this.history[this.history.length - 1];
}
getHistory() {
return this.history;
}
bind(callback) {
let func = (e) => callback(e.detail);
addEventListener(this.eventID, func);
return func;
}
unBind(callback) {
removeEventListener(this.eventID, callback);
}
setValue(value) {
if (value !== this.getValue() && !(value instanceof Observe)) {
this.updateHistory(value);
this.emit(value);
}
else if (value instanceof Observe) {
let lh = this.getHistory()[this.history.length - 1];
lh.unBind(this.lastNestedBound);
this.lastNestedBound = value.bind((d) => this.emit(value));
this.updateHistory(value);
this.emit(value);
}
}
updateHistory(value) {
this.history.push(value);
if (this.history.length > this.maxHistorySize) {
this.history.splice(1, 1);
}
}
reset() {
this.setValue(this.getHistory()[0]);
}
emit(value) {
this.currentEvent = new CustomEvent(this.eventID, { detail: value });
const success = dispatchEvent(this.currentEvent);
}
getEventID() {
return this.eventID;
}
stop() {
this.currentEvent.stopImmediatePropagation();
}
};
exports_1("default", Observe);
}
};
});

const __exp = __instantiate("Observe", false);
export default __exp["default"];

0 comments on commit 06505e3

Please sign in to comment.