t83714 / fractal-component Goto Github PK
View Code? Open in Web Editor NEWA javascript library that can help you to encapsulate decoupled UI component easily
License: MIT License
A javascript library that can help you to encapsulate decoupled UI component easily
License: MIT License
Sometimes, we need to share a portion of the state data among components.
fractal-component
doesn't stop you from accessing the state data globally in order to achieve this but we probably need a better way of doing that without breaking the promise of not depending on global state store.
Proposed solution:
SharedABCData.js:
import { createSharedState } from "fractal-component";
import * as actions from "./SharedABCDataActionCreators";
import * as actionTypes from "./SharedABCDataActionTypes";
const SharedABCData = createSharedState({
namespace: "io.github.t83714/SharedABCData",
initState: {
x: 101
},
actionTypes,
reducer: (state, action) => {
...
}
});
export default SharedABCData;
export { actions, actionTypes };
SharedABCData
by:import { useComponentManager } from "fractal-component";
import SharedABCData from "./SharedABCData";
function ComponentA(props){
const [state, dispatch] = useComponentManager({
namespace: "io.github.t83714/ComponentA",
initState: {
a: {
b: 1
}
},
....
sharedComponents: {
"a.c": SharedABCData
}
});
return <div>xxxx</div>;
}
Then, the actual component state of ComponentA
will be:
{
"a": {
"b": 1,
"c": {
"x": 101
}
}
}
Anytime when SharedABCData
changed, ComponentA
's state will also be updated accordingly and rendered.
Although from ComponentA
's point of view, the SharedABCData
portion of data appears to be part of its state data, there is only one copy of SharedABCData
in global state store and SharedABCData
it not part of ComponentA
's state data in global state data store.
The global data store will look like (assume namespace prefix is empty):
{
"io.github.t83714": {
"SharedABCData": {
"c0": {
"x": 101
}
},
"ComponentA": {
"c0": {
"a":{
"b":1
}
}
}
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.