[d24f17c] | 1 | var __defProp = Object.defineProperty;
|
---|
| 2 | var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
---|
| 3 | var __hasOwnProp = Object.prototype.hasOwnProperty;
|
---|
| 4 | var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
---|
| 5 | var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
---|
| 6 | var __spreadValues = (a, b) => {
|
---|
| 7 | for (var prop in b || (b = {}))
|
---|
| 8 | if (__hasOwnProp.call(b, prop))
|
---|
| 9 | __defNormalProp(a, prop, b[prop]);
|
---|
| 10 | if (__getOwnPropSymbols)
|
---|
| 11 | for (var prop of __getOwnPropSymbols(b)) {
|
---|
| 12 | if (__propIsEnum.call(b, prop))
|
---|
| 13 | __defNormalProp(a, prop, b[prop]);
|
---|
| 14 | }
|
---|
| 15 | return a;
|
---|
| 16 | };
|
---|
| 17 | var __publicField = (obj, key, value) => {
|
---|
| 18 | __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
---|
| 19 | return value;
|
---|
| 20 | };
|
---|
| 21 |
|
---|
| 22 | // src/devModeChecks/identityFunctionCheck.ts
|
---|
| 23 | var runIdentityFunctionCheck = (resultFunc, inputSelectorsResults, outputSelectorResult) => {
|
---|
| 24 | if (inputSelectorsResults.length === 1 && inputSelectorsResults[0] === outputSelectorResult) {
|
---|
| 25 | let isInputSameAsOutput = false;
|
---|
| 26 | try {
|
---|
| 27 | const emptyObject = {};
|
---|
| 28 | if (resultFunc(emptyObject) === emptyObject)
|
---|
| 29 | isInputSameAsOutput = true;
|
---|
| 30 | } catch (e) {
|
---|
| 31 | }
|
---|
| 32 | if (isInputSameAsOutput) {
|
---|
| 33 | let stack = void 0;
|
---|
| 34 | try {
|
---|
| 35 | throw new Error();
|
---|
| 36 | } catch (e) {
|
---|
| 37 | ;
|
---|
| 38 | ({ stack } = e);
|
---|
| 39 | }
|
---|
| 40 | console.warn(
|
---|
| 41 | "The result function returned its own inputs without modification. e.g\n`createSelector([state => state.todos], todos => todos)`\nThis could lead to inefficient memoization and unnecessary re-renders.\nEnsure transformation logic is in the result function, and extraction logic is in the input selectors.",
|
---|
| 42 | { stack }
|
---|
| 43 | );
|
---|
| 44 | }
|
---|
| 45 | }
|
---|
| 46 | };
|
---|
| 47 |
|
---|
| 48 | // src/devModeChecks/inputStabilityCheck.ts
|
---|
| 49 | var runInputStabilityCheck = (inputSelectorResultsObject, options, inputSelectorArgs) => {
|
---|
| 50 | const { memoize, memoizeOptions } = options;
|
---|
| 51 | const { inputSelectorResults, inputSelectorResultsCopy } = inputSelectorResultsObject;
|
---|
| 52 | const createAnEmptyObject = memoize(() => ({}), ...memoizeOptions);
|
---|
| 53 | const areInputSelectorResultsEqual = createAnEmptyObject.apply(null, inputSelectorResults) === createAnEmptyObject.apply(null, inputSelectorResultsCopy);
|
---|
| 54 | if (!areInputSelectorResultsEqual) {
|
---|
| 55 | let stack = void 0;
|
---|
| 56 | try {
|
---|
| 57 | throw new Error();
|
---|
| 58 | } catch (e) {
|
---|
| 59 | ;
|
---|
| 60 | ({ stack } = e);
|
---|
| 61 | }
|
---|
| 62 | console.warn(
|
---|
| 63 | "An input selector returned a different result when passed same arguments.\nThis means your output selector will likely run more frequently than intended.\nAvoid returning a new reference inside your input selector, e.g.\n`createSelector([state => state.todos.map(todo => todo.id)], todoIds => todoIds.length)`",
|
---|
| 64 | {
|
---|
| 65 | arguments: inputSelectorArgs,
|
---|
| 66 | firstInputs: inputSelectorResults,
|
---|
| 67 | secondInputs: inputSelectorResultsCopy,
|
---|
| 68 | stack
|
---|
| 69 | }
|
---|
| 70 | );
|
---|
| 71 | }
|
---|
| 72 | };
|
---|
| 73 |
|
---|
| 74 | // src/devModeChecks/setGlobalDevModeChecks.ts
|
---|
| 75 | var globalDevModeChecks = {
|
---|
| 76 | inputStabilityCheck: "once",
|
---|
| 77 | identityFunctionCheck: "once"
|
---|
| 78 | };
|
---|
| 79 | var setGlobalDevModeChecks = (devModeChecks) => {
|
---|
| 80 | Object.assign(globalDevModeChecks, devModeChecks);
|
---|
| 81 | };
|
---|
| 82 |
|
---|
| 83 | // src/utils.ts
|
---|
| 84 | var NOT_FOUND = "NOT_FOUND";
|
---|
| 85 | function assertIsFunction(func, errorMessage = `expected a function, instead received ${typeof func}`) {
|
---|
| 86 | if (typeof func !== "function") {
|
---|
| 87 | throw new TypeError(errorMessage);
|
---|
| 88 | }
|
---|
| 89 | }
|
---|
| 90 | function assertIsObject(object, errorMessage = `expected an object, instead received ${typeof object}`) {
|
---|
| 91 | if (typeof object !== "object") {
|
---|
| 92 | throw new TypeError(errorMessage);
|
---|
| 93 | }
|
---|
| 94 | }
|
---|
| 95 | function assertIsArrayOfFunctions(array, errorMessage = `expected all items to be functions, instead received the following types: `) {
|
---|
| 96 | if (!array.every((item) => typeof item === "function")) {
|
---|
| 97 | const itemTypes = array.map(
|
---|
| 98 | (item) => typeof item === "function" ? `function ${item.name || "unnamed"}()` : typeof item
|
---|
| 99 | ).join(", ");
|
---|
| 100 | throw new TypeError(`${errorMessage}[${itemTypes}]`);
|
---|
| 101 | }
|
---|
| 102 | }
|
---|
| 103 | var ensureIsArray = (item) => {
|
---|
| 104 | return Array.isArray(item) ? item : [item];
|
---|
| 105 | };
|
---|
| 106 | function getDependencies(createSelectorArgs) {
|
---|
| 107 | const dependencies = Array.isArray(createSelectorArgs[0]) ? createSelectorArgs[0] : createSelectorArgs;
|
---|
| 108 | assertIsArrayOfFunctions(
|
---|
| 109 | dependencies,
|
---|
| 110 | `createSelector expects all input-selectors to be functions, but received the following types: `
|
---|
| 111 | );
|
---|
| 112 | return dependencies;
|
---|
| 113 | }
|
---|
| 114 | function collectInputSelectorResults(dependencies, inputSelectorArgs) {
|
---|
| 115 | const inputSelectorResults = [];
|
---|
| 116 | const { length } = dependencies;
|
---|
| 117 | for (let i = 0; i < length; i++) {
|
---|
| 118 | inputSelectorResults.push(dependencies[i].apply(null, inputSelectorArgs));
|
---|
| 119 | }
|
---|
| 120 | return inputSelectorResults;
|
---|
| 121 | }
|
---|
| 122 | var getDevModeChecksExecutionInfo = (firstRun, devModeChecks) => {
|
---|
| 123 | const { identityFunctionCheck, inputStabilityCheck } = __spreadValues(__spreadValues({}, globalDevModeChecks), devModeChecks);
|
---|
| 124 | return {
|
---|
| 125 | identityFunctionCheck: {
|
---|
| 126 | shouldRun: identityFunctionCheck === "always" || identityFunctionCheck === "once" && firstRun,
|
---|
| 127 | run: runIdentityFunctionCheck
|
---|
| 128 | },
|
---|
| 129 | inputStabilityCheck: {
|
---|
| 130 | shouldRun: inputStabilityCheck === "always" || inputStabilityCheck === "once" && firstRun,
|
---|
| 131 | run: runInputStabilityCheck
|
---|
| 132 | }
|
---|
| 133 | };
|
---|
| 134 | };
|
---|
| 135 |
|
---|
| 136 | // src/autotrackMemoize/autotracking.ts
|
---|
| 137 | var $REVISION = 0;
|
---|
| 138 | var CURRENT_TRACKER = null;
|
---|
| 139 | var Cell = class {
|
---|
| 140 | constructor(initialValue, isEqual = tripleEq) {
|
---|
| 141 | __publicField(this, "revision", $REVISION);
|
---|
| 142 | __publicField(this, "_value");
|
---|
| 143 | __publicField(this, "_lastValue");
|
---|
| 144 | __publicField(this, "_isEqual", tripleEq);
|
---|
| 145 | this._value = this._lastValue = initialValue;
|
---|
| 146 | this._isEqual = isEqual;
|
---|
| 147 | }
|
---|
| 148 | // Whenever a storage value is read, it'll add itself to the current tracker if
|
---|
| 149 | // one exists, entangling its state with that cache.
|
---|
| 150 | get value() {
|
---|
| 151 | CURRENT_TRACKER == null ? void 0 : CURRENT_TRACKER.add(this);
|
---|
| 152 | return this._value;
|
---|
| 153 | }
|
---|
| 154 | // Whenever a storage value is updated, we bump the global revision clock,
|
---|
| 155 | // assign the revision for this storage to the new value, _and_ we schedule a
|
---|
| 156 | // rerender. This is important, and it's what makes autotracking _pull_
|
---|
| 157 | // based. We don't actively tell the caches which depend on the storage that
|
---|
| 158 | // anything has happened. Instead, we recompute the caches when needed.
|
---|
| 159 | set value(newValue) {
|
---|
| 160 | if (this.value === newValue)
|
---|
| 161 | return;
|
---|
| 162 | this._value = newValue;
|
---|
| 163 | this.revision = ++$REVISION;
|
---|
| 164 | }
|
---|
| 165 | };
|
---|
| 166 | function tripleEq(a, b) {
|
---|
| 167 | return a === b;
|
---|
| 168 | }
|
---|
| 169 | var TrackingCache = class {
|
---|
| 170 | constructor(fn) {
|
---|
| 171 | __publicField(this, "_cachedValue");
|
---|
| 172 | __publicField(this, "_cachedRevision", -1);
|
---|
| 173 | __publicField(this, "_deps", []);
|
---|
| 174 | __publicField(this, "hits", 0);
|
---|
| 175 | __publicField(this, "fn");
|
---|
| 176 | this.fn = fn;
|
---|
| 177 | }
|
---|
| 178 | clear() {
|
---|
| 179 | this._cachedValue = void 0;
|
---|
| 180 | this._cachedRevision = -1;
|
---|
| 181 | this._deps = [];
|
---|
| 182 | this.hits = 0;
|
---|
| 183 | }
|
---|
| 184 | get value() {
|
---|
| 185 | if (this.revision > this._cachedRevision) {
|
---|
| 186 | const { fn } = this;
|
---|
| 187 | const currentTracker = /* @__PURE__ */ new Set();
|
---|
| 188 | const prevTracker = CURRENT_TRACKER;
|
---|
| 189 | CURRENT_TRACKER = currentTracker;
|
---|
| 190 | this._cachedValue = fn();
|
---|
| 191 | CURRENT_TRACKER = prevTracker;
|
---|
| 192 | this.hits++;
|
---|
| 193 | this._deps = Array.from(currentTracker);
|
---|
| 194 | this._cachedRevision = this.revision;
|
---|
| 195 | }
|
---|
| 196 | CURRENT_TRACKER == null ? void 0 : CURRENT_TRACKER.add(this);
|
---|
| 197 | return this._cachedValue;
|
---|
| 198 | }
|
---|
| 199 | get revision() {
|
---|
| 200 | return Math.max(...this._deps.map((d) => d.revision), 0);
|
---|
| 201 | }
|
---|
| 202 | };
|
---|
| 203 | function getValue(cell) {
|
---|
| 204 | if (!(cell instanceof Cell)) {
|
---|
| 205 | console.warn("Not a valid cell! ", cell);
|
---|
| 206 | }
|
---|
| 207 | return cell.value;
|
---|
| 208 | }
|
---|
| 209 | function setValue(storage, value) {
|
---|
| 210 | if (!(storage instanceof Cell)) {
|
---|
| 211 | throw new TypeError(
|
---|
| 212 | "setValue must be passed a tracked store created with `createStorage`."
|
---|
| 213 | );
|
---|
| 214 | }
|
---|
| 215 | storage.value = storage._lastValue = value;
|
---|
| 216 | }
|
---|
| 217 | function createCell(initialValue, isEqual = tripleEq) {
|
---|
| 218 | return new Cell(initialValue, isEqual);
|
---|
| 219 | }
|
---|
| 220 | function createCache(fn) {
|
---|
| 221 | assertIsFunction(
|
---|
| 222 | fn,
|
---|
| 223 | "the first parameter to `createCache` must be a function"
|
---|
| 224 | );
|
---|
| 225 | return new TrackingCache(fn);
|
---|
| 226 | }
|
---|
| 227 |
|
---|
| 228 | // src/autotrackMemoize/tracking.ts
|
---|
| 229 | var neverEq = (a, b) => false;
|
---|
| 230 | function createTag() {
|
---|
| 231 | return createCell(null, neverEq);
|
---|
| 232 | }
|
---|
| 233 | function dirtyTag(tag, value) {
|
---|
| 234 | setValue(tag, value);
|
---|
| 235 | }
|
---|
| 236 | var consumeCollection = (node) => {
|
---|
| 237 | let tag = node.collectionTag;
|
---|
| 238 | if (tag === null) {
|
---|
| 239 | tag = node.collectionTag = createTag();
|
---|
| 240 | }
|
---|
| 241 | getValue(tag);
|
---|
| 242 | };
|
---|
| 243 | var dirtyCollection = (node) => {
|
---|
| 244 | const tag = node.collectionTag;
|
---|
| 245 | if (tag !== null) {
|
---|
| 246 | dirtyTag(tag, null);
|
---|
| 247 | }
|
---|
| 248 | };
|
---|
| 249 |
|
---|
| 250 | // src/autotrackMemoize/proxy.ts
|
---|
| 251 | var REDUX_PROXY_LABEL = Symbol();
|
---|
| 252 | var nextId = 0;
|
---|
| 253 | var proto = Object.getPrototypeOf({});
|
---|
| 254 | var ObjectTreeNode = class {
|
---|
| 255 | constructor(value) {
|
---|
| 256 | this.value = value;
|
---|
| 257 | __publicField(this, "proxy", new Proxy(this, objectProxyHandler));
|
---|
| 258 | __publicField(this, "tag", createTag());
|
---|
| 259 | __publicField(this, "tags", {});
|
---|
| 260 | __publicField(this, "children", {});
|
---|
| 261 | __publicField(this, "collectionTag", null);
|
---|
| 262 | __publicField(this, "id", nextId++);
|
---|
| 263 | this.value = value;
|
---|
| 264 | this.tag.value = value;
|
---|
| 265 | }
|
---|
| 266 | };
|
---|
| 267 | var objectProxyHandler = {
|
---|
| 268 | get(node, key) {
|
---|
| 269 | function calculateResult() {
|
---|
| 270 | const { value } = node;
|
---|
| 271 | const childValue = Reflect.get(value, key);
|
---|
| 272 | if (typeof key === "symbol") {
|
---|
| 273 | return childValue;
|
---|
| 274 | }
|
---|
| 275 | if (key in proto) {
|
---|
| 276 | return childValue;
|
---|
| 277 | }
|
---|
| 278 | if (typeof childValue === "object" && childValue !== null) {
|
---|
| 279 | let childNode = node.children[key];
|
---|
| 280 | if (childNode === void 0) {
|
---|
| 281 | childNode = node.children[key] = createNode(childValue);
|
---|
| 282 | }
|
---|
| 283 | if (childNode.tag) {
|
---|
| 284 | getValue(childNode.tag);
|
---|
| 285 | }
|
---|
| 286 | return childNode.proxy;
|
---|
| 287 | } else {
|
---|
| 288 | let tag = node.tags[key];
|
---|
| 289 | if (tag === void 0) {
|
---|
| 290 | tag = node.tags[key] = createTag();
|
---|
| 291 | tag.value = childValue;
|
---|
| 292 | }
|
---|
| 293 | getValue(tag);
|
---|
| 294 | return childValue;
|
---|
| 295 | }
|
---|
| 296 | }
|
---|
| 297 | const res = calculateResult();
|
---|
| 298 | return res;
|
---|
| 299 | },
|
---|
| 300 | ownKeys(node) {
|
---|
| 301 | consumeCollection(node);
|
---|
| 302 | return Reflect.ownKeys(node.value);
|
---|
| 303 | },
|
---|
| 304 | getOwnPropertyDescriptor(node, prop) {
|
---|
| 305 | return Reflect.getOwnPropertyDescriptor(node.value, prop);
|
---|
| 306 | },
|
---|
| 307 | has(node, prop) {
|
---|
| 308 | return Reflect.has(node.value, prop);
|
---|
| 309 | }
|
---|
| 310 | };
|
---|
| 311 | var ArrayTreeNode = class {
|
---|
| 312 | constructor(value) {
|
---|
| 313 | this.value = value;
|
---|
| 314 | __publicField(this, "proxy", new Proxy([this], arrayProxyHandler));
|
---|
| 315 | __publicField(this, "tag", createTag());
|
---|
| 316 | __publicField(this, "tags", {});
|
---|
| 317 | __publicField(this, "children", {});
|
---|
| 318 | __publicField(this, "collectionTag", null);
|
---|
| 319 | __publicField(this, "id", nextId++);
|
---|
| 320 | this.value = value;
|
---|
| 321 | this.tag.value = value;
|
---|
| 322 | }
|
---|
| 323 | };
|
---|
| 324 | var arrayProxyHandler = {
|
---|
| 325 | get([node], key) {
|
---|
| 326 | if (key === "length") {
|
---|
| 327 | consumeCollection(node);
|
---|
| 328 | }
|
---|
| 329 | return objectProxyHandler.get(node, key);
|
---|
| 330 | },
|
---|
| 331 | ownKeys([node]) {
|
---|
| 332 | return objectProxyHandler.ownKeys(node);
|
---|
| 333 | },
|
---|
| 334 | getOwnPropertyDescriptor([node], prop) {
|
---|
| 335 | return objectProxyHandler.getOwnPropertyDescriptor(node, prop);
|
---|
| 336 | },
|
---|
| 337 | has([node], prop) {
|
---|
| 338 | return objectProxyHandler.has(node, prop);
|
---|
| 339 | }
|
---|
| 340 | };
|
---|
| 341 | function createNode(value) {
|
---|
| 342 | if (Array.isArray(value)) {
|
---|
| 343 | return new ArrayTreeNode(value);
|
---|
| 344 | }
|
---|
| 345 | return new ObjectTreeNode(value);
|
---|
| 346 | }
|
---|
| 347 | function updateNode(node, newValue) {
|
---|
| 348 | const { value, tags, children } = node;
|
---|
| 349 | node.value = newValue;
|
---|
| 350 | if (Array.isArray(value) && Array.isArray(newValue) && value.length !== newValue.length) {
|
---|
| 351 | dirtyCollection(node);
|
---|
| 352 | } else {
|
---|
| 353 | if (value !== newValue) {
|
---|
| 354 | let oldKeysSize = 0;
|
---|
| 355 | let newKeysSize = 0;
|
---|
| 356 | let anyKeysAdded = false;
|
---|
| 357 | for (const _key in value) {
|
---|
| 358 | oldKeysSize++;
|
---|
| 359 | }
|
---|
| 360 | for (const key in newValue) {
|
---|
| 361 | newKeysSize++;
|
---|
| 362 | if (!(key in value)) {
|
---|
| 363 | anyKeysAdded = true;
|
---|
| 364 | break;
|
---|
| 365 | }
|
---|
| 366 | }
|
---|
| 367 | const isDifferent = anyKeysAdded || oldKeysSize !== newKeysSize;
|
---|
| 368 | if (isDifferent) {
|
---|
| 369 | dirtyCollection(node);
|
---|
| 370 | }
|
---|
| 371 | }
|
---|
| 372 | }
|
---|
| 373 | for (const key in tags) {
|
---|
| 374 | const childValue = value[key];
|
---|
| 375 | const newChildValue = newValue[key];
|
---|
| 376 | if (childValue !== newChildValue) {
|
---|
| 377 | dirtyCollection(node);
|
---|
| 378 | dirtyTag(tags[key], newChildValue);
|
---|
| 379 | }
|
---|
| 380 | if (typeof newChildValue === "object" && newChildValue !== null) {
|
---|
| 381 | delete tags[key];
|
---|
| 382 | }
|
---|
| 383 | }
|
---|
| 384 | for (const key in children) {
|
---|
| 385 | const childNode = children[key];
|
---|
| 386 | const newChildValue = newValue[key];
|
---|
| 387 | const childValue = childNode.value;
|
---|
| 388 | if (childValue === newChildValue) {
|
---|
| 389 | continue;
|
---|
| 390 | } else if (typeof newChildValue === "object" && newChildValue !== null) {
|
---|
| 391 | updateNode(childNode, newChildValue);
|
---|
| 392 | } else {
|
---|
| 393 | deleteNode(childNode);
|
---|
| 394 | delete children[key];
|
---|
| 395 | }
|
---|
| 396 | }
|
---|
| 397 | }
|
---|
| 398 | function deleteNode(node) {
|
---|
| 399 | if (node.tag) {
|
---|
| 400 | dirtyTag(node.tag, null);
|
---|
| 401 | }
|
---|
| 402 | dirtyCollection(node);
|
---|
| 403 | for (const key in node.tags) {
|
---|
| 404 | dirtyTag(node.tags[key], null);
|
---|
| 405 | }
|
---|
| 406 | for (const key in node.children) {
|
---|
| 407 | deleteNode(node.children[key]);
|
---|
| 408 | }
|
---|
| 409 | }
|
---|
| 410 |
|
---|
| 411 | // src/lruMemoize.ts
|
---|
| 412 | function createSingletonCache(equals) {
|
---|
| 413 | let entry;
|
---|
| 414 | return {
|
---|
| 415 | get(key) {
|
---|
| 416 | if (entry && equals(entry.key, key)) {
|
---|
| 417 | return entry.value;
|
---|
| 418 | }
|
---|
| 419 | return NOT_FOUND;
|
---|
| 420 | },
|
---|
| 421 | put(key, value) {
|
---|
| 422 | entry = { key, value };
|
---|
| 423 | },
|
---|
| 424 | getEntries() {
|
---|
| 425 | return entry ? [entry] : [];
|
---|
| 426 | },
|
---|
| 427 | clear() {
|
---|
| 428 | entry = void 0;
|
---|
| 429 | }
|
---|
| 430 | };
|
---|
| 431 | }
|
---|
| 432 | function createLruCache(maxSize, equals) {
|
---|
| 433 | let entries = [];
|
---|
| 434 | function get(key) {
|
---|
| 435 | const cacheIndex = entries.findIndex((entry) => equals(key, entry.key));
|
---|
| 436 | if (cacheIndex > -1) {
|
---|
| 437 | const entry = entries[cacheIndex];
|
---|
| 438 | if (cacheIndex > 0) {
|
---|
| 439 | entries.splice(cacheIndex, 1);
|
---|
| 440 | entries.unshift(entry);
|
---|
| 441 | }
|
---|
| 442 | return entry.value;
|
---|
| 443 | }
|
---|
| 444 | return NOT_FOUND;
|
---|
| 445 | }
|
---|
| 446 | function put(key, value) {
|
---|
| 447 | if (get(key) === NOT_FOUND) {
|
---|
| 448 | entries.unshift({ key, value });
|
---|
| 449 | if (entries.length > maxSize) {
|
---|
| 450 | entries.pop();
|
---|
| 451 | }
|
---|
| 452 | }
|
---|
| 453 | }
|
---|
| 454 | function getEntries() {
|
---|
| 455 | return entries;
|
---|
| 456 | }
|
---|
| 457 | function clear() {
|
---|
| 458 | entries = [];
|
---|
| 459 | }
|
---|
| 460 | return { get, put, getEntries, clear };
|
---|
| 461 | }
|
---|
| 462 | var referenceEqualityCheck = (a, b) => a === b;
|
---|
| 463 | function createCacheKeyComparator(equalityCheck) {
|
---|
| 464 | return function areArgumentsShallowlyEqual(prev, next) {
|
---|
| 465 | if (prev === null || next === null || prev.length !== next.length) {
|
---|
| 466 | return false;
|
---|
| 467 | }
|
---|
| 468 | const { length } = prev;
|
---|
| 469 | for (let i = 0; i < length; i++) {
|
---|
| 470 | if (!equalityCheck(prev[i], next[i])) {
|
---|
| 471 | return false;
|
---|
| 472 | }
|
---|
| 473 | }
|
---|
| 474 | return true;
|
---|
| 475 | };
|
---|
| 476 | }
|
---|
| 477 | function lruMemoize(func, equalityCheckOrOptions) {
|
---|
| 478 | const providedOptions = typeof equalityCheckOrOptions === "object" ? equalityCheckOrOptions : { equalityCheck: equalityCheckOrOptions };
|
---|
| 479 | const {
|
---|
| 480 | equalityCheck = referenceEqualityCheck,
|
---|
| 481 | maxSize = 1,
|
---|
| 482 | resultEqualityCheck
|
---|
| 483 | } = providedOptions;
|
---|
| 484 | const comparator = createCacheKeyComparator(equalityCheck);
|
---|
| 485 | let resultsCount = 0;
|
---|
| 486 | const cache = maxSize === 1 ? createSingletonCache(comparator) : createLruCache(maxSize, comparator);
|
---|
| 487 | function memoized() {
|
---|
| 488 | let value = cache.get(arguments);
|
---|
| 489 | if (value === NOT_FOUND) {
|
---|
| 490 | value = func.apply(null, arguments);
|
---|
| 491 | resultsCount++;
|
---|
| 492 | if (resultEqualityCheck) {
|
---|
| 493 | const entries = cache.getEntries();
|
---|
| 494 | const matchingEntry = entries.find(
|
---|
| 495 | (entry) => resultEqualityCheck(entry.value, value)
|
---|
| 496 | );
|
---|
| 497 | if (matchingEntry) {
|
---|
| 498 | value = matchingEntry.value;
|
---|
| 499 | resultsCount !== 0 && resultsCount--;
|
---|
| 500 | }
|
---|
| 501 | }
|
---|
| 502 | cache.put(arguments, value);
|
---|
| 503 | }
|
---|
| 504 | return value;
|
---|
| 505 | }
|
---|
| 506 | memoized.clearCache = () => {
|
---|
| 507 | cache.clear();
|
---|
| 508 | memoized.resetResultsCount();
|
---|
| 509 | };
|
---|
| 510 | memoized.resultsCount = () => resultsCount;
|
---|
| 511 | memoized.resetResultsCount = () => {
|
---|
| 512 | resultsCount = 0;
|
---|
| 513 | };
|
---|
| 514 | return memoized;
|
---|
| 515 | }
|
---|
| 516 |
|
---|
| 517 | // src/autotrackMemoize/autotrackMemoize.ts
|
---|
| 518 | function autotrackMemoize(func) {
|
---|
| 519 | const node = createNode(
|
---|
| 520 | []
|
---|
| 521 | );
|
---|
| 522 | let lastArgs = null;
|
---|
| 523 | const shallowEqual = createCacheKeyComparator(referenceEqualityCheck);
|
---|
| 524 | const cache = createCache(() => {
|
---|
| 525 | const res = func.apply(null, node.proxy);
|
---|
| 526 | return res;
|
---|
| 527 | });
|
---|
| 528 | function memoized() {
|
---|
| 529 | if (!shallowEqual(lastArgs, arguments)) {
|
---|
| 530 | updateNode(node, arguments);
|
---|
| 531 | lastArgs = arguments;
|
---|
| 532 | }
|
---|
| 533 | return cache.value;
|
---|
| 534 | }
|
---|
| 535 | memoized.clearCache = () => {
|
---|
| 536 | return cache.clear();
|
---|
| 537 | };
|
---|
| 538 | return memoized;
|
---|
| 539 | }
|
---|
| 540 |
|
---|
| 541 | // src/weakMapMemoize.ts
|
---|
| 542 | var StrongRef = class {
|
---|
| 543 | constructor(value) {
|
---|
| 544 | this.value = value;
|
---|
| 545 | }
|
---|
| 546 | deref() {
|
---|
| 547 | return this.value;
|
---|
| 548 | }
|
---|
| 549 | };
|
---|
| 550 | var Ref = typeof WeakRef !== "undefined" ? WeakRef : StrongRef;
|
---|
| 551 | var UNTERMINATED = 0;
|
---|
| 552 | var TERMINATED = 1;
|
---|
| 553 | function createCacheNode() {
|
---|
| 554 | return {
|
---|
| 555 | s: UNTERMINATED,
|
---|
| 556 | v: void 0,
|
---|
| 557 | o: null,
|
---|
| 558 | p: null
|
---|
| 559 | };
|
---|
| 560 | }
|
---|
| 561 | function weakMapMemoize(func, options = {}) {
|
---|
| 562 | let fnNode = createCacheNode();
|
---|
| 563 | const { resultEqualityCheck } = options;
|
---|
| 564 | let lastResult;
|
---|
| 565 | let resultsCount = 0;
|
---|
| 566 | function memoized() {
|
---|
| 567 | var _a, _b;
|
---|
| 568 | let cacheNode = fnNode;
|
---|
| 569 | const { length } = arguments;
|
---|
| 570 | for (let i = 0, l = length; i < l; i++) {
|
---|
| 571 | const arg = arguments[i];
|
---|
| 572 | if (typeof arg === "function" || typeof arg === "object" && arg !== null) {
|
---|
| 573 | let objectCache = cacheNode.o;
|
---|
| 574 | if (objectCache === null) {
|
---|
| 575 | cacheNode.o = objectCache = /* @__PURE__ */ new WeakMap();
|
---|
| 576 | }
|
---|
| 577 | const objectNode = objectCache.get(arg);
|
---|
| 578 | if (objectNode === void 0) {
|
---|
| 579 | cacheNode = createCacheNode();
|
---|
| 580 | objectCache.set(arg, cacheNode);
|
---|
| 581 | } else {
|
---|
| 582 | cacheNode = objectNode;
|
---|
| 583 | }
|
---|
| 584 | } else {
|
---|
| 585 | let primitiveCache = cacheNode.p;
|
---|
| 586 | if (primitiveCache === null) {
|
---|
| 587 | cacheNode.p = primitiveCache = /* @__PURE__ */ new Map();
|
---|
| 588 | }
|
---|
| 589 | const primitiveNode = primitiveCache.get(arg);
|
---|
| 590 | if (primitiveNode === void 0) {
|
---|
| 591 | cacheNode = createCacheNode();
|
---|
| 592 | primitiveCache.set(arg, cacheNode);
|
---|
| 593 | } else {
|
---|
| 594 | cacheNode = primitiveNode;
|
---|
| 595 | }
|
---|
| 596 | }
|
---|
| 597 | }
|
---|
| 598 | const terminatedNode = cacheNode;
|
---|
| 599 | let result;
|
---|
| 600 | if (cacheNode.s === TERMINATED) {
|
---|
| 601 | result = cacheNode.v;
|
---|
| 602 | } else {
|
---|
| 603 | result = func.apply(null, arguments);
|
---|
| 604 | resultsCount++;
|
---|
| 605 | }
|
---|
| 606 | terminatedNode.s = TERMINATED;
|
---|
| 607 | if (resultEqualityCheck) {
|
---|
| 608 | const lastResultValue = (_b = (_a = lastResult == null ? void 0 : lastResult.deref) == null ? void 0 : _a.call(lastResult)) != null ? _b : lastResult;
|
---|
| 609 | if (lastResultValue != null && resultEqualityCheck(lastResultValue, result)) {
|
---|
| 610 | result = lastResultValue;
|
---|
| 611 | resultsCount !== 0 && resultsCount--;
|
---|
| 612 | }
|
---|
| 613 | const needsWeakRef = typeof result === "object" && result !== null || typeof result === "function";
|
---|
| 614 | lastResult = needsWeakRef ? new Ref(result) : result;
|
---|
| 615 | }
|
---|
| 616 | terminatedNode.v = result;
|
---|
| 617 | return result;
|
---|
| 618 | }
|
---|
| 619 | memoized.clearCache = () => {
|
---|
| 620 | fnNode = createCacheNode();
|
---|
| 621 | memoized.resetResultsCount();
|
---|
| 622 | };
|
---|
| 623 | memoized.resultsCount = () => resultsCount;
|
---|
| 624 | memoized.resetResultsCount = () => {
|
---|
| 625 | resultsCount = 0;
|
---|
| 626 | };
|
---|
| 627 | return memoized;
|
---|
| 628 | }
|
---|
| 629 |
|
---|
| 630 | // src/createSelectorCreator.ts
|
---|
| 631 | function createSelectorCreator(memoizeOrOptions, ...memoizeOptionsFromArgs) {
|
---|
| 632 | const createSelectorCreatorOptions = typeof memoizeOrOptions === "function" ? {
|
---|
| 633 | memoize: memoizeOrOptions,
|
---|
| 634 | memoizeOptions: memoizeOptionsFromArgs
|
---|
| 635 | } : memoizeOrOptions;
|
---|
| 636 | const createSelector2 = (...createSelectorArgs) => {
|
---|
| 637 | let recomputations = 0;
|
---|
| 638 | let dependencyRecomputations = 0;
|
---|
| 639 | let lastResult;
|
---|
| 640 | let directlyPassedOptions = {};
|
---|
| 641 | let resultFunc = createSelectorArgs.pop();
|
---|
| 642 | if (typeof resultFunc === "object") {
|
---|
| 643 | directlyPassedOptions = resultFunc;
|
---|
| 644 | resultFunc = createSelectorArgs.pop();
|
---|
| 645 | }
|
---|
| 646 | assertIsFunction(
|
---|
| 647 | resultFunc,
|
---|
| 648 | `createSelector expects an output function after the inputs, but received: [${typeof resultFunc}]`
|
---|
| 649 | );
|
---|
| 650 | const combinedOptions = __spreadValues(__spreadValues({}, createSelectorCreatorOptions), directlyPassedOptions);
|
---|
| 651 | const {
|
---|
| 652 | memoize,
|
---|
| 653 | memoizeOptions = [],
|
---|
| 654 | argsMemoize = weakMapMemoize,
|
---|
| 655 | argsMemoizeOptions = [],
|
---|
| 656 | devModeChecks = {}
|
---|
| 657 | } = combinedOptions;
|
---|
| 658 | const finalMemoizeOptions = ensureIsArray(memoizeOptions);
|
---|
| 659 | const finalArgsMemoizeOptions = ensureIsArray(argsMemoizeOptions);
|
---|
| 660 | const dependencies = getDependencies(createSelectorArgs);
|
---|
| 661 | const memoizedResultFunc = memoize(function recomputationWrapper() {
|
---|
| 662 | recomputations++;
|
---|
| 663 | return resultFunc.apply(
|
---|
| 664 | null,
|
---|
| 665 | arguments
|
---|
| 666 | );
|
---|
| 667 | }, ...finalMemoizeOptions);
|
---|
| 668 | let firstRun = true;
|
---|
| 669 | const selector = argsMemoize(function dependenciesChecker() {
|
---|
| 670 | dependencyRecomputations++;
|
---|
| 671 | const inputSelectorResults = collectInputSelectorResults(
|
---|
| 672 | dependencies,
|
---|
| 673 | arguments
|
---|
| 674 | );
|
---|
| 675 | lastResult = memoizedResultFunc.apply(null, inputSelectorResults);
|
---|
| 676 | if (process.env.NODE_ENV !== "production") {
|
---|
| 677 | const { identityFunctionCheck, inputStabilityCheck } = getDevModeChecksExecutionInfo(firstRun, devModeChecks);
|
---|
| 678 | if (identityFunctionCheck.shouldRun) {
|
---|
| 679 | identityFunctionCheck.run(
|
---|
| 680 | resultFunc,
|
---|
| 681 | inputSelectorResults,
|
---|
| 682 | lastResult
|
---|
| 683 | );
|
---|
| 684 | }
|
---|
| 685 | if (inputStabilityCheck.shouldRun) {
|
---|
| 686 | const inputSelectorResultsCopy = collectInputSelectorResults(
|
---|
| 687 | dependencies,
|
---|
| 688 | arguments
|
---|
| 689 | );
|
---|
| 690 | inputStabilityCheck.run(
|
---|
| 691 | { inputSelectorResults, inputSelectorResultsCopy },
|
---|
| 692 | { memoize, memoizeOptions: finalMemoizeOptions },
|
---|
| 693 | arguments
|
---|
| 694 | );
|
---|
| 695 | }
|
---|
| 696 | if (firstRun)
|
---|
| 697 | firstRun = false;
|
---|
| 698 | }
|
---|
| 699 | return lastResult;
|
---|
| 700 | }, ...finalArgsMemoizeOptions);
|
---|
| 701 | return Object.assign(selector, {
|
---|
| 702 | resultFunc,
|
---|
| 703 | memoizedResultFunc,
|
---|
| 704 | dependencies,
|
---|
| 705 | dependencyRecomputations: () => dependencyRecomputations,
|
---|
| 706 | resetDependencyRecomputations: () => {
|
---|
| 707 | dependencyRecomputations = 0;
|
---|
| 708 | },
|
---|
| 709 | lastResult: () => lastResult,
|
---|
| 710 | recomputations: () => recomputations,
|
---|
| 711 | resetRecomputations: () => {
|
---|
| 712 | recomputations = 0;
|
---|
| 713 | },
|
---|
| 714 | memoize,
|
---|
| 715 | argsMemoize
|
---|
| 716 | });
|
---|
| 717 | };
|
---|
| 718 | Object.assign(createSelector2, {
|
---|
| 719 | withTypes: () => createSelector2
|
---|
| 720 | });
|
---|
| 721 | return createSelector2;
|
---|
| 722 | }
|
---|
| 723 | var createSelector = /* @__PURE__ */ createSelectorCreator(weakMapMemoize);
|
---|
| 724 |
|
---|
| 725 | // src/createStructuredSelector.ts
|
---|
| 726 | var createStructuredSelector = Object.assign(
|
---|
| 727 | (inputSelectorsObject, selectorCreator = createSelector) => {
|
---|
| 728 | assertIsObject(
|
---|
| 729 | inputSelectorsObject,
|
---|
| 730 | `createStructuredSelector expects first argument to be an object where each property is a selector, instead received a ${typeof inputSelectorsObject}`
|
---|
| 731 | );
|
---|
| 732 | const inputSelectorKeys = Object.keys(inputSelectorsObject);
|
---|
| 733 | const dependencies = inputSelectorKeys.map(
|
---|
| 734 | (key) => inputSelectorsObject[key]
|
---|
| 735 | );
|
---|
| 736 | const structuredSelector = selectorCreator(
|
---|
| 737 | dependencies,
|
---|
| 738 | (...inputSelectorResults) => {
|
---|
| 739 | return inputSelectorResults.reduce((composition, value, index) => {
|
---|
| 740 | composition[inputSelectorKeys[index]] = value;
|
---|
| 741 | return composition;
|
---|
| 742 | }, {});
|
---|
| 743 | }
|
---|
| 744 | );
|
---|
| 745 | return structuredSelector;
|
---|
| 746 | },
|
---|
| 747 | { withTypes: () => createStructuredSelector }
|
---|
| 748 | );
|
---|
| 749 | export {
|
---|
| 750 | createSelector,
|
---|
| 751 | createSelectorCreator,
|
---|
| 752 | createStructuredSelector,
|
---|
| 753 | lruMemoize,
|
---|
| 754 | referenceEqualityCheck,
|
---|
| 755 | setGlobalDevModeChecks,
|
---|
| 756 | autotrackMemoize as unstable_autotrackMemoize,
|
---|
| 757 | weakMapMemoize
|
---|
| 758 | };
|
---|
| 759 | //# sourceMappingURL=reselect.legacy-esm.js.map |
---|