Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@equinor/fusion-framework-module-context

Package Overview
Dependencies
Maintainers
3
Versions
145
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@equinor/fusion-framework-module-context - npm Package Compare versions

Comparing version 0.1.3 to 0.3.0

21

CHANGELOG.md

@@ -6,2 +6,23 @@ # Change Log

## 0.3.0 (2022-11-02)
### Features
- **module-context:** expose current context from client on provider ([6895056](https://github.com/equinor/fusion-framework/commit/68950561d5b3fce3c555842c8d26004387a963e1))
### Bug Fixes
- **module-context:** expose provider ([1fd2c5a](https://github.com/equinor/fusion-framework/commit/1fd2c5ae8a486a7c9b9933ffcb37918dfa3ac4b0))
- **module-context:** fix relative import ([da23b68](https://github.com/equinor/fusion-framework/commit/da23b6836739de1dda27c84b18083feff5c4055b))
## [0.2.0](https://github.com/equinor/fusion-framework/compare/@equinor/fusion-framework-module-context@0.1.4...@equinor/fusion-framework-module-context@0.2.0) (2022-11-02)
### Features
- **module-context:** connect context module to parent ([6f1158f](https://github.com/equinor/fusion-framework/commit/6f1158f089fee8d9350875b20cba61f52886ee7a))
## [0.1.4](https://github.com/equinor/fusion-framework/compare/@equinor/fusion-framework-module-context@0.1.3...@equinor/fusion-framework-module-context@0.1.4) (2022-11-01)
**Note:** Version bump only for package @equinor/fusion-framework-module-context
## [0.1.3](https://github.com/equinor/fusion-framework/compare/@equinor/fusion-framework-module-context@0.1.2...@equinor/fusion-framework-module-context@0.1.3) (2022-11-01)

@@ -8,0 +29,0 @@

2

dist/esm/client/ContextClient.js

@@ -42,3 +42,3 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {

}
else {
else if (idOrItem !== __classPrivateFieldGet(this, _ContextClient_currentContext$, "f").value) {
__classPrivateFieldGet(this, _ContextClient_currentContext$, "f").next(idOrItem);

@@ -45,0 +45,0 @@ }

@@ -6,4 +6,5 @@ import { module } from './module';

export { ContextModuleConfigurator, } from './configurator';
export { ContextProvider } from './provider';
export { default, module as contextModule, moduleKey as contextModuleKey, } from './module';
export * from './types';
//# sourceMappingURL=index.js.map

@@ -17,8 +17,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

initialize: (args) => __awaiter(void 0, void 0, void 0, function* () {
var _a;
const config = yield args.config.createConfig(args);
const event = args.hasModule('event') ? yield args.requireInstance('event') : undefined;
return new ContextProvider({ config, event });
const parentContext = (_a = args.ref) === null || _a === void 0 ? void 0 : _a.context;
return new ContextProvider({ config, event, parentContext });
}),
dispose: (args) => {
args.instance.dispose();
},
};
export default module;
//# sourceMappingURL=module.js.map

@@ -12,3 +12,4 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {

};
var _ContextProvider_contextClient, _ContextProvider_contextQuery;
var _ContextProvider_contextClient, _ContextProvider_contextQuery, _ContextProvider_event, _ContextProvider_subscriptions;
import { pairwise, Subscription } from 'rxjs';
import { ContextClient } from './client/ContextClient';

@@ -20,13 +21,27 @@ import Query from '@equinor/fusion-observable/query';

_ContextProvider_contextQuery.set(this, void 0);
const { config, event } = args;
_ContextProvider_event.set(this, void 0);
_ContextProvider_subscriptions.set(this, new Subscription());
const { config, event, parentContext } = args;
__classPrivateFieldSet(this, _ContextProvider_contextClient, new ContextClient(config.getContext), "f");
__classPrivateFieldSet(this, _ContextProvider_contextQuery, new Query(config.queryContext), "f");
if (event) {
__classPrivateFieldGet(this, _ContextProvider_contextClient, "f").currentContext$.subscribe((context) => {
event.dispatchEvent('onCurrentContextChange', {
__classPrivateFieldSet(this, _ContextProvider_event, event, "f");
__classPrivateFieldGet(this, _ContextProvider_subscriptions, "f").add(__classPrivateFieldGet(this, _ContextProvider_contextClient, "f").currentContext$
.pipe(pairwise())
.subscribe(([previous, next]) => {
event.dispatchEvent('onCurrentContextChanged', {
source: this,
canBubble: true,
detail: { context },
detail: { previous, next },
});
});
}));
__classPrivateFieldGet(this, _ContextProvider_subscriptions, "f").add(event.addEventListener('onCurrentContextChanged', (e) => {
if (e.source !== this) {
this.currentContext = e.detail.next;
}
}));
}
if (parentContext) {
__classPrivateFieldGet(this, _ContextProvider_subscriptions, "f").add(parentContext.contextClient.currentContext$.subscribe((next) => (this.currentContext = next)));
}
}

@@ -39,2 +54,5 @@ get contextClient() {

}
get currentContext$() {
return __classPrivateFieldGet(this, _ContextProvider_contextClient, "f").currentContext$;
}
get currentContext() {

@@ -44,7 +62,26 @@ return __classPrivateFieldGet(this, _ContextProvider_contextClient, "f").currentContext;

set currentContext(context) {
__classPrivateFieldGet(this, _ContextProvider_contextClient, "f").setCurrentContext(context);
if (__classPrivateFieldGet(this, _ContextProvider_event, "f")) {
__classPrivateFieldGet(this, _ContextProvider_event, "f")
.dispatchEvent('onCurrentContextChange', {
source: this,
canBubble: true,
cancelable: true,
detail: { context },
})
.then((e) => {
if (!e.canceled) {
__classPrivateFieldGet(this, _ContextProvider_contextClient, "f").setCurrentContext(context);
}
});
}
else {
__classPrivateFieldGet(this, _ContextProvider_contextClient, "f").setCurrentContext(context);
}
}
dispose() {
__classPrivateFieldGet(this, _ContextProvider_subscriptions, "f").unsubscribe();
}
}
_ContextProvider_contextClient = new WeakMap(), _ContextProvider_contextQuery = new WeakMap();
_ContextProvider_contextClient = new WeakMap(), _ContextProvider_contextQuery = new WeakMap(), _ContextProvider_event = new WeakMap(), _ContextProvider_subscriptions = new WeakMap();
export default ContextProvider;
//# sourceMappingURL=provider.js.map
import { AnyModule, ModuleInitializerArgs } from '@equinor/fusion-framework-module';
import { ServicesModule } from '@equinor/fusion-framework-module-services';
import { QueryCtorOptions } from '@equinor/fusion-observable/query';
import { ContextClientOptions } from 'client/ContextClient';
import { ContextClientOptions } from './client/ContextClient';
import { ContextItem, QueryContextParameters } from './types';

@@ -6,0 +6,0 @@ export interface IContextModuleConfig {

import { IModulesConfigurator } from '@equinor/fusion-framework-module';
export declare const enableContext: (config: IModulesConfigurator) => void;
export { ContextModuleConfigurator, IContextModuleConfigurator, IContextModuleConfig, } from './configurator';
export { IContextProvider, ContextProvider } from './provider';
export { default, ContextModule, module as contextModule, moduleKey as contextModuleKey, } from './module';
export * from './types';

@@ -0,1 +1,2 @@

import { Observable } from 'rxjs';
import { IContextModuleConfig } from './configurator';

@@ -10,2 +11,4 @@ import { ContextClient } from './client/ContextClient';

readonly queryClient: Query<ContextItem[], QueryContextParameters>;
readonly currentContext$: Observable<ContextItem | undefined>;
currentContext: ContextItem | undefined;
}

@@ -16,2 +19,3 @@ export declare class ContextProvider implements IContextProvider {

get queryClient(): Query<ContextItem<Record<string, unknown>>[], QueryContextParameters>;
get currentContext$(): Observable<ContextItem | undefined>;
get currentContext(): ContextItem | undefined;

@@ -22,3 +26,5 @@ set currentContext(context: ContextItem | undefined);

event?: ModuleType<EventModule>;
parentContext?: IContextProvider;
});
dispose(): void;
}

@@ -30,4 +36,8 @@ export default ContextProvider;

context: ContextItem | undefined;
}>>;
}, IContextProvider>>;
onCurrentContextChanged: FrameworkEvent<FrameworkEventInit<{
next: ContextItem | undefined;
previous: ContextItem | undefined;
}, IContextProvider>>;
}
}
{
"name": "@equinor/fusion-framework-module-context",
"version": "0.1.3",
"version": "0.3.0",
"description": "",

@@ -36,3 +36,3 @@ "main": "./dist/esm/index.js",

"@equinor/fusion-framework-module": "^1.2.6",
"@equinor/fusion-framework-module-event": "^1.0.13",
"@equinor/fusion-framework-module-event": "^1.1.1",
"@equinor/fusion-framework-module-services": "^0.5.0",

@@ -44,6 +44,6 @@ "@equinor/fusion-observable": "^1.2.1",

"@equinor/fusion-framework-module": "^1.2.5",
"@equinor/fusion-observable": "^1.1.0",
"@equinor/fusion-observable": "^1.2.1",
"rxjs": "^7.5.7"
},
"gitHead": "b0bada58a93067d4f6adfa7f3e47c864c22c5bc9"
"gitHead": "21ae1ec0a760c03a0887eced5532de8443274916"
}

@@ -43,6 +43,8 @@ import { Observable, BehaviorSubject, EMPTY } from 'rxjs';

if (typeof idOrItem === 'string') {
// TODO - compare context
this.resolveContext(idOrItem)
.pipe(catchError(() => EMPTY))
.subscribe((value) => this.#currentContext$.next(value));
} else {
/** only add context if not match */
} else if (idOrItem !== this.#currentContext$.value) {
this.#currentContext$.next(idOrItem);

@@ -49,0 +51,0 @@ }

import { AnyModule, ModuleInitializerArgs } from '@equinor/fusion-framework-module';
import { ServicesModule } from '@equinor/fusion-framework-module-services';
import { QueryCtorOptions } from '@equinor/fusion-observable/query';
import { ContextClientOptions } from 'client/ContextClient';
import { ContextClientOptions } from './client/ContextClient';
import { ContextItem, QueryContextParameters } from './types';

@@ -64,3 +64,3 @@ import { getContextSelector, queryContextSelector } from './selectors';

) {
const config = {
const config: IContextModuleConfig = {
getContext: {

@@ -73,3 +73,2 @@ query: {

},
// TODO
queryContext: {

@@ -81,3 +80,3 @@ client: await this.createContextClientQuery(init),

},
} as IContextModuleConfig;
};

@@ -84,0 +83,0 @@ return this.processConfig(config);

@@ -18,2 +18,4 @@ import { IModulesConfigurator } from '@equinor/fusion-framework-module';

export { IContextProvider, ContextProvider } from './provider';
export {

@@ -20,0 +22,0 @@ default,

@@ -1,2 +0,2 @@

import { Module } from '@equinor/fusion-framework-module';
import { Module, ModulesInstance } from '@equinor/fusion-framework-module';

@@ -26,6 +26,11 @@ import { EventModule } from '@equinor/fusion-framework-module-event';

const event = args.hasModule('event') ? await args.requireInstance('event') : undefined;
return new ContextProvider({ config, event });
const parentContext = (args.ref as ModulesInstance<[ContextModule]>)?.context;
return new ContextProvider({ config, event, parentContext });
},
dispose: (args) => {
(args.instance as ContextProvider).dispose();
},
};
export default module;

@@ -0,1 +1,3 @@

import { Observable, pairwise, Subscription } from 'rxjs';
import { IContextModuleConfig } from './configurator';

@@ -22,2 +24,5 @@

readonly queryClient: Query<ContextItem[], QueryContextParameters>;
readonly currentContext$: Observable<ContextItem | undefined>;
currentContext: ContextItem | undefined;
}

@@ -29,2 +34,6 @@

#event?: ModuleType<EventModule>;
#subscriptions = new Subscription();
public get contextClient() {

@@ -38,2 +47,6 @@ return this.#contextClient;

get currentContext$(): Observable<ContextItem | undefined> {
return this.#contextClient.currentContext$;
}
get currentContext(): ContextItem | undefined {

@@ -44,7 +57,28 @@ return this.#contextClient.currentContext;

set currentContext(context: ContextItem | undefined) {
this.#contextClient.setCurrentContext(context);
if (this.#event) {
/** notify listeners that context is about to change */
this.#event
.dispatchEvent('onCurrentContextChange', {
source: this,
canBubble: true,
cancelable: true,
detail: { context },
})
.then((e) => {
/** check if setting context was prevented by listener */
if (!e.canceled) {
this.#contextClient.setCurrentContext(context);
}
});
} else {
this.#contextClient.setCurrentContext(context);
}
}
constructor(args: { config: IContextModuleConfig; event?: ModuleType<EventModule> }) {
const { config, event } = args;
constructor(args: {
config: IContextModuleConfig;
event?: ModuleType<EventModule>;
parentContext?: IContextProvider;
}) {
const { config, event, parentContext } = args;
this.#contextClient = new ContextClient(config.getContext);

@@ -55,11 +89,40 @@

if (event) {
this.#event = event;
/** this might be moved to client, to await prevention of event */
this.#contextClient.currentContext$.subscribe((context) => {
event.dispatchEvent('onCurrentContextChange', {
canBubble: true,
detail: { context },
});
});
this.#subscriptions.add(
this.#contextClient.currentContext$
.pipe(pairwise())
.subscribe(([previous, next]) => {
event.dispatchEvent('onCurrentContextChanged', {
source: this,
canBubble: true,
detail: { previous, next },
});
})
);
this.#subscriptions.add(
/** observe event from child modules */
event.addEventListener('onCurrentContextChanged', (e) => {
/** loop prevention */
if (e.source !== this) {
this.currentContext = e.detail.next;
}
})
);
}
if (parentContext) {
this.#subscriptions.add(
parentContext.contextClient.currentContext$.subscribe(
(next) => (this.currentContext = next)
)
);
}
}
dispose() {
this.#subscriptions.unsubscribe();
}
}

@@ -71,8 +134,22 @@

interface FrameworkEventMap {
/** dispatch before context changes */
onCurrentContextChange: FrameworkEvent<
FrameworkEventInit<{
context: ContextItem | undefined;
}>
FrameworkEventInit<
{
context: ContextItem | undefined;
},
IContextProvider
>
>;
/** dispatch after context changed */
onCurrentContextChanged: FrameworkEvent<
FrameworkEventInit<
{
next: ContextItem | undefined;
previous: ContextItem | undefined;
},
IContextProvider
>
>;
}
}

@@ -15,2 +15,5 @@ {

"path": "../module-services"
},
{
"path": "../module-event"
}

@@ -17,0 +20,0 @@ ],

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc