@equinor/fusion-framework-module-event
Advanced tools
Comparing version 4.2.0 to 4.2.1
# Change Log | ||
## 4.2.1 | ||
### Patch Changes | ||
- [#2343](https://github.com/equinor/fusion-framework/pull/2343) [`736ef31`](https://github.com/equinor/fusion-framework/commit/736ef310ee101738f9022d581a2b3189b30a2646) Thanks [@odinr](https://github.com/odinr)! - Mutating complex objects like class instances would cause immer to throw an error. This change adds a try-catch block around the creation of immutable copies of event details to handle potential errors and disable mutations if the event details cannot be securely mutated. | ||
**added:** | ||
- Imported `enableMapSet` from `immer` and invoked `enableMapSet()` to support Map and Set types in Immer drafts. | ||
- Added a try-catch block around the creation of immutable copies of event details to handle potential errors and disable mutations if the event details cannot be securely mutated. | ||
**modified:** | ||
- Removed the initial assignment of `#detail` and `#originalDetail` to the immutable copy produced by `immer`. Instead, they are initially assigned the raw `args.detail` value. | ||
- The assignment of `#detail` and `#originalDetail` to an immutable copy is now done inside the try block, ensuring that mutations are only disabled upon failure to create an immutable copy. | ||
- The assignment of `#source` is now done directly from `args.source` without attempting to create an immutable copy. | ||
## 4.2.0 | ||
@@ -4,0 +21,0 @@ |
@@ -13,3 +13,4 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { | ||
var _FrameworkEvent_detail, _FrameworkEvent_originalDetail, _FrameworkEvent_source, _FrameworkEvent_canceled, _FrameworkEvent_cancelable, _FrameworkEvent_mutableDetails, _FrameworkEvent_canBubble, _FrameworkEvent_created; | ||
import { produce } from 'immer'; | ||
import { produce, enableMapSet } from 'immer'; | ||
enableMapSet(); | ||
/** | ||
@@ -45,6 +46,16 @@ * Represents a framework event with customizable details and behavior. | ||
_FrameworkEvent_created.set(this, Date.now()); | ||
__classPrivateFieldSet(this, _FrameworkEvent_detail, produce(args.detail, () => { }), "f"); | ||
__classPrivateFieldSet(this, _FrameworkEvent_detail, args.detail, "f"); | ||
__classPrivateFieldSet(this, _FrameworkEvent_originalDetail, args.detail, "f"); | ||
__classPrivateFieldSet(this, _FrameworkEvent_mutableDetails, !!args.mutableDetails, "f"); | ||
__classPrivateFieldSet(this, _FrameworkEvent_originalDetail, produce(args.detail, () => { }), "f"); | ||
__classPrivateFieldSet(this, _FrameworkEvent_source, produce(args.source, () => { }), "f"); | ||
try { | ||
/** Attempt to create an immutable copy of the event details */ | ||
const detail = produce(args.detail, () => { }); | ||
__classPrivateFieldSet(this, _FrameworkEvent_detail, detail, "f"); | ||
__classPrivateFieldSet(this, _FrameworkEvent_originalDetail, detail, "f"); | ||
} | ||
catch (error) { | ||
/** The event details cannot be securely mutated, disable mutations */ | ||
__classPrivateFieldSet(this, _FrameworkEvent_mutableDetails, false, "f"); | ||
} | ||
__classPrivateFieldSet(this, _FrameworkEvent_source, args.source, "f"); | ||
__classPrivateFieldSet(this, _FrameworkEvent_cancelable, !!args.cancelable, "f"); | ||
@@ -51,0 +62,0 @@ __classPrivateFieldSet(this, _FrameworkEvent_canBubble, args.canBubble === undefined ? true : args.canBubble, "f"); |
// Generated by genversion. | ||
export const version = '4.2.0'; | ||
export const version = '4.2.1'; | ||
//# sourceMappingURL=version.js.map |
@@ -1,1 +0,1 @@ | ||
export declare const version = "4.2.0"; | ||
export declare const version = "4.2.1"; |
{ | ||
"name": "@equinor/fusion-framework-module-event", | ||
"version": "4.2.0", | ||
"version": "4.2.1", | ||
"description": "Fusion module for events", | ||
@@ -5,0 +5,0 @@ "main": "./dist/esm/index.js", |
import type { ModuleInstance } from '@equinor/fusion-framework-module'; | ||
import type { IEventModuleProvider } from './provider'; | ||
import { produce, type Draft } from 'immer'; | ||
import { produce, enableMapSet, type Draft } from 'immer'; | ||
enableMapSet(); | ||
export declare interface FrameworkEventMap { | ||
@@ -161,6 +163,15 @@ onModulesLoaded: FrameworkEvent<FrameworkEventInit<ModuleInstance, IEventModuleProvider>>; | ||
) { | ||
this.#detail = produce(args.detail, () => {}) as FrameworkEventInitDetail<TInit>; | ||
this.#detail = args.detail; | ||
this.#originalDetail = args.detail; | ||
this.#mutableDetails = !!args.mutableDetails; | ||
this.#originalDetail = produce(args.detail, () => {}) as FrameworkEventInitDetail<TInit>; | ||
this.#source = produce(args.source, () => {}) as FrameworkEventInitSource<TInit>; | ||
try { | ||
/** Attempt to create an immutable copy of the event details */ | ||
const detail = produce(args.detail, () => {}) as FrameworkEventInitDetail<TInit>; | ||
this.#detail = detail; | ||
this.#originalDetail = detail; | ||
} catch (error) { | ||
/** The event details cannot be securely mutated, disable mutations */ | ||
this.#mutableDetails = false; | ||
} | ||
this.#source = args.source; | ||
this.#cancelable = !!args.cancelable; | ||
@@ -167,0 +178,0 @@ this.#canBubble = args.canBubble === undefined ? true : args.canBubble; |
// Generated by genversion. | ||
export const version = '4.2.0'; | ||
export const version = '4.2.1'; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
144360
1146