@equinor/fusion
Advanced tools
Comparing version 0.1.25 to 0.1.26
@@ -7,2 +7,5 @@ import ApiClients from "../http/apiClients"; | ||
history: Context[] | null; | ||
links: { | ||
[key: string]: string; | ||
}; | ||
}; | ||
@@ -14,2 +17,5 @@ export default class ContextManager extends ReliableDictionary<ContextCache> { | ||
setCurrentContextAsync(context: Context): Promise<void>; | ||
private updateHistoryAsync; | ||
private updateLinksAsync; | ||
getLinkedContext(context: Context): Promise<Context | null>; | ||
getCurrentContext(): Context | null; | ||
@@ -16,0 +22,0 @@ getHistory(): Context[]; |
@@ -17,3 +17,2 @@ import { useState, useCallback, useEffect } from "react"; | ||
const currentContext = await this.getCurrentContextAsync(); | ||
const history = await this.getAsync("history"); | ||
await this.setAsync("current", context); | ||
@@ -23,3 +22,8 @@ if (!currentContext) { | ||
} | ||
this.updateHistoryAsync(currentContext); | ||
this.updateLinksAsync(currentContext, context); | ||
} | ||
async updateHistoryAsync(currentContext) { | ||
const newHistory = [currentContext]; | ||
const history = await this.getAsync("history"); | ||
if (history) { | ||
@@ -35,2 +39,20 @@ history | ||
} | ||
async updateLinksAsync(currentContext, newContext) { | ||
const links = await this.getAsync("links"); | ||
await this.setAsync("links", Object.assign({}, (links || {}), { [currentContext.id]: newContext.id })); | ||
} | ||
async getLinkedContext(context) { | ||
const links = await this.getAsync("links"); | ||
if (!links || !links[context.id]) { | ||
return null; | ||
} | ||
const linkedContextId = links[context.id]; | ||
const history = await this.getAsync("history"); | ||
const contextFromHistory = history ? history.find(c => c.id === linkedContextId) : null; | ||
if (contextFromHistory) { | ||
return contextFromHistory; | ||
} | ||
const response = await this.contextClient.getContextAsync(linkedContextId); | ||
return response.data || null; | ||
} | ||
getCurrentContext() { | ||
@@ -37,0 +59,0 @@ // Avoid returning cached context if we're in the process of resolving a context from the current route |
{ | ||
"name": "@equinor/fusion", | ||
"version": "0.1.25", | ||
"version": "0.1.26", | ||
"description": "Everything a Fusion app needs to communicate with the core", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
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
108952
2510