@stratumn/react-map-explorer
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -8,5 +8,25 @@ import { Segment } from '@stratumn/js-chainscript'; | ||
export interface Props { | ||
/** | ||
* Map process. | ||
*/ | ||
process: string; | ||
/** | ||
* Id of the map you want to display. | ||
*/ | ||
mapId: string; | ||
/** | ||
* Hash of a known link that should be in the map. | ||
* If no link with this hash is currently loaded, the component will re-fetch | ||
* the map from the server. | ||
* You can use this prop to automatically refresh the map when creating new | ||
* links. | ||
*/ | ||
includeHash?: string; | ||
/** | ||
* Object that actually loads the whole map. | ||
*/ | ||
mapLoader: IMapLoader; | ||
/** | ||
* Callback when a segment is selected. | ||
*/ | ||
onSegmentSelected?: (s: Segment) => void; | ||
@@ -28,4 +48,7 @@ } | ||
componentDidMount(): Promise<void>; | ||
componentDidUpdate(prevProps: Props): Promise<void>; | ||
render(): JSX.Element; | ||
private shouldReloadMap; | ||
private loadMap; | ||
} | ||
//# sourceMappingURL=mapExplorer.d.ts.map |
@@ -42,5 +42,21 @@ "use strict"; | ||
this.state = { isLoaded: false }; | ||
} | ||
componentDidMount() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.shouldReloadMap = (prevProps) => { | ||
// If the map we want to display has changed, refresh. | ||
if (prevProps.process !== this.props.process || | ||
prevProps.mapId !== this.props.mapId) { | ||
return true; | ||
} | ||
// If an unknown link should be included, refresh. | ||
if (this.props.includeHash && | ||
prevProps.includeHash !== this.props.includeHash) { | ||
if (!this.state.segments) { | ||
return true; | ||
} | ||
if (!this.state.segments.find((s) => Buffer.from(s.linkHash()).toString('hex') === this.props.includeHash)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
this.loadMap = () => __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
@@ -61,2 +77,14 @@ const segments = yield this.props.mapLoader.load(this.props.process, this.props.mapId); | ||
} | ||
componentDidMount() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield this.loadMap(); | ||
}); | ||
} | ||
componentDidUpdate(prevProps) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (this.shouldReloadMap(prevProps)) { | ||
yield this.loadMap(); | ||
} | ||
}); | ||
} | ||
render() { | ||
@@ -63,0 +91,0 @@ const { mapId } = this.props; |
{ | ||
"name": "@stratumn/react-map-explorer", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "A React component to load and display Chainscript process maps.", | ||
@@ -48,4 +48,4 @@ "keywords": [ | ||
"dependencies": { | ||
"@stratumn/js-chainscript": "^1.0.2", | ||
"@stratumn/store-client": "^0.1.0", | ||
"@stratumn/js-chainscript": "^1.0.3", | ||
"@stratumn/store-client": "^0.1.2", | ||
"buffer": "^5.2.1", | ||
@@ -52,0 +52,0 @@ "react": "^16.6.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
21203
317
+ Added@types/node@22.12.0(transitive)
- Removed@types/node@22.13.1(transitive)