@uppy/store-default
Advanced tools
Comparing version 3.0.0-beta.1 to 3.0.0-beta.2
# @uppy/store-default | ||
## 3.0.0-beta.2 | ||
Released: 2022-08-03 | ||
Included in: Uppy v3.0.0-beta.4 | ||
- @uppy/store-default: export the class, don't expose `.callbacks` (Antoine du Hamel / #3928) | ||
## 2.1.0 | ||
@@ -4,0 +11,0 @@ |
@@ -8,3 +8,3 @@ function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; } | ||
const packageJson = { | ||
"version": "3.0.0-beta.1" | ||
"version": "3.0.0-beta.2" | ||
}; | ||
@@ -15,2 +15,4 @@ /** | ||
var _callbacks = /*#__PURE__*/_classPrivateFieldLooseKey("callbacks"); | ||
var _publish = /*#__PURE__*/_classPrivateFieldLooseKey("publish"); | ||
@@ -23,4 +25,7 @@ | ||
}); | ||
Object.defineProperty(this, _callbacks, { | ||
writable: true, | ||
value: new Set() | ||
}); | ||
this.state = {}; | ||
this.callbacks = []; // TODO: use a Set instead, make it a private prop | ||
} | ||
@@ -44,12 +49,11 @@ | ||
subscribe(listener) { | ||
this.callbacks.push(listener); | ||
_classPrivateFieldLooseBase(this, _callbacks)[_callbacks].add(listener); | ||
return () => { | ||
// Remove the listener. | ||
this.callbacks.splice(this.callbacks.indexOf(listener), 1); | ||
_classPrivateFieldLooseBase(this, _callbacks)[_callbacks].delete(listener); | ||
}; | ||
} | ||
} // TODO: export the class instead in the next major. | ||
} | ||
function _publish2() { | ||
@@ -60,3 +64,3 @@ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
this.callbacks.forEach(listener => { | ||
_classPrivateFieldLooseBase(this, _callbacks)[_callbacks].forEach(listener => { | ||
listener(...args); | ||
@@ -67,4 +71,2 @@ }); | ||
DefaultStore.VERSION = packageJson.version; | ||
export default function defaultStore() { | ||
return new DefaultStore(); | ||
} | ||
export default DefaultStore; |
{ | ||
"name": "@uppy/store-default", | ||
"description": "The default simple object-based store for Uppy.", | ||
"version": "3.0.0-beta.1", | ||
"version": "3.0.0-beta.2", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "main": "lib/index.js", |
@@ -21,3 +21,3 @@ # @uppy/store-default | ||
const uppy = new Uppy({ | ||
store: DefaultStore(), | ||
store: new DefaultStore(), | ||
}) | ||
@@ -24,0 +24,0 @@ ``` |
@@ -8,5 +8,6 @@ import packageJson from '../package.json' | ||
#callbacks = new Set() | ||
constructor () { | ||
this.state = {} | ||
this.callbacks = [] // TODO: use a Set instead, make it a private prop | ||
} | ||
@@ -27,9 +28,5 @@ | ||
subscribe (listener) { | ||
this.callbacks.push(listener) | ||
this.#callbacks.add(listener) | ||
return () => { | ||
// Remove the listener. | ||
this.callbacks.splice( | ||
this.callbacks.indexOf(listener), | ||
1, | ||
) | ||
this.#callbacks.delete(listener) | ||
} | ||
@@ -39,3 +36,3 @@ } | ||
#publish (...args) { | ||
this.callbacks.forEach((listener) => { | ||
this.#callbacks.forEach((listener) => { | ||
listener(...args) | ||
@@ -46,5 +43,2 @@ }) | ||
// TODO: export the class instead in the next major. | ||
export default function defaultStore () { | ||
return new DefaultStore() | ||
} | ||
export default DefaultStore |
import { describe, expect, it } from '@jest/globals' | ||
import assert from 'node:assert' | ||
import DefaultStore from './index.js' | ||
describe('DefaultStore', () => { | ||
it('can be created with or without new', () => { | ||
let store = DefaultStore() | ||
expect(typeof store).toBe('object') | ||
store = new DefaultStore() | ||
expect(typeof store).toBe('object') | ||
it('cannot be created without new', () => { | ||
assert.throws(() => DefaultStore(), /TypeError/) | ||
}) | ||
it('merges in state using `setState`', () => { | ||
const store = DefaultStore() | ||
const store = new DefaultStore() | ||
expect(store.getState()).toEqual({}) | ||
@@ -34,3 +32,3 @@ | ||
const store = DefaultStore() | ||
const store = new DefaultStore() | ||
store.subscribe(listener) | ||
@@ -37,0 +35,0 @@ |
@@ -6,3 +6,3 @@ import type { Store } from '@uppy/utils' | ||
declare class DefaultStore implements Store { | ||
export default class DefaultStore implements Store { | ||
constructor () | ||
@@ -16,5 +16,1 @@ | ||
} | ||
declare function createDefaultStore (): DefaultStore | ||
export default createDefaultStore |
import DefaultStore from '..' | ||
const store = DefaultStore() | ||
const store = new DefaultStore() | ||
store.setState({ a: 'b' }) | ||
store.getState() |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9855
132