Grabbed dndbeyond's source code
``` ~/go/bin/sourcemapper -output ddb -jsurl https://media.dndbeyond.com/character-app/static/js/main.90aa78c5.js ```
This commit is contained in:
+126
@@ -0,0 +1,126 @@
|
||||
import { getBatch } from './batch'; // encapsulates the subscription logic for connecting a component to the redux store, as
|
||||
// well as nesting subscriptions of descendant components, so that we can ensure the
|
||||
// ancestor components re-render before descendants
|
||||
|
||||
function createListenerCollection() {
|
||||
var batch = getBatch();
|
||||
var first = null;
|
||||
var last = null;
|
||||
return {
|
||||
clear: function clear() {
|
||||
first = null;
|
||||
last = null;
|
||||
},
|
||||
notify: function notify() {
|
||||
batch(function () {
|
||||
var listener = first;
|
||||
|
||||
while (listener) {
|
||||
listener.callback();
|
||||
listener = listener.next;
|
||||
}
|
||||
});
|
||||
},
|
||||
get: function get() {
|
||||
var listeners = [];
|
||||
var listener = first;
|
||||
|
||||
while (listener) {
|
||||
listeners.push(listener);
|
||||
listener = listener.next;
|
||||
}
|
||||
|
||||
return listeners;
|
||||
},
|
||||
subscribe: function subscribe(callback) {
|
||||
var isSubscribed = true;
|
||||
var listener = last = {
|
||||
callback: callback,
|
||||
next: null,
|
||||
prev: last
|
||||
};
|
||||
|
||||
if (listener.prev) {
|
||||
listener.prev.next = listener;
|
||||
} else {
|
||||
first = listener;
|
||||
}
|
||||
|
||||
return function unsubscribe() {
|
||||
if (!isSubscribed || first === null) return;
|
||||
isSubscribed = false;
|
||||
|
||||
if (listener.next) {
|
||||
listener.next.prev = listener.prev;
|
||||
} else {
|
||||
last = listener.prev;
|
||||
}
|
||||
|
||||
if (listener.prev) {
|
||||
listener.prev.next = listener.next;
|
||||
} else {
|
||||
first = listener.next;
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
var nullListeners = {
|
||||
notify: function notify() {},
|
||||
get: function get() {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
export function createSubscription(store, parentSub) {
|
||||
var unsubscribe;
|
||||
var listeners = nullListeners;
|
||||
|
||||
function addNestedSub(listener) {
|
||||
trySubscribe();
|
||||
return listeners.subscribe(listener);
|
||||
}
|
||||
|
||||
function notifyNestedSubs() {
|
||||
listeners.notify();
|
||||
}
|
||||
|
||||
function handleChangeWrapper() {
|
||||
if (subscription.onStateChange) {
|
||||
subscription.onStateChange();
|
||||
}
|
||||
}
|
||||
|
||||
function isSubscribed() {
|
||||
return Boolean(unsubscribe);
|
||||
}
|
||||
|
||||
function trySubscribe() {
|
||||
if (!unsubscribe) {
|
||||
unsubscribe = parentSub ? parentSub.addNestedSub(handleChangeWrapper) : store.subscribe(handleChangeWrapper);
|
||||
listeners = createListenerCollection();
|
||||
}
|
||||
}
|
||||
|
||||
function tryUnsubscribe() {
|
||||
if (unsubscribe) {
|
||||
unsubscribe();
|
||||
unsubscribe = undefined;
|
||||
listeners.clear();
|
||||
listeners = nullListeners;
|
||||
}
|
||||
}
|
||||
|
||||
var subscription = {
|
||||
addNestedSub: addNestedSub,
|
||||
notifyNestedSubs: notifyNestedSubs,
|
||||
handleChangeWrapper: handleChangeWrapper,
|
||||
isSubscribed: isSubscribed,
|
||||
trySubscribe: trySubscribe,
|
||||
tryUnsubscribe: tryUnsubscribe,
|
||||
getListeners: function getListeners() {
|
||||
return listeners;
|
||||
}
|
||||
};
|
||||
return subscription;
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// Default to a dummy "batch" implementation that just runs the callback
|
||||
function defaultNoopBatch(callback) {
|
||||
callback();
|
||||
}
|
||||
|
||||
var batch = defaultNoopBatch; // Allow injecting another batching function later
|
||||
|
||||
export var setBatch = function setBatch(newBatch) {
|
||||
return batch = newBatch;
|
||||
}; // Supply a getter just to skip dealing with ESM bindings
|
||||
|
||||
export var getBatch = function getBatch() {
|
||||
return batch;
|
||||
};
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
export default function bindActionCreators(actionCreators, dispatch) {
|
||||
var boundActionCreators = {};
|
||||
|
||||
var _loop = function _loop(key) {
|
||||
var actionCreator = actionCreators[key];
|
||||
|
||||
if (typeof actionCreator === 'function') {
|
||||
boundActionCreators[key] = function () {
|
||||
return dispatch(actionCreator.apply(void 0, arguments));
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
for (var key in actionCreators) {
|
||||
_loop(key);
|
||||
}
|
||||
|
||||
return boundActionCreators;
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
function is(x, y) {
|
||||
if (x === y) {
|
||||
return x !== 0 || y !== 0 || 1 / x === 1 / y;
|
||||
} else {
|
||||
return x !== x && y !== y;
|
||||
}
|
||||
}
|
||||
|
||||
export default function shallowEqual(objA, objB) {
|
||||
if (is(objA, objB)) return true;
|
||||
|
||||
if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var keysA = Object.keys(objA);
|
||||
var keysB = Object.keys(objB);
|
||||
if (keysA.length !== keysB.length) return false;
|
||||
|
||||
for (var i = 0; i < keysA.length; i++) {
|
||||
if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !is(objA[keysA[i]], objB[keysA[i]])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
import { useEffect, useLayoutEffect } from 'react'; // React currently throws a warning when using useLayoutEffect on the server.
|
||||
// To get around it, we can conditionally useEffect on the server (no-op) and
|
||||
// useLayoutEffect in the browser. We need useLayoutEffect to ensure the store
|
||||
// subscription callback always has the selector from the latest render commit
|
||||
// available, otherwise a store update may happen between render and the effect,
|
||||
// which may cause missed updates; we also must ensure the store subscription
|
||||
// is created synchronously, otherwise a store update may occur before the
|
||||
// subscription is created and an inconsistent state may be observed
|
||||
|
||||
export var useIsomorphicLayoutEffect = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined' ? useLayoutEffect : useEffect;
|
||||
Reference in New Issue
Block a user