@miniplex/bucket
Advanced tools
Comparing version 2.0.0-beta.3 to 2.0.0-beta.4
@@ -1,2 +0,2 @@ | ||
import { Event } from "@hmans/event"; | ||
import { Event } from "eventery"; | ||
/** | ||
@@ -8,3 +8,4 @@ * A class wrapping an array of entities of a specific type, providing | ||
export declare class Bucket<E> implements Iterable<E> { | ||
entities: E[]; | ||
protected _entities: E[]; | ||
get entities(): E[]; | ||
[Symbol.iterator](): { | ||
@@ -16,11 +17,11 @@ next: () => { | ||
}; | ||
constructor(entities?: E[]); | ||
constructor(_entities?: E[]); | ||
/** | ||
* Fired when an entity has been added to the bucket. | ||
*/ | ||
onEntityAdded: Event<E>; | ||
onEntityAdded: Event<[entity: E]>; | ||
/** | ||
* Fired when an entity is about to be removed from the bucket. | ||
*/ | ||
onEntityRemoved: Event<E>; | ||
onEntityRemoved: Event<[entity: E]>; | ||
/** | ||
@@ -27,0 +28,0 @@ * A map of entity positions, used for fast lookups. |
@@ -1,1 +0,1 @@ | ||
export * from "./Bucket"; | ||
export * from "./Bucket.js"; |
export * from "./declarations/src/index"; | ||
//# sourceMappingURL=miniplex-bucket.cjs.d.ts.map |
@@ -5,3 +5,3 @@ 'use strict'; | ||
var event = require('@hmans/event'); | ||
var eventery = require('eventery'); | ||
@@ -81,2 +81,18 @@ function _arrayLikeToArray(arr, len) { | ||
function _toPrimitive(input, hint) { | ||
if (typeof input !== "object" || input === null) return input; | ||
var prim = input[Symbol.toPrimitive]; | ||
if (prim !== undefined) { | ||
var res = prim.call(input, hint || "default"); | ||
if (typeof res !== "object") return res; | ||
throw new TypeError("@@toPrimitive must return a primitive value."); | ||
} | ||
return (hint === "string" ? String : Number)(input); | ||
} | ||
function _toPropertyKey(arg) { | ||
var key = _toPrimitive(arg, "string"); | ||
return typeof key === "symbol" ? key : String(key); | ||
} | ||
function _defineProperties(target, props) { | ||
@@ -88,3 +104,3 @@ for (var i = 0; i < props.length; i++) { | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); | ||
} | ||
@@ -102,2 +118,3 @@ } | ||
function _defineProperty(obj, key, value) { | ||
key = _toPropertyKey(key); | ||
if (key in obj) { | ||
@@ -126,8 +143,17 @@ Object.defineProperty(obj, key, { | ||
function Bucket() { | ||
var entities = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
var _entities = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
_classCallCheck(this, Bucket); | ||
_defineProperty(this, "onEntityAdded", new event.Event()); | ||
_defineProperty(this, "onEntityRemoved", new event.Event()); | ||
/** | ||
* Fired when an entity has been added to the bucket. | ||
*/ | ||
_defineProperty(this, "onEntityAdded", new eventery.Event()); | ||
/** | ||
* Fired when an entity is about to be removed from the bucket. | ||
*/ | ||
_defineProperty(this, "onEntityRemoved", new eventery.Event()); | ||
/** | ||
* A map of entity positions, used for fast lookups. | ||
*/ | ||
_defineProperty(this, "entityPositions", new Map()); | ||
this.entities = entities; | ||
this._entities = _entities; | ||
this.add = this.add.bind(this); | ||
@@ -137,16 +163,18 @@ this.remove = this.remove.bind(this); | ||
/* Register all entity positions */ | ||
for (var i = 0; i < entities.length; i++) { | ||
this.entityPositions.set(entities[i], i); | ||
for (var i = 0; i < _entities.length; i++) { | ||
this.entityPositions.set(_entities[i], i); | ||
} | ||
} | ||
_createClass(Bucket, [{ | ||
key: "entities", | ||
get: function get() { | ||
return this._entities; | ||
} | ||
/** | ||
* Fired when an entity has been added to the bucket. | ||
*/ | ||
_createClass(Bucket, [{ | ||
/* Custom iterator that iterates over all entities in reverse order. */ | ||
}, { | ||
key: _Symbol$iterator, | ||
value: /* Custom iterator that iterates over all entities in reverse order. */ | ||
function value() { | ||
value: function value() { | ||
var _this = this; | ||
var index = this.entities.length; | ||
var index = this._entities.length; | ||
var result = { | ||
@@ -158,3 +186,3 @@ value: undefined, | ||
next: function next() { | ||
result.value = _this.entities[--index]; | ||
result.value = _this._entities[--index]; | ||
result.done = index < 0; | ||
@@ -226,2 +254,3 @@ return result; | ||
value: function remove(entity) { | ||
/* TODO: Return early if entity is not in bucket. */ | ||
if (this.has(entity)) { | ||
@@ -259,4 +288,4 @@ /* Emit our own onEntityRemoved event. */ | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var entity = _step.value; | ||
this.remove(entity); | ||
var _entity = _step.value; | ||
this.remove(_entity); | ||
} | ||
@@ -263,0 +292,0 @@ } catch (err) { |
@@ -5,3 +5,3 @@ 'use strict'; | ||
var event = require('@hmans/event'); | ||
var eventery = require('eventery'); | ||
@@ -81,2 +81,18 @@ function _arrayLikeToArray(arr, len) { | ||
function _toPrimitive(input, hint) { | ||
if (typeof input !== "object" || input === null) return input; | ||
var prim = input[Symbol.toPrimitive]; | ||
if (prim !== undefined) { | ||
var res = prim.call(input, hint || "default"); | ||
if (typeof res !== "object") return res; | ||
throw new TypeError("@@toPrimitive must return a primitive value."); | ||
} | ||
return (hint === "string" ? String : Number)(input); | ||
} | ||
function _toPropertyKey(arg) { | ||
var key = _toPrimitive(arg, "string"); | ||
return typeof key === "symbol" ? key : String(key); | ||
} | ||
function _defineProperties(target, props) { | ||
@@ -88,3 +104,3 @@ for (var i = 0; i < props.length; i++) { | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); | ||
} | ||
@@ -102,2 +118,3 @@ } | ||
function _defineProperty(obj, key, value) { | ||
key = _toPropertyKey(key); | ||
if (key in obj) { | ||
@@ -126,8 +143,17 @@ Object.defineProperty(obj, key, { | ||
function Bucket() { | ||
var entities = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
var _entities = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
_classCallCheck(this, Bucket); | ||
_defineProperty(this, "onEntityAdded", new event.Event()); | ||
_defineProperty(this, "onEntityRemoved", new event.Event()); | ||
/** | ||
* Fired when an entity has been added to the bucket. | ||
*/ | ||
_defineProperty(this, "onEntityAdded", new eventery.Event()); | ||
/** | ||
* Fired when an entity is about to be removed from the bucket. | ||
*/ | ||
_defineProperty(this, "onEntityRemoved", new eventery.Event()); | ||
/** | ||
* A map of entity positions, used for fast lookups. | ||
*/ | ||
_defineProperty(this, "entityPositions", new Map()); | ||
this.entities = entities; | ||
this._entities = _entities; | ||
this.add = this.add.bind(this); | ||
@@ -137,16 +163,18 @@ this.remove = this.remove.bind(this); | ||
/* Register all entity positions */ | ||
for (var i = 0; i < entities.length; i++) { | ||
this.entityPositions.set(entities[i], i); | ||
for (var i = 0; i < _entities.length; i++) { | ||
this.entityPositions.set(_entities[i], i); | ||
} | ||
} | ||
_createClass(Bucket, [{ | ||
key: "entities", | ||
get: function get() { | ||
return this._entities; | ||
} | ||
/** | ||
* Fired when an entity has been added to the bucket. | ||
*/ | ||
_createClass(Bucket, [{ | ||
/* Custom iterator that iterates over all entities in reverse order. */ | ||
}, { | ||
key: _Symbol$iterator, | ||
value: /* Custom iterator that iterates over all entities in reverse order. */ | ||
function value() { | ||
value: function value() { | ||
var _this = this; | ||
var index = this.entities.length; | ||
var index = this._entities.length; | ||
var result = { | ||
@@ -158,3 +186,3 @@ value: undefined, | ||
next: function next() { | ||
result.value = _this.entities[--index]; | ||
result.value = _this._entities[--index]; | ||
result.done = index < 0; | ||
@@ -226,2 +254,3 @@ return result; | ||
value: function remove(entity) { | ||
/* TODO: Return early if entity is not in bucket. */ | ||
if (this.has(entity)) { | ||
@@ -259,4 +288,4 @@ /* Emit our own onEntityRemoved event. */ | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var entity = _step.value; | ||
this.remove(entity); | ||
var _entity = _step.value; | ||
this.remove(_entity); | ||
} | ||
@@ -263,0 +292,0 @@ } catch (err) { |
@@ -1,2 +0,2 @@ | ||
import { Event } from '@hmans/event'; | ||
import { Event } from 'eventery'; | ||
@@ -76,2 +76,18 @@ function _arrayLikeToArray(arr, len) { | ||
function _toPrimitive(input, hint) { | ||
if (typeof input !== "object" || input === null) return input; | ||
var prim = input[Symbol.toPrimitive]; | ||
if (prim !== undefined) { | ||
var res = prim.call(input, hint || "default"); | ||
if (typeof res !== "object") return res; | ||
throw new TypeError("@@toPrimitive must return a primitive value."); | ||
} | ||
return (hint === "string" ? String : Number)(input); | ||
} | ||
function _toPropertyKey(arg) { | ||
var key = _toPrimitive(arg, "string"); | ||
return typeof key === "symbol" ? key : String(key); | ||
} | ||
function _defineProperties(target, props) { | ||
@@ -83,3 +99,3 @@ for (var i = 0; i < props.length; i++) { | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); | ||
} | ||
@@ -97,2 +113,3 @@ } | ||
function _defineProperty(obj, key, value) { | ||
key = _toPropertyKey(key); | ||
if (key in obj) { | ||
@@ -121,8 +138,17 @@ Object.defineProperty(obj, key, { | ||
function Bucket() { | ||
var entities = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
var _entities = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
_classCallCheck(this, Bucket); | ||
/** | ||
* Fired when an entity has been added to the bucket. | ||
*/ | ||
_defineProperty(this, "onEntityAdded", new Event()); | ||
/** | ||
* Fired when an entity is about to be removed from the bucket. | ||
*/ | ||
_defineProperty(this, "onEntityRemoved", new Event()); | ||
/** | ||
* A map of entity positions, used for fast lookups. | ||
*/ | ||
_defineProperty(this, "entityPositions", new Map()); | ||
this.entities = entities; | ||
this._entities = _entities; | ||
this.add = this.add.bind(this); | ||
@@ -132,16 +158,18 @@ this.remove = this.remove.bind(this); | ||
/* Register all entity positions */ | ||
for (var i = 0; i < entities.length; i++) { | ||
this.entityPositions.set(entities[i], i); | ||
for (var i = 0; i < _entities.length; i++) { | ||
this.entityPositions.set(_entities[i], i); | ||
} | ||
} | ||
_createClass(Bucket, [{ | ||
key: "entities", | ||
get: function get() { | ||
return this._entities; | ||
} | ||
/** | ||
* Fired when an entity has been added to the bucket. | ||
*/ | ||
_createClass(Bucket, [{ | ||
/* Custom iterator that iterates over all entities in reverse order. */ | ||
}, { | ||
key: _Symbol$iterator, | ||
value: /* Custom iterator that iterates over all entities in reverse order. */ | ||
function value() { | ||
value: function value() { | ||
var _this = this; | ||
var index = this.entities.length; | ||
var index = this._entities.length; | ||
var result = { | ||
@@ -153,3 +181,3 @@ value: undefined, | ||
next: function next() { | ||
result.value = _this.entities[--index]; | ||
result.value = _this._entities[--index]; | ||
result.done = index < 0; | ||
@@ -221,2 +249,3 @@ return result; | ||
value: function remove(entity) { | ||
/* TODO: Return early if entity is not in bucket. */ | ||
if (this.has(entity)) { | ||
@@ -254,4 +283,4 @@ /* Emit our own onEntityRemoved event. */ | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var entity = _step.value; | ||
this.remove(entity); | ||
var _entity = _step.value; | ||
this.remove(_entity); | ||
} | ||
@@ -258,0 +287,0 @@ } catch (err) { |
@@ -1,2 +0,2 @@ | ||
Copyright (c) 2022 Hendrik Mans | ||
Copyright (c) 2023 Hendrik Mans | ||
@@ -3,0 +3,0 @@ Permission is hereby granted, free of charge, to any person obtaining |
@@ -18,3 +18,3 @@ { | ||
"sideEffects": false, | ||
"version": "2.0.0-beta.3", | ||
"version": "2.0.0-beta.4", | ||
"main": "dist/miniplex-bucket.cjs.js", | ||
@@ -30,8 +30,8 @@ "module": "dist/miniplex-bucket.esm.js", | ||
"dependencies": { | ||
"@hmans/event": "^0.2.0" | ||
"eventery": "^0.0.4" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^18.11.9", | ||
"@types/node": "^20.4.1", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^4.9.3" | ||
"typescript": "^5.1.6" | ||
}, | ||
@@ -38,0 +38,0 @@ "scripts": { |
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
29433
11
879
+ Addedeventery@^0.0.4
+ Addedeventery@0.0.4(transitive)
- Removed@hmans/event@^0.2.0
- Removed@hmans/event@0.2.0(transitive)