Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

blac

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

blac - npm Package Compare versions

Comparing version 1.0.10 to 1.0.11

2

index.cjs.js

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var l=(c=>(c.BLOC_DISPOSED="BLOC_DISPOSED",c.LISTENER_REMOVED="LISTENER_REMOVED",c.LISTENER_ADDED="LISTENER_ADDED",c.STATE_CHANGED="STATE_CHANGED",c.BLOC_CREATED="BLOC_CREATED",c))(l||{});const o=class o{constructor(t={}){this.blocInstanceMap=new Map,this.isolatedBlocMap=new Map,this.pluginList=[],this.postChangesToDocument=!1,this.addPlugin=s=>{this.pluginList.findIndex(n=>n.name===s.name)===-1&&this.pluginList.push(s)},this.reportToPlugins=(s,i,n)=>{this.pluginList.forEach(r=>{r.onEvent(s,i,n)})},this.report=(s,i,n)=>{const r=i.constructor;switch(s){case"BLOC_DISPOSED":this.disposeBloc(i);break;case"LISTENER_REMOVED":i.observer.size===0&&!r.keepAlive&&this.disposeBloc(i);break}this.reportToPlugins(s,i,n)},this.disposeBloc=s=>{s.constructor.isolated?this.unregisterIsolatedBlocInstance(s):this.unregisterBlocInstance(s)},this.getAllBlocs=(s,i={})=>{const n=s,{searchIsolated:r=n.isolated}=i;if(r){const u=this.isolatedBlocMap.get(s);if(u)return u}else return Array.from(this.blocInstanceMap.values()).filter(a=>a instanceof s);return[]},this.configure=s=>{s.exposeBlacInstance};const{__unsafe_ignore_singleton:e=!1}=t;if(o.instance&&!e)return o.instance;o.instance=this}static getInstance(){return o.instance}resetInstance(){o.instance=new o({__unsafe_ignore_singleton:!0})}createBlocInstanceMapKey(t,e){return`${t}:${e}`}unregisterBlocInstance(t){const e=this.createBlocInstanceMapKey(t.name,t.id);this.blocInstanceMap.delete(e)}registerBlocInstance(t){const e=this.createBlocInstanceMapKey(t.name,t.id);this.blocInstanceMap.set(e,t)}findRegisteredBlocInstance(t,e){if(t.isolated)return;const i=this.createBlocInstanceMapKey(t.name,e);return this.blocInstanceMap.get(i)}registerIsolatedBlocInstance(t){const e=t.constructor,s=this.isolatedBlocMap.get(e);s?s.push(t):this.isolatedBlocMap.set(e,[t])}unregisterIsolatedBlocInstance(t){const e=t.constructor,s=this.isolatedBlocMap.get(e);if(s){const i=s.findIndex(n=>n.id===t.id);s.splice(i,1),s.length===0&&this.isolatedBlocMap.delete(e)}}findIsolatedBlocInstance(t,e){const s=this.isolatedBlocMap.get(t);if(s)return s.find(i=>i.id===e)}createNewBlocInstance(t,e,s){const i=t,n=Object.prototype.hasOwnProperty.call(t,"create");i._propsOnInit=s;const r=n?i.create():new t;return r.updateId(e),i.isolated?(this.registerIsolatedBlocInstance(r),r):(this.registerBlocInstance(r),r)}getBloc(t,e={}){const i=t.isolated,n=e.id||t.name,r=i?this.findIsolatedBlocInstance(t,n):this.findRegisteredBlocInstance(t,n),{reconnect:u}=e;if(r)if(u)r.dispose();else return r;return this.createNewBlocInstance(t,n,e.props)}};o.instance=new o,o.getAllBlocs=o.instance.getAllBlocs,o.addPlugin=o.instance.addPlugin,o.configure=o.instance.configure;let g=o;class b{constructor(){this._observers=new Set}get size(){return this._observers.size}get observers(){return this._observers}subscribe(t){return this._observers.add(t),()=>this.unsubscribe(t)}unsubscribe(t){this._observers.delete(t)}notify(t,e){this._observers.forEach(s=>s(t,e))}dispose(){this._observers.clear()}}const p=class p{constructor(t){this.isolated=!1,this.isBlacLive=!0,this.blac=g.getInstance(),this.createdAt=Date.now(),this.updateId=e=>{const s=this.id;!e||e===s||(this.id=e)},this.addEventListenerStateChange=e=>(this.blac.report(l.LISTENER_ADDED,this),this.observer.subscribe(e),()=>this.handleUnsubscribe(e)),this.handleUnsubscribe=e=>{this.observer.unsubscribe(e),this.blac.report(l.LISTENER_REMOVED,this)},this.observer=new b,this._state=t,this.blac.report(l.BLOC_CREATED,this),this.id=this.constructor.name,this.isolated=this.constructor.isolated}get props(){if(this.localProps)return this.localProps;const t=this.constructor._propsOnInit;if(t)return this.localProps=t,t}set props(t){this.localProps=t}get state(){return this._state}get name(){return this.constructor.name}dispose(){this.blac.report(l.BLOC_DISPOSED,this),this.isBlacLive=!1,this.observer.dispose()}};p.isolated=!1,p.keepAlive=!1,p.isBlacClass=!0;let f=p;class E extends f{constructor(t){super(t),this.connectAddons=()=>{const{addons:e}=this;if(e)for(const s of e)s.onEmit&&this.observer.subscribe((i,n)=>{var r;(r=s.onEmit)==null||r.call(s,{newState:i,oldState:n,cubit:this})}),s.onInit&&s.onInit(this)},this.addons=this.constructor.addons,this.connectAddons()}emit(t){if(t===this.state)return;const e=this.state,s=t;this._state=t,this.observer.notify(s,e),this.blac.report(l.STATE_CHANGED,this,{newState:s,oldState:e})}patch(t,e=!1){let s=!1;if(!e)for(const i in t){const n=this.state[i];if(t[i]!==n){s=!0;break}}s&&this.emit({...this.state,...t})}}class B extends f{constructor(){super(...arguments),this.emit=t=>{const e=this.state,s=this.reducer(t,this.state);this._state=s,this.observer.notify(s,e),this.blac.report(l.STATE_CHANGED,this,{newState:s,oldState:e})}}}function S(c={}){const{localStoragePrefix:t="blac",localStorageKey:e,defaultValue:s}=c,i=a=>{console.log(t,a);const h=localStorage.getItem(`${t}:${a}`);if(!h)return s;try{return JSON.parse(JSON.parse(h)).persist}catch{return h}},n=a=>{const h=e??a.id,d=i(h);typeof d!==void 0&&a.emit(d)};let r="";return{name:"Persist",onInit:n,onEmit:({newState:a,cubit:h})=>{const d=e??h.id,I=JSON.stringify(`{"persist": ${a}}`);I!==r&&(localStorage.setItem(`${t}:${d}`,I),r=I)}}}exports.Blac=g;exports.BlacEvent=l;exports.BlacObservable=b;exports.Bloc=B;exports.BlocBase=f;exports.Cubit=E;exports.Persist=S;
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var l=(c=>(c.BLOC_DISPOSED="BLOC_DISPOSED",c.LISTENER_REMOVED="LISTENER_REMOVED",c.LISTENER_ADDED="LISTENER_ADDED",c.STATE_CHANGED="STATE_CHANGED",c.BLOC_CREATED="BLOC_CREATED",c))(l||{});const o=class o{constructor(t={}){this.createdAt=Date.now(),this.blocInstanceMap=new Map,this.isolatedBlocMap=new Map,this.pluginList=[],this.postChangesToDocument=!1,this.log=(...e)=>{console.log(`☢️ [Blac ${this.createdAt}]`,...e)},this.addPlugin=e=>{this.pluginList.findIndex(r=>r.name===e.name)===-1&&(this.log("Add plugin",e.name),this.pluginList.push(e))},this.reportToPlugins=(e,i,r)=>{this.pluginList.forEach(n=>{n.onEvent(e,i,r)})},this.report=(e,i,r)=>{const n=i.constructor;switch(e){case"BLOC_DISPOSED":this.disposeBloc(i);break;case"LISTENER_REMOVED":i.observer.size===0&&!n.keepAlive&&this.disposeBloc(i);break}this.reportToPlugins(e,i,r)},this.disposeBloc=e=>{const i=e.constructor;this.log("Dispose bloc",{bloc:e,blocName:e.name,blocId:e.id,isolated:i.isolated}),i.isolated?this.unregisterIsolatedBlocInstance(e):this.unregisterBlocInstance(e)},this.getAllBlocs=(e,i={})=>{const r=e,{searchIsolated:n=r.isolated}=i;if(n){const d=this.isolatedBlocMap.get(e);if(d)return d}else return Array.from(this.blocInstanceMap.values()).filter(a=>a instanceof e);return[]},this.configure=e=>{e.exposeBlacInstance};const{__unsafe_ignore_singleton:s=!1}=t;if(o.instance&&!s)return o.instance;this.log("Create new Blac instance"),o.instance=this}static getInstance(){return o.instance}resetInstance(){this.log("Reset Blac instance"),o.instance=new o({__unsafe_ignore_singleton:!0})}createBlocInstanceMapKey(t,s){return`${t}:${s}`}unregisterBlocInstance(t){const s=this.createBlocInstanceMapKey(t.name,t.id);this.log("Unregister bloc",s),this.blocInstanceMap.delete(s)}registerBlocInstance(t){const s=this.createBlocInstanceMapKey(t.name,t.id);this.log("Register bloc",s),this.blocInstanceMap.set(s,t)}findRegisteredBlocInstance(t,s){if(t.isolated)return;const i=this.createBlocInstanceMapKey(t.name,s);return this.blocInstanceMap.get(i)}registerIsolatedBlocInstance(t){const s=t.constructor,e=this.isolatedBlocMap.get(s);this.log("Register isolated bloc",s.name,t.id),e?e.push(t):this.isolatedBlocMap.set(s,[t])}unregisterIsolatedBlocInstance(t){const s=t.constructor,e=this.isolatedBlocMap.get(s);if(this.log("Unregister isolated bloc",s.name,t.id),e){const i=e.findIndex(r=>r.id===t.id);e.splice(i,1),e.length===0&&this.isolatedBlocMap.delete(s)}}findIsolatedBlocInstance(t,s){const e=this.isolatedBlocMap.get(t);if(e)return e.find(i=>i.id===s)}createNewBlocInstance(t,s,e){const i=t,r=Object.prototype.hasOwnProperty.call(t,"create");i._propsOnInit=e;const n=r?i.create():new t;return n.updateId(s),this.log("Create new bloc instance",{blocClass:t,id:s,props:e,newBloc:n}),i.isolated?(this.registerIsolatedBlocInstance(n),n):(this.registerBlocInstance(n),n)}getBloc(t,s={}){const i=t.isolated,r=s.id||t.name,n=i?this.findIsolatedBlocInstance(t,r):this.findRegisteredBlocInstance(t,r),{reconnect:d}=s;if(n)if(d)n.dispose();else return n;return this.createNewBlocInstance(t,r,s.props)}};o.instance=new o,o.getAllBlocs=o.instance.getAllBlocs,o.addPlugin=o.instance.addPlugin,o.configure=o.instance.configure;let f=o;class b{constructor(){this._observers=new Set}get size(){return this._observers.size}get observers(){return this._observers}subscribe(t){return this._observers.add(t),()=>this.unsubscribe(t)}unsubscribe(t){this._observers.delete(t)}notify(t,s){this._observers.forEach(e=>e(t,s))}dispose(){this._observers.clear()}}const g=class g{constructor(t){this.isolated=!1,this.isBlacLive=!0,this.blac=f.getInstance(),this.createdAt=Date.now(),this.updateId=s=>{const e=this.id;!s||s===e||(this.id=s)},this.addEventListenerStateChange=s=>(this.blac.report(l.LISTENER_ADDED,this),this.observer.subscribe(s),()=>this.handleUnsubscribe(s)),this.handleUnsubscribe=s=>{this.observer.unsubscribe(s),this.blac.report(l.LISTENER_REMOVED,this)},this.observer=new b,this._state=t,this.blac.report(l.BLOC_CREATED,this),this.id=this.constructor.name,this.isolated=this.constructor.isolated}get props(){if(this.localProps)return this.localProps;const t=this.constructor._propsOnInit;if(t)return this.localProps=t,t}set props(t){this.localProps=t}get state(){return this._state}get name(){return this.constructor.name}dispose(){this.blac.report(l.BLOC_DISPOSED,this),this.isBlacLive=!1,this.observer.dispose()}};g.isolated=!1,g.keepAlive=!1,g.isBlacClass=!0;let p=g;class E extends p{constructor(t){super(t),this.connectAddons=()=>{const{addons:s}=this;if(s)for(const e of s)e.onEmit&&this.observer.subscribe((i,r)=>{var n;(n=e.onEmit)==null||n.call(e,{newState:i,oldState:r,cubit:this})}),e.onInit&&e.onInit(this)},this.addons=this.constructor.addons,this.connectAddons()}emit(t){if(t===this.state)return;const s=this.state,e=t;this._state=t,this.observer.notify(e,s),this.blac.report(l.STATE_CHANGED,this,{newState:e,oldState:s})}patch(t,s=!1){let e=!1;if(!s)for(const i in t){const r=this.state[i];if(t[i]!==r){e=!0;break}}e&&this.emit({...this.state,...t})}}class B extends p{constructor(){super(...arguments),this.emit=t=>{const s=this.state,e=this.reducer(t,this.state);this._state=e,this.observer.notify(e,s),this.blac.report(l.STATE_CHANGED,this,{newState:e,oldState:s})}}}function S(c={}){const{localStoragePrefix:t="blac",localStorageKey:s,defaultValue:e}=c,i=a=>{console.log(t,a);const h=localStorage.getItem(`${t}:${a}`);if(!h)return e;try{return JSON.parse(JSON.parse(h)).persist}catch{return h}},r=a=>{const h=s??a.id,u=i(h);typeof u!==void 0&&a.emit(u)};let n="";return{name:"Persist",onInit:r,onEmit:({newState:a,cubit:h})=>{const u=s??h.id,I=JSON.stringify(`{"persist": ${a}}`);I!==n&&(localStorage.setItem(`${t}:${u}`,I),n=I)}}}exports.Blac=f;exports.BlacEvent=l;exports.BlacObservable=b;exports.Bloc=B;exports.BlocBase=p;exports.Cubit=E;exports.Persist=S;
//# sourceMappingURL=index.cjs.js.map
var l = /* @__PURE__ */ ((c) => (c.BLOC_DISPOSED = "BLOC_DISPOSED", c.LISTENER_REMOVED = "LISTENER_REMOVED", c.LISTENER_ADDED = "LISTENER_ADDED", c.STATE_CHANGED = "STATE_CHANGED", c.BLOC_CREATED = "BLOC_CREATED", c))(l || {});
const o = class o {
constructor(t = {}) {
this.blocInstanceMap = /* @__PURE__ */ new Map(), this.isolatedBlocMap = /* @__PURE__ */ new Map(), this.pluginList = [], this.postChangesToDocument = !1, this.addPlugin = (s) => {
this.pluginList.findIndex((n) => n.name === s.name) === -1 && this.pluginList.push(s);
}, this.reportToPlugins = (s, i, n) => {
this.pluginList.forEach((r) => {
r.onEvent(s, i, n);
this.createdAt = Date.now(), this.blocInstanceMap = /* @__PURE__ */ new Map(), this.isolatedBlocMap = /* @__PURE__ */ new Map(), this.pluginList = [], this.postChangesToDocument = !1, this.log = (...s) => {
console.log(`☢️ [Blac ${this.createdAt}]`, ...s);
}, this.addPlugin = (s) => {
this.pluginList.findIndex((r) => r.name === s.name) === -1 && (this.log("Add plugin", s.name), this.pluginList.push(s));
}, this.reportToPlugins = (s, i, r) => {
this.pluginList.forEach((n) => {
n.onEvent(s, i, r);
});
}, this.report = (s, i, n) => {
const r = i.constructor;
}, this.report = (s, i, r) => {
const n = i.constructor;
switch (s) {

@@ -17,14 +19,20 @@ case "BLOC_DISPOSED":

case "LISTENER_REMOVED":
i.observer.size === 0 && !r.keepAlive && this.disposeBloc(i);
i.observer.size === 0 && !n.keepAlive && this.disposeBloc(i);
break;
}
this.reportToPlugins(s, i, n);
this.reportToPlugins(s, i, r);
}, this.disposeBloc = (s) => {
s.constructor.isolated ? this.unregisterIsolatedBlocInstance(s) : this.unregisterBlocInstance(s);
const i = s.constructor;
this.log("Dispose bloc", {
bloc: s,
blocName: s.name,
blocId: s.id,
isolated: i.isolated
}), i.isolated ? this.unregisterIsolatedBlocInstance(s) : this.unregisterBlocInstance(s);
}, this.getAllBlocs = (s, i = {}) => {
const n = s, { searchIsolated: r = n.isolated } = i;
if (r) {
const u = this.isolatedBlocMap.get(s);
if (u)
return u;
const r = s, { searchIsolated: n = r.isolated } = i;
if (n) {
const d = this.isolatedBlocMap.get(s);
if (d)
return d;
} else

@@ -39,3 +47,3 @@ return Array.from(this.blocInstanceMap.values()).filter((a) => a instanceof s);

return o.instance;
o.instance = this;
this.log("Create new Blac instance"), o.instance = this;
}

@@ -46,3 +54,3 @@ static getInstance() {

resetInstance() {
o.instance = new o({
this.log("Reset Blac instance"), o.instance = new o({
__unsafe_ignore_singleton: !0

@@ -56,7 +64,7 @@ });

const e = this.createBlocInstanceMapKey(t.name, t.id);
this.blocInstanceMap.delete(e);
this.log("Unregister bloc", e), this.blocInstanceMap.delete(e);
}
registerBlocInstance(t) {
const e = this.createBlocInstanceMapKey(t.name, t.id);
this.blocInstanceMap.set(e, t);
this.log("Register bloc", e), this.blocInstanceMap.set(e, t);
}

@@ -71,8 +79,8 @@ findRegisteredBlocInstance(t, e) {

const e = t.constructor, s = this.isolatedBlocMap.get(e);
s ? s.push(t) : this.isolatedBlocMap.set(e, [t]);
this.log("Register isolated bloc", e.name, t.id), s ? s.push(t) : this.isolatedBlocMap.set(e, [t]);
}
unregisterIsolatedBlocInstance(t) {
const e = t.constructor, s = this.isolatedBlocMap.get(e);
if (s) {
const i = s.findIndex((n) => n.id === t.id);
if (this.log("Unregister isolated bloc", e.name, t.id), s) {
const i = s.findIndex((r) => r.id === t.id);
s.splice(i, 1), s.length === 0 && this.isolatedBlocMap.delete(e);

@@ -87,3 +95,3 @@ }

createNewBlocInstance(t, e, s) {
const i = t, n = Object.prototype.hasOwnProperty.call(
const i = t, r = Object.prototype.hasOwnProperty.call(
t,

@@ -93,17 +101,22 @@ "create"

i._propsOnInit = s;
const r = n ? i.create() : new t();
return r.updateId(e), i.isolated ? (this.registerIsolatedBlocInstance(r), r) : (this.registerBlocInstance(r), r);
const n = r ? i.create() : new t();
return n.updateId(e), this.log("Create new bloc instance", {
blocClass: t,
id: e,
props: s,
newBloc: n
}), i.isolated ? (this.registerIsolatedBlocInstance(n), n) : (this.registerBlocInstance(n), n);
}
getBloc(t, e = {}) {
const i = t.isolated, n = e.id || t.name, r = i ? this.findIsolatedBlocInstance(t, n) : this.findRegisteredBlocInstance(t, n), { reconnect: u } = e;
if (r)
if (u)
r.dispose();
const i = t.isolated, r = e.id || t.name, n = i ? this.findIsolatedBlocInstance(t, r) : this.findRegisteredBlocInstance(t, r), { reconnect: d } = e;
if (n)
if (d)
n.dispose();
else
return r;
return this.createNewBlocInstance(t, n, e.props);
return n;
return this.createNewBlocInstance(t, r, e.props);
}
};
o.instance = new o(), o.getAllBlocs = o.instance.getAllBlocs, o.addPlugin = o.instance.addPlugin, o.configure = o.instance.configure;
let g = o;
let I = o;
class b {

@@ -132,7 +145,7 @@ constructor() {

}
const p = class p {
const g = class g {
// onConnect(): void;
// onDisconnect(): void;
constructor(t) {
this.isolated = !1, this.isBlacLive = !0, this.blac = g.getInstance(), this.createdAt = Date.now(), this.updateId = (e) => {
this.isolated = !1, this.isBlacLive = !0, this.blac = I.getInstance(), this.createdAt = Date.now(), this.updateId = (e) => {
const s = this.id;

@@ -164,5 +177,5 @@ !e || e === s || (this.id = e);

};
p.isolated = !1, p.keepAlive = !1, p.isBlacClass = !0;
let f = p;
class E extends f {
g.isolated = !1, g.keepAlive = !1, g.isBlacClass = !0;
let p = g;
class E extends p {
constructor(t) {

@@ -173,7 +186,7 @@ super(t), this.connectAddons = () => {

for (const s of e)
s.onEmit && this.observer.subscribe((i, n) => {
var r;
(r = s.onEmit) == null || r.call(s, {
s.onEmit && this.observer.subscribe((i, r) => {
var n;
(n = s.onEmit) == null || n.call(s, {
newState: i,
oldState: n,
oldState: r,
cubit: this

@@ -206,4 +219,4 @@ });

for (const i in t) {
const n = this.state[i];
if (t[i] !== n) {
const r = this.state[i];
if (t[i] !== r) {
s = !0;

@@ -216,3 +229,3 @@ break;

}
class S extends f {
class S extends p {
constructor() {

@@ -228,3 +241,3 @@ super(...arguments), this.emit = (t) => {

}
function D(c = {}) {
function B(c = {}) {
const {

@@ -244,13 +257,13 @@ localStoragePrefix: t = "blac",

}
}, n = (a) => {
const h = e ?? a.id, d = i(h);
typeof d !== void 0 && a.emit(d);
}, r = (a) => {
const h = e ?? a.id, u = i(h);
typeof u !== void 0 && a.emit(u);
};
let r = "";
let n = "";
return {
name: "Persist",
onInit: n,
onInit: r,
onEmit: ({ newState: a, cubit: h }) => {
const d = e ?? h.id, I = JSON.stringify(`{"persist": ${a}}`);
I !== r && (localStorage.setItem(`${t}:${d}`, I), r = I);
const u = e ?? h.id, f = JSON.stringify(`{"persist": ${a}}`);
f !== n && (localStorage.setItem(`${t}:${u}`, f), n = f);
}

@@ -260,10 +273,10 @@ };

export {
g as Blac,
I as Blac,
l as BlacEvent,
b as BlacObservable,
S as Bloc,
f as BlocBase,
p as BlocBase,
E as Cubit,
D as Persist
B as Persist
};
//# sourceMappingURL=index.es.js.map
{
"name": "blac",
"version": "1.0.10",
"version": "1.0.11",
"license": "MIT",

@@ -5,0 +5,0 @@ "main": "index.cjs.js",

@@ -27,2 +27,3 @@ import { BlocBase, BlocInstanceId } from './BlocBase';

static instance: Blac;
createdAt: number;
static getAllBlocs: <B extends BlocBase<any, {}>>(blocClass: BlocConstructor<B>, options?: {

@@ -40,2 +41,3 @@ searchIsolated?: boolean;

});
log: (...args: any[]) => void;
static getInstance(): Blac;

@@ -42,0 +44,0 @@ resetInstance(): void;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc