@miniplex/bucket
Advanced tools
Comparing version 0.0.0-canary-20221029092412 to 2.0.0-beta.1
import { Event } from "@hmans/event"; | ||
export declare type Predicate<E, D extends E> = ((v: E) => v is D) | ((entity: E) => boolean); | ||
export declare class Bucket<E> { | ||
/** | ||
* A class wrapping an array of entities of a specific type, providing | ||
* performance-optimized methods for adding, looking up and removing entities, and events | ||
* for when entities are added or removed. | ||
*/ | ||
export declare class Bucket<E> implements Iterable<E> { | ||
entities: E[]; | ||
@@ -12,12 +16,46 @@ [Symbol.iterator](): { | ||
constructor(entities?: E[]); | ||
/** | ||
* Fired when an entity has been added to the bucket. | ||
*/ | ||
onEntityAdded: Event<E>; | ||
/** | ||
* Fired when an entity is about to be removed from the bucket. | ||
*/ | ||
onEntityRemoved: Event<E>; | ||
/** | ||
* A map of entity positions, used for fast lookups. | ||
*/ | ||
private entityPositions; | ||
/** | ||
* Returns the total size of the bucket, i.e. the number of entities it contains. | ||
*/ | ||
get size(): number; | ||
/** | ||
* Returns true if the bucket contains the given entity. | ||
* | ||
* @param entity The entity to check for. | ||
* @returns `true` if the specificed entity is in this bucket, `false` otherwise. | ||
*/ | ||
has(entity: any): entity is E; | ||
/** | ||
* Adds the given entity to the bucket. If the entity is already in the bucket, it is | ||
* not added again. | ||
* | ||
* @param entity The entity to add to the bucket. | ||
* @returns The entity passed into this function (regardless of whether it was added or not). | ||
*/ | ||
add<D extends E>(entity: D): D & E; | ||
/** | ||
* Removes the given entity from the bucket. If the entity is not in the bucket, nothing | ||
* happens. | ||
* | ||
* @param entity The entity to remove from the bucket. | ||
* @returns The entity passed into this function (regardless of whether it was removed or not). | ||
*/ | ||
remove(entity: E): E; | ||
/** | ||
* Removes all entities from the bucket. Will cause the `onEntityRemoved` event to be | ||
* fired for each entity. | ||
*/ | ||
clear(): void; | ||
derivedBuckets: Map<Predicate<E, any>, Bucket<any>>; | ||
where<D extends E>(predicate: Predicate<E, D>): Bucket<D>; | ||
} |
@@ -7,31 +7,2 @@ 'use strict'; | ||
function _arrayWithHoles(arr) { | ||
if (Array.isArray(arr)) return arr; | ||
} | ||
function _iterableToArrayLimit(arr, i) { | ||
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; | ||
if (_i == null) return; | ||
var _arr = []; | ||
var _n = true; | ||
var _d = false; | ||
var _s, _e; | ||
try { | ||
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { | ||
_arr.push(_s.value); | ||
if (i && _arr.length === i) break; | ||
} | ||
} catch (err) { | ||
_d = true; | ||
_e = err; | ||
} finally { | ||
try { | ||
if (!_n && _i["return"] != null) _i["return"](); | ||
} finally { | ||
if (_d) throw _e; | ||
} | ||
} | ||
return _arr; | ||
} | ||
function _arrayLikeToArray(arr, len) { | ||
@@ -52,10 +23,2 @@ if (len == null || len > arr.length) len = arr.length; | ||
function _nonIterableRest() { | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
function _slicedToArray(arr, i) { | ||
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); | ||
} | ||
function _createForOfIteratorHelper(o, allowArrayLike) { | ||
@@ -152,2 +115,8 @@ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; | ||
var _Symbol$iterator; | ||
/** | ||
* A class wrapping an array of entities of a specific type, providing | ||
* performance-optimized methods for adding, looking up and removing entities, and events | ||
* for when entities are added or removed. | ||
*/ | ||
_Symbol$iterator = Symbol.iterator; | ||
@@ -161,17 +130,30 @@ var Bucket = /*#__PURE__*/function () { | ||
_defineProperty(this, "entityPositions", new Map()); | ||
_defineProperty(this, "derivedBuckets", new Map()); | ||
this.entities = entities; | ||
this.add = this.add.bind(this); | ||
this.remove = this.remove.bind(this); | ||
/* Register all entity positions */ | ||
for (var i = 0; i < entities.length; i++) { | ||
this.entityPositions.set(entities[i], i); | ||
} | ||
} | ||
/** | ||
* Fired when an entity has been added to the bucket. | ||
*/ | ||
_createClass(Bucket, [{ | ||
key: _Symbol$iterator, | ||
value: function value() { | ||
value: /* Custom iterator that iterates over all entities in reverse order. */ | ||
function value() { | ||
var _this = this; | ||
var index = this.entities.length; | ||
var result = { | ||
value: undefined, | ||
done: false | ||
}; | ||
return { | ||
next: function next() { | ||
var value = _this.entities[--index]; | ||
return { | ||
value: value, | ||
done: index < 0 | ||
}; | ||
result.value = _this.entities[--index]; | ||
result.done = index < 0; | ||
return result; | ||
} | ||
@@ -182,5 +164,16 @@ }; | ||
key: "size", | ||
get: function get() { | ||
get: | ||
/** | ||
* Returns the total size of the bucket, i.e. the number of entities it contains. | ||
*/ | ||
function get() { | ||
return this.entities.length; | ||
} | ||
/** | ||
* Returns true if the bucket contains the given entity. | ||
* | ||
* @param entity The entity to check for. | ||
* @returns `true` if the specificed entity is in this bucket, `false` otherwise. | ||
*/ | ||
}, { | ||
@@ -191,2 +184,10 @@ key: "has", | ||
} | ||
/** | ||
* Adds the given entity to the bucket. If the entity is already in the bucket, it is | ||
* not added again. | ||
* | ||
* @param entity The entity to add to the bucket. | ||
* @returns The entity passed into this function (regardless of whether it was added or not). | ||
*/ | ||
}, { | ||
@@ -201,23 +202,13 @@ key: "add", | ||
this.onEntityAdded.emit(entity); | ||
/* Add the entity to any derived buckets. */ | ||
var _iterator = _createForOfIteratorHelper(this.derivedBuckets), | ||
_step; | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var _step$value = _slicedToArray(_step.value, 2), | ||
predicate = _step$value[0], | ||
bucket = _step$value[1]; | ||
if (predicate(entity)) { | ||
bucket.add(entity); | ||
} | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
} | ||
return entity; | ||
} | ||
/** | ||
* Removes the given entity from the bucket. If the entity is not in the bucket, nothing | ||
* happens. | ||
* | ||
* @param entity The entity to remove from the bucket. | ||
* @returns The entity passed into this function (regardless of whether it was removed or not). | ||
*/ | ||
}, { | ||
@@ -227,3 +218,10 @@ key: "remove", | ||
if (this.has(entity)) { | ||
/* Emit our own onEntityRemoved event. */ | ||
this.onEntityRemoved.emit(entity); | ||
/* Get the entity's current position. */ | ||
var index = this.entityPositions.get(entity); | ||
this.entityPositions["delete"](entity); | ||
/* Perform shuffle-pop if there is more than one entity. */ | ||
var other = this.entities[this.entities.length - 1]; | ||
@@ -234,64 +232,29 @@ if (other !== entity) { | ||
} | ||
/* Remove the entity from the entities array. */ | ||
this.entities.pop(); | ||
this.entityPositions["delete"](entity); | ||
/* Remove the entity from any derived buckets. */ | ||
var _iterator2 = _createForOfIteratorHelper(this.derivedBuckets.values()), | ||
_step2; | ||
try { | ||
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { | ||
var query = _step2.value; | ||
query.remove(entity); | ||
} | ||
/* Emit our own onEntityRemoved event. */ | ||
} catch (err) { | ||
_iterator2.e(err); | ||
} finally { | ||
_iterator2.f(); | ||
} | ||
this.onEntityRemoved.emit(entity); | ||
} | ||
return entity; | ||
} | ||
/** | ||
* Removes all entities from the bucket. Will cause the `onEntityRemoved` event to be | ||
* fired for each entity. | ||
*/ | ||
}, { | ||
key: "clear", | ||
value: function clear() { | ||
var _iterator3 = _createForOfIteratorHelper(this), | ||
_step3; | ||
var _iterator = _createForOfIteratorHelper(this), | ||
_step; | ||
try { | ||
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { | ||
var _entity = _step3.value; | ||
this.remove(_entity); | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var entity = _step.value; | ||
this.remove(entity); | ||
} | ||
} catch (err) { | ||
_iterator3.e(err); | ||
_iterator.e(err); | ||
} finally { | ||
_iterator3.f(); | ||
_iterator.f(); | ||
} | ||
} | ||
}, { | ||
key: "where", | ||
value: function where(predicate) { | ||
if (this.derivedBuckets.has(predicate)) { | ||
return this.derivedBuckets.get(predicate); | ||
} | ||
var bucket = new Bucket(); | ||
this.derivedBuckets.set(predicate, bucket); | ||
var _iterator4 = _createForOfIteratorHelper(this.entities), | ||
_step4; | ||
try { | ||
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) { | ||
var _entity2 = _step4.value; | ||
if (predicate(_entity2)) { | ||
bucket.add(_entity2); | ||
} | ||
} | ||
} catch (err) { | ||
_iterator4.e(err); | ||
} finally { | ||
_iterator4.f(); | ||
} | ||
return bucket; | ||
} | ||
}]); | ||
@@ -298,0 +261,0 @@ return Bucket; |
@@ -7,31 +7,2 @@ 'use strict'; | ||
function _arrayWithHoles(arr) { | ||
if (Array.isArray(arr)) return arr; | ||
} | ||
function _iterableToArrayLimit(arr, i) { | ||
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; | ||
if (_i == null) return; | ||
var _arr = []; | ||
var _n = true; | ||
var _d = false; | ||
var _s, _e; | ||
try { | ||
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { | ||
_arr.push(_s.value); | ||
if (i && _arr.length === i) break; | ||
} | ||
} catch (err) { | ||
_d = true; | ||
_e = err; | ||
} finally { | ||
try { | ||
if (!_n && _i["return"] != null) _i["return"](); | ||
} finally { | ||
if (_d) throw _e; | ||
} | ||
} | ||
return _arr; | ||
} | ||
function _arrayLikeToArray(arr, len) { | ||
@@ -52,10 +23,2 @@ if (len == null || len > arr.length) len = arr.length; | ||
function _nonIterableRest() { | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
function _slicedToArray(arr, i) { | ||
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); | ||
} | ||
function _createForOfIteratorHelper(o, allowArrayLike) { | ||
@@ -152,2 +115,8 @@ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; | ||
var _Symbol$iterator; | ||
/** | ||
* A class wrapping an array of entities of a specific type, providing | ||
* performance-optimized methods for adding, looking up and removing entities, and events | ||
* for when entities are added or removed. | ||
*/ | ||
_Symbol$iterator = Symbol.iterator; | ||
@@ -161,17 +130,30 @@ var Bucket = /*#__PURE__*/function () { | ||
_defineProperty(this, "entityPositions", new Map()); | ||
_defineProperty(this, "derivedBuckets", new Map()); | ||
this.entities = entities; | ||
this.add = this.add.bind(this); | ||
this.remove = this.remove.bind(this); | ||
/* Register all entity positions */ | ||
for (var i = 0; i < entities.length; i++) { | ||
this.entityPositions.set(entities[i], i); | ||
} | ||
} | ||
/** | ||
* Fired when an entity has been added to the bucket. | ||
*/ | ||
_createClass(Bucket, [{ | ||
key: _Symbol$iterator, | ||
value: function value() { | ||
value: /* Custom iterator that iterates over all entities in reverse order. */ | ||
function value() { | ||
var _this = this; | ||
var index = this.entities.length; | ||
var result = { | ||
value: undefined, | ||
done: false | ||
}; | ||
return { | ||
next: function next() { | ||
var value = _this.entities[--index]; | ||
return { | ||
value: value, | ||
done: index < 0 | ||
}; | ||
result.value = _this.entities[--index]; | ||
result.done = index < 0; | ||
return result; | ||
} | ||
@@ -182,5 +164,16 @@ }; | ||
key: "size", | ||
get: function get() { | ||
get: | ||
/** | ||
* Returns the total size of the bucket, i.e. the number of entities it contains. | ||
*/ | ||
function get() { | ||
return this.entities.length; | ||
} | ||
/** | ||
* Returns true if the bucket contains the given entity. | ||
* | ||
* @param entity The entity to check for. | ||
* @returns `true` if the specificed entity is in this bucket, `false` otherwise. | ||
*/ | ||
}, { | ||
@@ -191,2 +184,10 @@ key: "has", | ||
} | ||
/** | ||
* Adds the given entity to the bucket. If the entity is already in the bucket, it is | ||
* not added again. | ||
* | ||
* @param entity The entity to add to the bucket. | ||
* @returns The entity passed into this function (regardless of whether it was added or not). | ||
*/ | ||
}, { | ||
@@ -201,23 +202,13 @@ key: "add", | ||
this.onEntityAdded.emit(entity); | ||
/* Add the entity to any derived buckets. */ | ||
var _iterator = _createForOfIteratorHelper(this.derivedBuckets), | ||
_step; | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var _step$value = _slicedToArray(_step.value, 2), | ||
predicate = _step$value[0], | ||
bucket = _step$value[1]; | ||
if (predicate(entity)) { | ||
bucket.add(entity); | ||
} | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
} | ||
return entity; | ||
} | ||
/** | ||
* Removes the given entity from the bucket. If the entity is not in the bucket, nothing | ||
* happens. | ||
* | ||
* @param entity The entity to remove from the bucket. | ||
* @returns The entity passed into this function (regardless of whether it was removed or not). | ||
*/ | ||
}, { | ||
@@ -227,3 +218,10 @@ key: "remove", | ||
if (this.has(entity)) { | ||
/* Emit our own onEntityRemoved event. */ | ||
this.onEntityRemoved.emit(entity); | ||
/* Get the entity's current position. */ | ||
var index = this.entityPositions.get(entity); | ||
this.entityPositions["delete"](entity); | ||
/* Perform shuffle-pop if there is more than one entity. */ | ||
var other = this.entities[this.entities.length - 1]; | ||
@@ -234,64 +232,29 @@ if (other !== entity) { | ||
} | ||
/* Remove the entity from the entities array. */ | ||
this.entities.pop(); | ||
this.entityPositions["delete"](entity); | ||
/* Remove the entity from any derived buckets. */ | ||
var _iterator2 = _createForOfIteratorHelper(this.derivedBuckets.values()), | ||
_step2; | ||
try { | ||
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { | ||
var query = _step2.value; | ||
query.remove(entity); | ||
} | ||
/* Emit our own onEntityRemoved event. */ | ||
} catch (err) { | ||
_iterator2.e(err); | ||
} finally { | ||
_iterator2.f(); | ||
} | ||
this.onEntityRemoved.emit(entity); | ||
} | ||
return entity; | ||
} | ||
/** | ||
* Removes all entities from the bucket. Will cause the `onEntityRemoved` event to be | ||
* fired for each entity. | ||
*/ | ||
}, { | ||
key: "clear", | ||
value: function clear() { | ||
var _iterator3 = _createForOfIteratorHelper(this), | ||
_step3; | ||
var _iterator = _createForOfIteratorHelper(this), | ||
_step; | ||
try { | ||
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { | ||
var _entity = _step3.value; | ||
this.remove(_entity); | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var entity = _step.value; | ||
this.remove(entity); | ||
} | ||
} catch (err) { | ||
_iterator3.e(err); | ||
_iterator.e(err); | ||
} finally { | ||
_iterator3.f(); | ||
_iterator.f(); | ||
} | ||
} | ||
}, { | ||
key: "where", | ||
value: function where(predicate) { | ||
if (this.derivedBuckets.has(predicate)) { | ||
return this.derivedBuckets.get(predicate); | ||
} | ||
var bucket = new Bucket(); | ||
this.derivedBuckets.set(predicate, bucket); | ||
var _iterator4 = _createForOfIteratorHelper(this.entities), | ||
_step4; | ||
try { | ||
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) { | ||
var _entity2 = _step4.value; | ||
if (predicate(_entity2)) { | ||
bucket.add(_entity2); | ||
} | ||
} | ||
} catch (err) { | ||
_iterator4.e(err); | ||
} finally { | ||
_iterator4.f(); | ||
} | ||
return bucket; | ||
} | ||
}]); | ||
@@ -298,0 +261,0 @@ return Bucket; |
import { Event } from '@hmans/event'; | ||
function _arrayWithHoles(arr) { | ||
if (Array.isArray(arr)) return arr; | ||
} | ||
function _iterableToArrayLimit(arr, i) { | ||
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; | ||
if (_i == null) return; | ||
var _arr = []; | ||
var _n = true; | ||
var _d = false; | ||
var _s, _e; | ||
try { | ||
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { | ||
_arr.push(_s.value); | ||
if (i && _arr.length === i) break; | ||
} | ||
} catch (err) { | ||
_d = true; | ||
_e = err; | ||
} finally { | ||
try { | ||
if (!_n && _i["return"] != null) _i["return"](); | ||
} finally { | ||
if (_d) throw _e; | ||
} | ||
} | ||
return _arr; | ||
} | ||
function _arrayLikeToArray(arr, len) { | ||
@@ -47,10 +18,2 @@ if (len == null || len > arr.length) len = arr.length; | ||
function _nonIterableRest() { | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); | ||
} | ||
function _slicedToArray(arr, i) { | ||
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); | ||
} | ||
function _createForOfIteratorHelper(o, allowArrayLike) { | ||
@@ -147,2 +110,8 @@ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; | ||
var _Symbol$iterator; | ||
/** | ||
* A class wrapping an array of entities of a specific type, providing | ||
* performance-optimized methods for adding, looking up and removing entities, and events | ||
* for when entities are added or removed. | ||
*/ | ||
_Symbol$iterator = Symbol.iterator; | ||
@@ -156,17 +125,30 @@ var Bucket = /*#__PURE__*/function () { | ||
_defineProperty(this, "entityPositions", new Map()); | ||
_defineProperty(this, "derivedBuckets", new Map()); | ||
this.entities = entities; | ||
this.add = this.add.bind(this); | ||
this.remove = this.remove.bind(this); | ||
/* Register all entity positions */ | ||
for (var i = 0; i < entities.length; i++) { | ||
this.entityPositions.set(entities[i], i); | ||
} | ||
} | ||
/** | ||
* Fired when an entity has been added to the bucket. | ||
*/ | ||
_createClass(Bucket, [{ | ||
key: _Symbol$iterator, | ||
value: function value() { | ||
value: /* Custom iterator that iterates over all entities in reverse order. */ | ||
function value() { | ||
var _this = this; | ||
var index = this.entities.length; | ||
var result = { | ||
value: undefined, | ||
done: false | ||
}; | ||
return { | ||
next: function next() { | ||
var value = _this.entities[--index]; | ||
return { | ||
value: value, | ||
done: index < 0 | ||
}; | ||
result.value = _this.entities[--index]; | ||
result.done = index < 0; | ||
return result; | ||
} | ||
@@ -177,5 +159,16 @@ }; | ||
key: "size", | ||
get: function get() { | ||
get: | ||
/** | ||
* Returns the total size of the bucket, i.e. the number of entities it contains. | ||
*/ | ||
function get() { | ||
return this.entities.length; | ||
} | ||
/** | ||
* Returns true if the bucket contains the given entity. | ||
* | ||
* @param entity The entity to check for. | ||
* @returns `true` if the specificed entity is in this bucket, `false` otherwise. | ||
*/ | ||
}, { | ||
@@ -186,2 +179,10 @@ key: "has", | ||
} | ||
/** | ||
* Adds the given entity to the bucket. If the entity is already in the bucket, it is | ||
* not added again. | ||
* | ||
* @param entity The entity to add to the bucket. | ||
* @returns The entity passed into this function (regardless of whether it was added or not). | ||
*/ | ||
}, { | ||
@@ -196,23 +197,13 @@ key: "add", | ||
this.onEntityAdded.emit(entity); | ||
/* Add the entity to any derived buckets. */ | ||
var _iterator = _createForOfIteratorHelper(this.derivedBuckets), | ||
_step; | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var _step$value = _slicedToArray(_step.value, 2), | ||
predicate = _step$value[0], | ||
bucket = _step$value[1]; | ||
if (predicate(entity)) { | ||
bucket.add(entity); | ||
} | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
} | ||
return entity; | ||
} | ||
/** | ||
* Removes the given entity from the bucket. If the entity is not in the bucket, nothing | ||
* happens. | ||
* | ||
* @param entity The entity to remove from the bucket. | ||
* @returns The entity passed into this function (regardless of whether it was removed or not). | ||
*/ | ||
}, { | ||
@@ -222,3 +213,10 @@ key: "remove", | ||
if (this.has(entity)) { | ||
/* Emit our own onEntityRemoved event. */ | ||
this.onEntityRemoved.emit(entity); | ||
/* Get the entity's current position. */ | ||
var index = this.entityPositions.get(entity); | ||
this.entityPositions["delete"](entity); | ||
/* Perform shuffle-pop if there is more than one entity. */ | ||
var other = this.entities[this.entities.length - 1]; | ||
@@ -229,64 +227,29 @@ if (other !== entity) { | ||
} | ||
/* Remove the entity from the entities array. */ | ||
this.entities.pop(); | ||
this.entityPositions["delete"](entity); | ||
/* Remove the entity from any derived buckets. */ | ||
var _iterator2 = _createForOfIteratorHelper(this.derivedBuckets.values()), | ||
_step2; | ||
try { | ||
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { | ||
var query = _step2.value; | ||
query.remove(entity); | ||
} | ||
/* Emit our own onEntityRemoved event. */ | ||
} catch (err) { | ||
_iterator2.e(err); | ||
} finally { | ||
_iterator2.f(); | ||
} | ||
this.onEntityRemoved.emit(entity); | ||
} | ||
return entity; | ||
} | ||
/** | ||
* Removes all entities from the bucket. Will cause the `onEntityRemoved` event to be | ||
* fired for each entity. | ||
*/ | ||
}, { | ||
key: "clear", | ||
value: function clear() { | ||
var _iterator3 = _createForOfIteratorHelper(this), | ||
_step3; | ||
var _iterator = _createForOfIteratorHelper(this), | ||
_step; | ||
try { | ||
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) { | ||
var _entity = _step3.value; | ||
this.remove(_entity); | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var entity = _step.value; | ||
this.remove(entity); | ||
} | ||
} catch (err) { | ||
_iterator3.e(err); | ||
_iterator.e(err); | ||
} finally { | ||
_iterator3.f(); | ||
_iterator.f(); | ||
} | ||
} | ||
}, { | ||
key: "where", | ||
value: function where(predicate) { | ||
if (this.derivedBuckets.has(predicate)) { | ||
return this.derivedBuckets.get(predicate); | ||
} | ||
var bucket = new Bucket(); | ||
this.derivedBuckets.set(predicate, bucket); | ||
var _iterator4 = _createForOfIteratorHelper(this.entities), | ||
_step4; | ||
try { | ||
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) { | ||
var _entity2 = _step4.value; | ||
if (predicate(_entity2)) { | ||
bucket.add(_entity2); | ||
} | ||
} | ||
} catch (err) { | ||
_iterator4.e(err); | ||
} finally { | ||
_iterator4.f(); | ||
} | ||
return bucket; | ||
} | ||
}]); | ||
@@ -293,0 +256,0 @@ return Bucket; |
@@ -18,3 +18,3 @@ { | ||
"sideEffects": false, | ||
"version": "0.0.0-canary-20221029092412", | ||
"version": "2.0.0-beta.1", | ||
"main": "dist/miniplex-bucket.cjs.js", | ||
@@ -33,3 +33,3 @@ "module": "dist/miniplex-bucket.esm.js", | ||
"devDependencies": { | ||
"@types/node": "^18.11.0", | ||
"@types/node": "^18.11.9", | ||
"ts-node": "^10.9.1", | ||
@@ -36,0 +36,0 @@ "typescript": "^4.8.4" |
@@ -1,1 +0,1 @@ | ||
# Bucketeer | ||
# @miniplex/bucket |
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
25797
768