Skip to content

Commit

Permalink
fix: Strip Symbol from production builds (#6389)
Browse files Browse the repository at this point in the history
* Add a Symbol-like symbol (thank you glimmer-vm)

This is similar to what is implemented here:
https://github.com/glimmerjs/glimmer-vm/blob/72718d0d6ebb2614ec984f51435a44830d410e4c/packages/%40glimmer/reference/lib/validators.ts

* Replace `Symbol`s that may be iterable by `symbol`s

These occurences of Symbol might be replaced by this `symbol`, similar
but different in the sense it is iterable.
  • Loading branch information
dcyriller authored and runspired committed Sep 11, 2019
1 parent 004c2a1 commit 109aac1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/store/addon/-private/system/fetch-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import RequestCache from './request-cache';
import { CollectionResourceDocument, SingleResourceDocument } from '../ts-interfaces/ember-data-json-api';
import { RecordIdentifier } from '../ts-interfaces/identifier';
import { FindRecordQuery, SaveRecordMutation, Request } from '../ts-interfaces/fetch-manager';
import { symbol } from '../ts-interfaces/utils/symbol';
import Store from './store';
import recordDataFor from './record-data-for';

Expand All @@ -27,7 +28,7 @@ function payloadIsNotBlank(adapterPayload): boolean {
}

const emberRun = emberRunLoop.backburner;
export const SaveOp = Symbol('SaveOp');
export const SaveOp: unique symbol = symbol('SaveOp');

interface PendingFetchItem {
identifier: RecordIdentifier;
Expand Down
5 changes: 3 additions & 2 deletions packages/store/addon/-private/system/request-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import {
Operation,
RequestStateEnum,
} from '../ts-interfaces/fetch-manager';
import { symbol } from '../ts-interfaces/utils/symbol';

import { _findHasMany, _findBelongsTo, _findAll, _query, _queryRecord } from './store/finders';

const Touching = Symbol('touching');
export const RequestPromise = Symbol('promise');
export const Touching: unique symbol = symbol('touching');
export const RequestPromise: unique symbol = symbol('promise');

export interface InternalRequest extends RequestState {
[Touching]: RecordIdentifier[];
Expand Down
5 changes: 4 additions & 1 deletion packages/store/addon/-private/ts-interfaces/utils/brand.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { symbol } from './symbol';

/**
@module @ember-data/store
*/
Expand All @@ -14,4 +16,5 @@
*
* @internal
*/
export const BRAND_SYMBOL = Symbol(`DEBUG-ts-brand`);

export const BRAND_SYMBOL: unique symbol = symbol('DEBUG-ts-brand');
19 changes: 19 additions & 0 deletions packages/store/addon/-private/ts-interfaces/utils/symbol.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
@module @ember-data/store
*/

/**
* This symbol provides a Symbol replacement for browsers that do not have it
* (eg. IE 11).
*
* The replacement is different from the native Symbol in some ways. It is a
* function that produces an output:
* - iterable;
* - that is a string, not a symbol.
*
* @internal
*/
export const symbol =
typeof Symbol !== 'undefined'
? Symbol
: (key: string) => `__${key}${Math.floor(Math.random() * Date.now())}__` as any;

0 comments on commit 109aac1

Please sign in to comment.