Skip to content

Instantly share code, notes, and snippets.

@zerobias
Created February 26, 2020 15:43
Show Gist options
  • Save zerobias/0679f7aaa097a3cef9dc097d7e369cfd to your computer and use it in GitHub Desktop.
Save zerobias/0679f7aaa097a3cef9dc097d7e369cfd to your computer and use it in GitHub Desktop.
parcel 2 dynamic import

parcel 2 dynamic import

source files

index.ts

import {run} from './foo'

run().then(console.log)

foo.ts

export const run = () => import('./bar')

bar.ts

import {x} from './baz'

export const xString = x.map(x => x.toString())

baz.ts

import {createStore} from 'effector'
export const x = createStore(0)
parcelRequire.registerBundle('e1095da0325446888ed16378b7e22c16', function() {
var e =
'undefined' != typeof globalThis
? globalThis
: 'undefined' != typeof self
? self
: 'undefined' != typeof window
? window
: 'undefined' != typeof global
? global
: {}
var t = function() {
var t = {exports: this}
this.__esModule = !0
var r = (function(e) {
var t,
r = e.Symbol
return (
'function' == typeof r
? r.observable
? (t = r.observable)
: ((t = r('observable')), (r.observable = t))
: (t = '@@observable'),
t
)
})(
'undefined' != typeof self
? self
: 'undefined' != typeof window
? window
: void 0 !== e
? e
: void 0 !== t
? t
: Function('return this')(),
)
return (this.default = r), t.exports
}.call({})
function r({
node: e = [],
from: t,
source: r,
parent: n = t || r,
to: s,
target: a,
child: o = s || a,
scope: i = {},
meta: l = {},
family: c = {type: 'regular'},
}) {
const f = J(n),
p = J(c.links),
h = J(c.owners),
m = [],
b = {}
for (let t = 0; t < e.length; t++) {
const r = e[t]
r && (m.push(r), K(r, b))
}
const g = {
seq: m,
next: J(o),
meta: l,
scope: i,
family: {type: c.type || 'crosslink', links: p, owners: h},
reg: b,
}
for (let e = 0; e < p.length; e++) u(p[e]).push(g)
for (let e = 0; e < h.length; e++) d(h[e]).push(g)
for (let e = 0; e < f.length; e++) f[e].next.push(g)
return g
}
var n,
s = (n = t) && n.__esModule ? n.default : n
function a(e, t) {
const n = (e, ...t) => n.create(e, t, t)
return (
(n.graphite = r({meta: he('event', n, t, e)})),
(n.create = e => (te(n, e), e)),
(n.watch = q(ue, n)),
(n.map = e => {
let t, r
g(e) && ((t = e), (r = e.name), (e = e.fn))
const s = a(oe(n, r), t)
return be(n, s, 'map', e), s
}),
(n.filter = e =>
v(e)
? (console.error('.filter(fn) is deprecated, use .filterMap instead'),
o(n, e))
: ge(n, 'filter', e.fn, [T({fn: G})])),
(n.filterMap = q(o, n)),
(n.prepend = e => {
const t = a('* → ' + n.shortName, {parent: n.parent})
return be(t, n, 'prepend', e), de(n, t), t
}),
(n.subscribe = e => ue(n, t => e.next(t))),
(n[s] = () => n),
ce(n)
)
}
function o(e, t) {
return ge(e, 'filterMap', t, [O({fn: G}), E.defined()])
}
function i(e, t) {
const n = C(e),
a = C(e),
o = me('updates'),
f = {
subscribers: new Map(),
updates: o,
defaultState: e,
stateRef: n,
getState: q(D, n),
setState(e) {
te({target: f, params: e, defer: 1})
},
}
if (
((f.graphite = r({
scope: {state: n},
node: [
E.defined(),
B({store: n}),
E.changed({store: a}),
B({store: a}),
],
child: o,
meta: he('store', f, t),
})),
pe && void 0 === e)
)
throw Error("current state can't be undefined, use null instead")
return (
(f.watch = f.subscribe = q(c, f)),
(f.reset = (...e) => {
for (const t of e) f.on(t, () => f.defaultState)
return f
}),
(f.on = (e, t) => (
f.off(e), f.subscribers.set(e, ie(ve(e, f, 'on', 1, t))), f
)),
(f.off = q(l, f)),
(f.map = (e, t) => {
let r, n, s
g(e) && ((r = e), (n = e.name), (t = e.firstState), (e = e.fn))
const a = f.getState()
void 0 !== a && (s = e(a, t))
const o = i(s, {name: oe(f, n), config: r, strict: 0})
return ve(f, o, 'map', 0, e), o
}),
(f[s] = () => ({
subscribe: e => (
y(e),
c(f, t => {
e.next && e.next(t)
})
),
[s]() {
return this
},
})),
H(f, [o]),
ce(f)
)
}
function l(e, t) {
const r = e.subscribers.get(t)
return void 0 !== r && (r(), e.subscribers.delete(t)), e
}
function c(e, t, r) {
if (!r || !p(t)) {
if (!v(t)) throw Error('watch requires function handler')
return t(e.getState()), ue(e, t)
}
if (!v(r)) throw Error('second argument should be a function')
return t.watch(t => r(e.getState(), t))
}
const f = e => e.graphite || e,
u = e => e.family.owners,
d = e => e.family.links,
p = e => (v(e) || g(e)) && 'kind' in e,
h = e => t => p(t) && t.kind === e,
m = h('store'),
b = (h('event'), h('effect'), h('domain')),
g = e => 'object' == typeof e && null !== e,
v = e => 'function' == typeof e,
y = e => {
if (!g(e) && !v(e)) throw Error('expect value to be an object')
},
k = (e, t) => {
const r = e.indexOf(t)
;-1 !== r && e.splice(r, 1)
},
w = (e, t) => {
k(e.next, t), k(u(e), t), k(d(e), t)
},
x = (e, t, r) => {
let n
;(e.next.length = 0), (e.seq.length = 0), (e.scope = null)
let s = d(e)
for (; (n = s.pop()); )
w(n, e),
(t || (r && !e.meta.sample) || 'crosslink' === n.family.type) &&
x(n, t, r)
for (s = u(e); (n = s.pop()); )
w(n, e), r && 'crosslink' === n.family.type && x(n, t, r)
},
S = e => e.clear(),
N = (e, {deep: t} = {}) => {
let r = 0
if (m(e)) S(e.subscribers)
else if (b(e)) {
r = 1
const t = e.history
S(t.events), S(t.effects), S(t.stores), S(t.domains)
}
x(f(e), !!t, r)
},
z = () => {
let e = 0
return () => (++e).toString(36)
},
M = z(),
_ = z(),
q = (e, t) => e.bind(null, t),
A = (e, t, r) => e.bind(null, t, r),
R = (e, t, r) => ({id: _(), type: e, data: r, hasRef: t}),
j = ({
from: e = 'store',
store: t,
target: r,
to: n = r ? 'store' : 'stack',
}) => R('mov', 'store' === e, {from: e, store: t, to: n, target: r}),
E = {
defined: () => R('check', 0, {type: 'defined'}),
changed: ({store: e}) => R('check', 1, {type: 'changed', store: e}),
},
O = A(R, 'compute', 0),
T = A(R, 'filter', 0),
P = A(R, 'run', 0),
B = ({store: e}) => j({from: 'stack', target: e}),
C = e => ({id: _(), current: e}),
D = ({current: e}) => e,
F = (e, {fn: t}, {a: r}) => t(e, r),
I = (e, {fn: t}, {a: r}) => t(r, e),
G = (e, {fn: t}) => t(e),
H = (e, t) => {
const r = f(e)
for (let e = 0; e < t.length; e++) {
const n = f(t[e])
'domain' !== r.family.type && (n.family.type = 'crosslink'),
u(n).push(r),
d(r).push(n)
}
},
J = (e = []) => {
const t = []
if (Array.isArray(e))
for (let r = 0; r < e.length; r++)
Array.isArray(e[r]) ? t.push(...e[r]) : t.push(e[r])
else t.push(e)
return t.map(f)
},
K = ({hasRef: e, type: t, data: r}, n) => {
let s
e && ((s = r.store), (n[s.id] = s)),
'mov' === t && 'store' === r.to && ((s = r.target), (n[s.id] = s))
}
let L = null
const Q = (e, t) => {
if (!e) return t
if (!t) return e
let r
const n = e.v.type === t.v.type
return (
((n && e.v.id > t.v.id) || (!n && 'sampler' === e.v.type)) &&
((r = e), (e = t), (t = r)),
(r = Q(e.r, t)),
(e.r = e.l),
(e.l = r),
e
)
},
U = []
let V = 0
for (; V < 5; ) U.push({first: null, last: null, size: 0}), (V += 1)
const W = () => {
for (let e = 0; e < 5; e++) {
const t = U[e]
if (t.size > 0) {
if (2 === e || 3 === e) {
t.size -= 1
const e = L.v
return (L = Q(L.l, L.r)), e
}
1 === t.size && (t.last = null)
const r = t.first
return (t.first = r.right), (t.size -= 1), r.value
}
}
},
X = (e, t, r, n) =>
Y(0, {a: null, b: null, node: t, parent: r, value: n}, e),
Y = (e, t, r, n = 0) => {
const s = Z(r),
a = U[s],
o = {idx: e, stack: t, type: r, id: n}
if (2 === s || 3 === s) L = Q(L, {v: o, l: 0, r: 0})
else {
const e = {right: null, value: o}
0 === a.size ? (a.first = e) : (a.last.right = e), (a.last = e)
}
a.size += 1
},
Z = e => {
switch (e) {
case 'child':
return 0
case 'pure':
return 1
case 'barrier':
return 2
case 'sampler':
return 3
case 'effect':
return 4
default:
return -1
}
},
$ = new Set()
let ee = 0
const te = (e, t, r) => {
if (
(e.target && ((t = e.params), (r = e.defer), (e = e.target)),
Array.isArray(e))
)
for (let r = 0; r < e.length; r++) X('pure', f(e[r]), null, t[r])
else X('pure', f(e), null, t)
;(r && ee) ||
(() => {
const e = ee
ee = 1
const t = {stop: 0}
let r, n
e: for (; (n = W()); ) {
const {idx: e, stack: s, type: a} = n
r = s.node
const o = {skip: 0, fail: 0, ref: '', scope: r.scope}
for (let n = e; n < r.seq.length && !t.stop; n++) {
const i = r.seq[n],
l = i.data
switch (i.type) {
case 'barrier': {
const t = l.barrierID,
r = l.priority
if (n !== e || a !== r) {
$.has(t) || ($.add(t), Y(n, s, r, t))
continue e
}
$.delete(t)
break
}
case 'mov': {
let e
switch (l.from) {
case 'stack':
e = s.value
break
case 'a':
e = s.a
break
case 'b':
e = s.b
break
case 'value':
e = l.store
break
case 'store':
e = D(r.reg[l.store.id])
}
switch (l.to) {
case 'stack':
s.value = e
break
case 'a':
s.a = e
break
case 'b':
s.b = e
break
case 'store':
r.reg[l.target.id].current = e
}
break
}
case 'check':
switch (l.type) {
case 'defined':
o.skip = void 0 === s.value
break
case 'changed':
o.skip = s.value === D(r.reg[l.store.id])
}
break
case 'filter':
o.skip = !re(o, l, s)
break
case 'run':
if (n !== e || 'effect' !== a) {
Y(n, s, 'effect')
continue e
}
case 'compute':
s.value = re(o, l, s)
}
t.stop = o.fail || o.skip
}
if (!t.stop)
for (let e = 0; e < r.next.length; e++)
X('child', r.next[e], s, s.value)
t.stop = 0
}
ee = e
})()
},
re = (e, {fn: t}, r) => {
try {
return t(r.value, e.scope, r)
} catch (t) {
console.error(t), (e.fail = 1)
}
},
ne = (e, t = {}) => (
g(e) &&
(ne(e.config, t),
null != e.name && (g(e.name) ? ne(e.name, t) : (t.name = e.name)),
e.loc && (t.loc = e.loc),
e.sid && (t.sid = e.sid),
e.handler && (t.handler = e.handler),
e.parent && (t.parent = e.parent),
'strict' in e && (t.strict = e.strict),
e.named && (t.named = e.named),
ne(e.ɔ, t)),
t
),
se = ne,
ae = (e, t) => '' + e.shortName + t,
oe = (e, t) => (null == t ? ae(e, ' → *') : t),
ie = e => {
const t = A(N, e, void 0)
return (t.unsubscribe = t), t
},
le = (e, t, {node: n, scope: s, meta: a}) =>
r({
node: n,
parent: e,
child: t,
scope: s,
meta: a,
family: {owners: [e, t], links: t},
}),
ce = e => (fe && H(fe.value, [e]), e)
let fe = null
const ue = (e, t) =>
ie(
ce(
r({
scope: {fn: t},
node: [P({fn: G})],
parent: e,
meta: {op: 'watch'},
family: {owners: e},
}),
),
),
de = ({parent: e}, t) => {
e && e.hooks.event(t)
}
let pe
const he = (e, t, r, n) => {
const s = se({name: n, config: r}),
a = M(),
{parent: o = null, sid: i = null, strict: l = 1, named: c = null} = s,
f = c || s.name || ('domain' === e ? '' : a),
u = (function(e, t) {
let r, n, s
const a = e
return (
t
? ((s = t.compositeName),
0 === e.length
? ((r = s.path), (n = s.fullName))
: ((r = s.path.concat([e])),
(n = 0 === s.fullName.length ? e : s.fullName + '/' + e)))
: ((r = 0 === e.length ? [] : [e]), (n = e)),
{shortName: a, fullName: n, path: r}
)
})(f, o)
return (
(t.kind = e),
(t.id = a),
(t.sid = i),
(t.shortName = f),
(t.parent = o),
(t.compositeName = u),
(t.defaultConfig = s),
(t.thru = q(ye, t)),
(t.getType = () => u.fullName),
(pe = l),
{unit: e, name: f, sid: i, named: c}
)
},
me = e => a({named: e}),
be = (e, t, r, n) =>
le(e, t, {scope: {fn: n}, node: [O({fn: G})], meta: {op: r}}),
ge = (e, t, r, n) => {
let s
g(r) && ((s = r), (r = r.fn))
const o = a(ae(e, ' →? *'), s)
return le(e, o, {scope: {fn: r}, node: n, meta: {op: t}}), o
},
ve = (e, {graphite: t, stateRef: r}, n, s, a) =>
le(e, t, {
scope: {fn: a},
node: [
j({store: r, to: 'a'}),
O({fn: s ? I : F}),
E.defined(),
E.changed({store: r}),
B({store: r}),
],
meta: {op: n},
}),
ye = (e, t) => t(e)
r({
node: [
P({
fn({fn: e, value: t}) {
e(t)
},
}),
],
meta: {op: 'fx', fx: 'sidechain'},
})
T({fn: (e, {state: t}) => void 0 !== e && e !== D(t)}), O({fn: e => e})
Object.defineProperty(we, '__esModule', {value: !0})
var ke = void 0
we.x = ke
var we = {}
;(ke = i(0, {
loc: {file: '/src/baz.ts', line: 2, column: 17},
name: 'x',
sid: 'id6umo',
})),
(we.x = ke),
Object.defineProperty(Se, '__esModule', {value: !0})
var xe = void 0
Se.xString = xe
var Se = {}
;(xe = ke.map(e => e.toString())),
(Se.xString = xe),
parcelRequire.register('e1095da0325446888ed16378b7e22c16', Se)
})
!(function() {
var e = {},
r = {},
n =
'undefined' != typeof globalThis
? globalThis
: 'undefined' != typeof self
? self
: 'undefined' != typeof window
? window
: 'undefined' != typeof global
? global
: {}
null == n.parcelRequire &&
((n.parcelRequire = function(n) {
if ((n in r && (r[n](), delete r[n]), n in e)) return e[n]
if ('undefined' != typeof module && 'function' == typeof module.require)
return module.require(n)
var t = new Error("Cannot find module '" + n + "'")
throw ((t.code = 'MODULE_NOT_FOUND'), t)
}),
(n.parcelRequire.register = function(r, n) {
e[r] = n
}),
(n.parcelRequire.registerBundle = function(n, t) {
;(r[n] = t), (e[n] = {})
}))
var t
let o = {}
var u = {}
u = (function(e) {
return function(r) {
return o[r]
? o[r]
: (o[r] = e(r).catch(function(e) {
throw (delete o[r], e)
}))
}
})(function(e) {
return new Promise(function(r, n) {
var t = document.createElement('script')
;(t.async = !0),
(t.type = 'text/javascript'),
(t.charset = 'utf-8'),
(t.src = e),
(t.onerror = function(e) {
;(t.onerror = t.onload = null), n(e)
}),
(t.onload = function() {
;(t.onerror = t.onload = null), r()
}),
document.getElementsByTagName('head')[0].appendChild(t)
})
})
var i = null
;(t = u(
(function() {
return (
i ||
(i = (function() {
try {
throw new Error()
} catch (r) {
var e = ('' + r.stack).match(/(https?|file|ftp):\/\/[^)\n]+/g)
if (e)
return (
('' + e[0]).replace(
/^((?:https?|file|ftp):\/\/.+)\/[^/]+$/,
'$1',
) + '/'
)
}
return '/'
})()),
i
)
})() + 'bar.f12f7610.js',
).then(() => parcelRequire('e1095da0325446888ed16378b7e22c16'))),
Object.defineProperty(c, '__esModule', {value: !0})
var a = void 0
c.run = a
var c = {}
function f() {
if ('function' != typeof WeakMap) return null
var e = new WeakMap()
return (
(f = function() {
return e
}),
e
)
}
;(a = () =>
Promise.resolve()
.then(() => t)
.then(e =>
(function(e) {
if (e && e.__esModule) return e
if (null === e || ('object' != typeof e && 'function' != typeof e))
return {default: e}
var r = f()
if (r && r.has(e)) return r.get(e)
var n = {},
t = Object.defineProperty && Object.getOwnPropertyDescriptor
for (var o in e)
if (Object.prototype.hasOwnProperty.call(e, o)) {
var u = t ? Object.getOwnPropertyDescriptor(e, o) : null
u && (u.get || u.set)
? Object.defineProperty(n, o, u)
: (n[o] = e[o])
}
return (n.default = e), r && r.set(e, n), n
})(e),
)),
(c.run = a),
a().then(console.log),
parcelRequire.register('12c1288c3d59e9d35f0a18e7d703ab2b', {})
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment