Comparing version 1.0.1-alpha.8 to 1.0.1-alpha.9
@@ -12,5 +12,4 @@ type BlacObserver<S> = (newState: S, oldState: S) => void | Promise<void>; | ||
type BlocProps = Record<string | number, any>; | ||
declare abstract class Cubit<S, P extends BlocProps = {}> extends BlocBase<S> { | ||
declare abstract class Cubit<S, P extends BlocProps = {}> extends BlocBase<S, P> { | ||
static create: () => Cubit<any, any>; | ||
props: P; | ||
constructor(initialState: S); | ||
@@ -36,2 +35,3 @@ /** | ||
static isBlacClass: boolean; | ||
static _propsOnInit: BlocProps | undefined; | ||
isolated: boolean; | ||
@@ -42,5 +42,5 @@ isBlacLive: boolean; | ||
id: BlocInstanceId; | ||
props: P; | ||
readonly createdAt: number; | ||
constructor(initialState: S); | ||
get props(): P; | ||
_state: S; | ||
@@ -112,3 +112,2 @@ get state(): S; | ||
pluginList: BlacPlugin[]; | ||
customPropsMap: Map<Function, BlocProps>; | ||
postChangesToDocument: boolean; | ||
@@ -128,4 +127,2 @@ constructor(); | ||
unregisterIsolatedBlocInstance(bloc: BlocBase<any>): void; | ||
setCustomProps(blocClass: BlocBaseAbstract, props: BlocProps | undefined): void; | ||
getCustomProps(blocClass: BlocBaseAbstract): BlocProps | undefined; | ||
createNewBlocInstance<B extends BlocBase<any>>(blocClass: BlocConstructor<B>, id: BlocInstanceId, props: BlocProps | undefined): InstanceType<BlocConstructor<B>>; | ||
@@ -132,0 +129,0 @@ getBloc<B extends BlocBase<S>, S>(blocClass: BlocConstructor<B>, options?: { |
@@ -100,3 +100,2 @@ /****************************************************************************** | ||
this.pluginList = []; | ||
this.customPropsMap = new Map(); | ||
this.postChangesToDocument = false; | ||
@@ -213,16 +212,6 @@ this.addPlugin = function (plugin) { | ||
}; | ||
Blac.prototype.setCustomProps = function (blocClass, props) { | ||
if (!props) | ||
return; | ||
this.customPropsMap.set(blocClass, props); | ||
}; | ||
Blac.prototype.getCustomProps = function (blocClass) { | ||
var props = this.customPropsMap.get(blocClass); | ||
this.customPropsMap.delete(blocClass); | ||
return props; | ||
}; | ||
Blac.prototype.createNewBlocInstance = function (blocClass, id, props) { | ||
var base = blocClass; | ||
var hasCreateMethod = Object.prototype.hasOwnProperty.call(blocClass, 'create'); | ||
this.setCustomProps(base, props); | ||
base._propsOnInit = props; | ||
var newBloc = hasCreateMethod ? base.create() : new blocClass(); | ||
@@ -299,3 +288,3 @@ newBloc.updateId(id); | ||
this.blac = Blac.getInstance(); | ||
this.props = {}; | ||
// public props: P = {} as P; | ||
this.createdAt = Date.now(); | ||
@@ -322,4 +311,13 @@ this.updateId = function (id) { | ||
this.isolated = this.constructor.isolated; | ||
// this.onConnect?.(); | ||
} | ||
Object.defineProperty(BlocBase.prototype, "props", { | ||
get: function () { | ||
var p = this.constructor._propsOnInit; | ||
if (!p) | ||
return {}; | ||
return p; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(BlocBase.prototype, "state", { | ||
@@ -354,7 +352,3 @@ get: function () { | ||
function Cubit(initialState) { | ||
var _this = _super.call(this, initialState) || this; | ||
_this.props = {}; | ||
var newProps = Blac.getInstance().getCustomProps(_this.constructor); | ||
_this.props = __assign(__assign({}, _this.props), newProps); | ||
return _this; | ||
return _super.call(this, initialState) || this; | ||
} | ||
@@ -361,0 +355,0 @@ /** |
@@ -102,3 +102,2 @@ 'use strict'; | ||
this.pluginList = []; | ||
this.customPropsMap = new Map(); | ||
this.postChangesToDocument = false; | ||
@@ -215,16 +214,6 @@ this.addPlugin = function (plugin) { | ||
}; | ||
Blac.prototype.setCustomProps = function (blocClass, props) { | ||
if (!props) | ||
return; | ||
this.customPropsMap.set(blocClass, props); | ||
}; | ||
Blac.prototype.getCustomProps = function (blocClass) { | ||
var props = this.customPropsMap.get(blocClass); | ||
this.customPropsMap.delete(blocClass); | ||
return props; | ||
}; | ||
Blac.prototype.createNewBlocInstance = function (blocClass, id, props) { | ||
var base = blocClass; | ||
var hasCreateMethod = Object.prototype.hasOwnProperty.call(blocClass, 'create'); | ||
this.setCustomProps(base, props); | ||
base._propsOnInit = props; | ||
var newBloc = hasCreateMethod ? base.create() : new blocClass(); | ||
@@ -301,3 +290,3 @@ newBloc.updateId(id); | ||
this.blac = Blac.getInstance(); | ||
this.props = {}; | ||
// public props: P = {} as P; | ||
this.createdAt = Date.now(); | ||
@@ -324,4 +313,13 @@ this.updateId = function (id) { | ||
this.isolated = this.constructor.isolated; | ||
// this.onConnect?.(); | ||
} | ||
Object.defineProperty(BlocBase.prototype, "props", { | ||
get: function () { | ||
var p = this.constructor._propsOnInit; | ||
if (!p) | ||
return {}; | ||
return p; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(BlocBase.prototype, "state", { | ||
@@ -356,7 +354,3 @@ get: function () { | ||
function Cubit(initialState) { | ||
var _this = _super.call(this, initialState) || this; | ||
_this.props = {}; | ||
var newProps = Blac.getInstance().getCustomProps(_this.constructor); | ||
_this.props = __assign(__assign({}, _this.props), newProps); | ||
return _this; | ||
return _super.call(this, initialState) || this; | ||
} | ||
@@ -363,0 +357,0 @@ /** |
{ | ||
"name": "blac", | ||
"version": "1.0.1-alpha.8", | ||
"version": "1.0.1-alpha.9", | ||
"license": "MIT", | ||
@@ -24,3 +24,4 @@ "main": "dist/blac.js", | ||
"test:watch": "vitest --watch", | ||
"coverage": "vitest run --coverage" | ||
"coverage": "vitest run --coverage", | ||
"pub:alpha": "npm run build && npm publish --tag alpha" | ||
}, | ||
@@ -27,0 +28,0 @@ "dependencies": {}, |
Sorry, the diff of this file is not supported yet
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
87119
939