Skip to content

Commit a51b064

Browse files
refactor(Data): add clear() method to set the value to null.
1 parent 3827dc7 commit a51b064

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/lib/data.class.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class Data<Type> extends DataCore<Type> {
3737
#value;
3838

3939
/**
40-
* Creates an instance of `Data` child class.
40+
* Creates an instance of `Data`.
4141
* @constructor
4242
* @param {Type} value Initial data value of generic type variable `Type`.
4343
*/
@@ -46,10 +46,20 @@ export class Data<Type> extends DataCore<Type> {
4646
this.#value = new Value(value);
4747
}
4848

49+
/**
50+
* @description Clears the value to `null`.
51+
* @public
52+
* @returns {this} Returns `this` current instance.
53+
*/
54+
public clear(): this {
55+
this.#value.set(null as unknown as Type);
56+
return this;
57+
}
58+
4959
/**
5060
* @description Destroys the `Value` object by setting it to `null`.
5161
* @public
52-
* @returns {this} Returns the current instance.
62+
* @returns {this} Returns `this` current instance.
5363
*/
5464
public destroy(): this {
5565
this.#value = null as any;
@@ -60,7 +70,7 @@ export class Data<Type> extends DataCore<Type> {
6070
* @description Sets the data value.
6171
* @public
6272
* @param {Type} value The data of `Type` to set.
63-
* @returns {this} Returns the current instance.
73+
* @returns {this} Returns `this` current instance.
6474
*/
6575
public set(value: Type) {
6676
super.validate();

0 commit comments

Comments
 (0)