Commit 2b24c879 authored by Robert Knight's avatar Robert Knight

Replace seamless-immutable with trivial helper

We use this dependency to guard against accidental mutation of objects
and arrays in the store. However the production build was including the
development version of the library.

To simplify things, replace the library with a small utility.
parent d2501f0c
......@@ -95,7 +95,6 @@
"retry": "^0.12.0",
"sass": "^1.23.0",
"scroll-into-view": "^1.8.2",
"seamless-immutable": "^7.1.4",
"shallowequal": "^1.1.0",
"showdown": "^1.6.4",
"sinon": "^9.0.0",
......
import angular from 'angular';
import immutable from 'seamless-immutable';
import EventEmitter from 'tiny-emitter';
import * as util from './angular-util';
import events from '../../events';
import threadList, { $imports } from '../thread-list';
import immutable from '../../util/immutable';
const annotFixtures = immutable({
annotation: { $tag: 't1', id: '1', text: 'text' },
......
import angular from 'angular';
import immutable from 'seamless-immutable';
import events from '../../events';
import storeFactory from '../../store';
import annotationMapperFactory from '../annotation-mapper';
import immutable from '../../util/immutable';
describe('annotationMapper', function() {
const sandbox = sinon.createSandbox();
......
import angular from 'angular';
import immutable from 'seamless-immutable';
import events from '../../events';
import * as annotationFixtures from '../../test/annotation-fixtures';
import uiConstants from '../../ui-constants';
import rootThreadFactory from '../root-thread';
import { $imports } from '../root-thread';
import immutable from '../../util/immutable';
const fixtures = immutable({
emptyThread: {
......
......@@ -15,11 +15,11 @@
*/
import { createSelector } from 'reselect';
import immutable from 'seamless-immutable';
import uiConstants from '../../ui-constants';
import * as metadata from '../../util/annotation-metadata';
import { countIf, toSet } from '../../util/array';
import immutable from '../../util/immutable';
import * as util from '../util';
/**
......
import immutable from 'seamless-immutable';
import createStore from '../../create-store';
import annotations from '../annotations';
import drafts from '../drafts';
import { Draft } from '../drafts';
import selection from '../selection';
import immutable from '../../../util/immutable';
const fixtures = immutable({
draftWithText: {
......
import immutable from 'seamless-immutable';
import createStore from '../../create-store';
import groups from '../groups';
import session from '../session';
import immutable from '../../../util/immutable';
describe('sidebar/store/modules/groups', () => {
const publicGroup = immutable({
......
import immutable from 'seamless-immutable';
import * as annotationFixtures from '../../test/annotation-fixtures';
import uiConstants from '../../ui-constants';
import storeFactory from '../index';
import immutable from '../../util/immutable';
const defaultAnnotation = annotationFixtures.defaultAnnotation;
const newAnnotation = annotationFixtures.newAnnotation;
......
import angular from 'angular';
import immutable from 'seamless-immutable';
import rootThreadFactory from '../../services/root-thread';
import searchFilterFactory from '../../services/search-filter';
import viewFilterFactory from '../../services/view-filter';
import storeFactory from '../../store';
import immutable from '../../util/immutable';
const fixtures = immutable({
annotations: [
......
import immutable from 'seamless-immutable';
import immutable from './immutable';
// TODO: Update when this is a property available on the API response
const DEFAULT_ORG_ID = '__default__';
......
/* global process */
/**
* Freeze an object recursively.
*
* This only works for plain objects, arrays and objects where data is stored
* in enumerable fields.
*/
function deepFreeze(object) {
Object.freeze(object);
Object.values(object).forEach(val => {
if (typeof val === 'object' && val !== null) {
deepFreeze(val);
}
});
return object;
}
/**
* Prevent accidental mutations to `object` or any of its fields in debug builds.
*
* @param {Object} object
* @return {Object} Returns the input object
*/
export default function immutable(object) {
if (process.env.NODE_ENV === 'production') {
return object;
} else {
return deepFreeze(object);
}
}
import immutable from '../immutable';
describe('immutable', () => {
it('deeply freezes objects', () => {
const obj = {
plainValue: 'plain',
objectValue: {
leafValue: 'leaf',
},
arrayValue: [1],
};
const result = immutable(obj);
assert.equal(result, obj);
assert.isTrue(Object.isFrozen(obj));
assert.isTrue(Object.isFrozen(obj.objectValue));
assert.isTrue(Object.isFrozen(obj.arrayValue));
});
});
......@@ -7015,11 +7015,6 @@ scroll-into-view@^1.8.2:
resolved "https://registry.yarnpkg.com/scroll-into-view/-/scroll-into-view-1.14.1.tgz#ca8e152228088d50fca7a266d3757141ba917fa2"
integrity sha512-50Ynbg3igEFY2bCa5Iv4H+t9dqCmG+Y10LnaaSIjPR13+KFtvFRr+Wmq0foGoyJmn8K+8My+ZFbEIZ2JUorxcA==
seamless-immutable@^7.1.4:
version "7.1.4"
resolved "https://registry.yarnpkg.com/seamless-immutable/-/seamless-immutable-7.1.4.tgz#6e9536def083ddc4dea0207d722e0e80d0f372f8"
integrity sha512-XiUO1QP4ki4E2PHegiGAlu6r82o5A+6tRh7IkGGTVg/h+UoeX4nFBeCGPOhb4CYjvkqsfm/TUtvOMYC1xmV30A==
semver-greatest-satisfied-range@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/semver-greatest-satisfied-range/-/semver-greatest-satisfied-range-1.1.0.tgz#13e8c2658ab9691cb0cd71093240280d36f77a5b"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment