Skip to content

Commit

Permalink
Add overrideValue
Browse files Browse the repository at this point in the history
In preparation for #633
  • Loading branch information
vanruesc committed Jan 4, 2025
1 parent bcb9cb9 commit 769b961
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/core/io/Resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ export abstract class Resource<T = unknown> extends EventDispatcher<BaseEventMap

private _value: T | null;

/**
* @see {@link overrideValue}
*/

private _overrideValue: T | null;

/**
* Constructs a new resource wrapper.
*
Expand All @@ -46,6 +52,7 @@ export abstract class Resource<T = unknown> extends EventDispatcher<BaseEventMap

this.id = Resource.idManager.getNextId();
this._value = value;
this._overrideValue = null;

}

Expand All @@ -55,7 +62,7 @@ export abstract class Resource<T = unknown> extends EventDispatcher<BaseEventMap

get value(): T | null {

return this._value;
return this._overrideValue ?? this._value;

}

Expand All @@ -66,4 +73,23 @@ export abstract class Resource<T = unknown> extends EventDispatcher<BaseEventMap

}

/**
* An additional value that overrides the main {@link value}.
*
* @internal
*/

get overrideValue(): T | null {

return this._overrideValue;

}

set overrideValue(value: T | null) {

this._overrideValue = value;
this.dispatchEvent({ type: Resource.EVENT_CHANGE });

}

}

0 comments on commit 769b961

Please sign in to comment.