@bizjournals/js-storage 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  import StorageAbstract from '../';
2
2
  import mockStorage from '../__mocks__/mock-storage';
3
+ import store from '../store';
3
4
 
4
5
  describe('core:class >> storageabstract:issupported', () => {
5
6
  let storageAbstract;
@@ -10,7 +11,7 @@ describe('core:class >> storageabstract:issupported', () => {
10
11
  mockStorage.removeItem.mockClear();
11
12
 
12
13
  storageAbstract.storage = mockStorage;
13
- StorageAbstract.supported = undefined;
14
+ store.supported = undefined;
14
15
  });
15
16
 
16
17
  it('returns false when the storage system is defaulted', () => {
@@ -1,5 +1,7 @@
1
1
  import StorageAbstract from '../';
2
2
 
3
+ import store from '../store';
4
+
3
5
  describe('core:class >> storageabstract:removeitem', () => {
4
6
  let storageClassMock, mockStorage, key = 'test';
5
7
 
@@ -20,7 +22,7 @@ describe('core:class >> storageabstract:removeitem', () => {
20
22
  };
21
23
 
22
24
  storageClassMock.storage = mockStorage;
23
- StorageAbstract.supported = undefined;
25
+ store.supported = undefined;
24
26
  });
25
27
 
26
28
  it('halts when it is not supported', () => {
@@ -33,7 +35,7 @@ describe('core:class >> storageabstract:removeitem', () => {
33
35
  });
34
36
 
35
37
  it('falls through when encountering an exception', () => {
36
- StorageAbstract.supported = true;
38
+ store.supported = true;
37
39
 
38
40
  const badStorage = {
39
41
  removeItem: jest.fn().mockImplementation(() => {
@@ -51,7 +53,7 @@ describe('core:class >> storageabstract:removeitem', () => {
51
53
  });
52
54
 
53
55
  it('removes both the item at namespace and expiration keys', () => {
54
- StorageAbstract.supported = true;
56
+ store.supported = true;
55
57
  storageClassMock.removeItem();
56
58
 
57
59
  expect(storageClassMock.namespaceKey).toHaveBeenCalledTimes(1);
@@ -1,4 +1,5 @@
1
1
  import StorageAbstract from '../';
2
+ import store from '../store';
2
3
 
3
4
  describe('core:class >> storageabstract:setitem', () => {
4
5
  let storageClassMock, mockStorage, key = 'test';
@@ -26,7 +27,7 @@ describe('core:class >> storageabstract:setitem', () => {
26
27
 
27
28
  storageClassMock.attempts = 0;
28
29
  storageClassMock.storage = mockStorage;
29
- StorageAbstract.supported = undefined;
30
+ store.supported = undefined;
30
31
  });
31
32
 
32
33
  it('resets the attempts and returns when it is not supported without continuing', () => {
@@ -1,5 +1,6 @@
1
1
  import { DEFAULT_EXPIRATION, DEFAULT_NAMESPACE, EXPIRES_KEY_SUFFIX } from "./constants";
2
2
  import { KEY_IS_REQUIRED_TO_FETCH_DATA } from "./exceptions";
3
+ import store from './store';
3
4
 
4
5
  /*
5
6
  |--------------------------------------------------------------------------
@@ -12,13 +13,6 @@ import { KEY_IS_REQUIRED_TO_FETCH_DATA } from "./exceptions";
12
13
  |
13
14
  */
14
15
  export default class StorageAbstract {
15
- /**
16
- * Extensions to this abstraction share an enabled state.
17
- *
18
- * @type {boolean}
19
- */
20
- static supported;
21
-
22
16
  /**
23
17
  * Constructor takes in options for namespace and expiration.
24
18
  * Session storage is the default storage type.
@@ -230,8 +224,8 @@ export default class StorageAbstract {
230
224
  * @returns {boolean}
231
225
  */
232
226
  isSupported () {
233
- if (typeof StorageAbstract.supported === "boolean") {
234
- return StorageAbstract.supported;
227
+ if (typeof store.supported === "boolean") {
228
+ return store.supported;
235
229
  }
236
230
 
237
231
  const test = 'biz.storage.test';
@@ -240,9 +234,9 @@ export default class StorageAbstract {
240
234
  this.storage.setItem(test, '1');
241
235
  this.storage.removeItem(test);
242
236
 
243
- StorageAbstract.supported = true;
237
+ store.supported = true;
244
238
  } catch (e) {
245
- StorageAbstract.supported = e instanceof DOMException &&
239
+ store.supported = e instanceof DOMException &&
246
240
  (
247
241
  // everything except Firefox
248
242
  e.code === 22 ||
@@ -256,6 +250,6 @@ export default class StorageAbstract {
256
250
  ) && (this.storage && this.storage.length !== 0);
257
251
  }
258
252
 
259
- return StorageAbstract.supported;
253
+ return store.supported;
260
254
  }
261
255
  }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The data store for global variables
3
+ *
4
+ */
5
+ const store = {
6
+ supported: null,
7
+ }
8
+
9
+ // --
10
+ export default store;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bizjournals/js-storage",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "ACBJ javascript storage classes",
5
5
  "repository": {
6
6
  "git": "https://gitlab.bizjournals.com/bizjournals/js-storage"