@blac/react
Advanced tools
Comparing version 0.0.20 to 0.0.21
@@ -1,2 +0,2 @@ | ||
import { useId, useMemo, useSyncExternalStore, useEffect } from 'react'; | ||
import { useId, useMemo, useSyncExternalStore } from 'react'; | ||
@@ -122,3 +122,2 @@ var externalBlocStore = function (bloc, dependencySelector) { | ||
this.pluginList = []; | ||
this.customPropsMap = new Map(); | ||
this.postChangesToDocument = false; | ||
@@ -235,16 +234,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(); | ||
@@ -321,3 +310,3 @@ newBloc.updateId(id); | ||
this.blac = Blac.getInstance(); | ||
this.props = {}; | ||
// public props: P = {} as P; | ||
this.createdAt = Date.now(); | ||
@@ -344,4 +333,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", { | ||
@@ -376,7 +374,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; | ||
} | ||
@@ -494,5 +488,5 @@ /** | ||
var state = useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot); | ||
useEffect(function () { | ||
resolvedBloc.props = props; | ||
}, [props]); | ||
// useEffect(() => { | ||
// resolvedBloc.props = props; | ||
// }, [props]); | ||
return [state, resolvedBloc]; | ||
@@ -499,0 +493,0 @@ }; |
@@ -124,3 +124,2 @@ 'use strict'; | ||
this.pluginList = []; | ||
this.customPropsMap = new Map(); | ||
this.postChangesToDocument = false; | ||
@@ -237,16 +236,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(); | ||
@@ -323,3 +312,3 @@ newBloc.updateId(id); | ||
this.blac = Blac.getInstance(); | ||
this.props = {}; | ||
// public props: P = {} as P; | ||
this.createdAt = Date.now(); | ||
@@ -346,4 +335,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", { | ||
@@ -378,7 +376,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; | ||
} | ||
@@ -496,5 +490,5 @@ /** | ||
var state = react.useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot); | ||
react.useEffect(function () { | ||
resolvedBloc.props = props; | ||
}, [props]); | ||
// useEffect(() => { | ||
// resolvedBloc.props = props; | ||
// }, [props]); | ||
return [state, resolvedBloc]; | ||
@@ -501,0 +495,0 @@ }; |
{ | ||
"name": "@blac/react", | ||
"version": "0.0.20", | ||
"version": "0.0.21", | ||
"license": "MIT", | ||
@@ -22,3 +22,4 @@ "main": "dist/blac-react.js", | ||
"prettier": "prettier --write ./src", | ||
"test": "vitest run --coverage" | ||
"test": "vitest run --coverage", | ||
"pub": "npm run build && npm publish" | ||
}, | ||
@@ -25,0 +26,0 @@ "dependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
102495
979