File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Abstract.
2
+ import { Immutability } from './immutability.abstract' ;
3
+ // Class.
4
+ import { ReadonlyData } from './readonly-data.class' ;
5
+ /**
6
+ * @description A class that stores and returns an immutable version of the provided value.
7
+ * The value is frozen at runtime and marked as `readonly` at type level.
8
+ * @export
9
+ * @class ImmutableData
10
+ * @template Type The original input type.
11
+ * @extends {ReadonlyData<Type> }
12
+ */
13
+ export class ImmutableData < Type > extends ReadonlyData < Type > {
14
+ /**
15
+ * @description Returns the `string` tag representation of the `ImmutableData` class when used in `Object.prototype.toString.call(instance)`.
16
+ * @public
17
+ * @readonly
18
+ * @type {string }
19
+ */
20
+ public override get [ Symbol . toStringTag ] ( ) : string {
21
+ return ImmutableData . name ;
22
+ }
23
+
24
+ /**
25
+ * Creates an instance of `ImmutableData`.
26
+ * @constructor
27
+ * @param {Type } value Initial value to store.
28
+ */
29
+ constructor ( value : Type ) {
30
+ super ( Immutability . deepFreeze ( value ) ) ;
31
+ }
32
+
33
+ /**
34
+ * @description Sets the data value.
35
+ * @public
36
+ * @param {Type } value The data value of `Type` to set.
37
+ * @returns {this } The `this` current instance.
38
+ */
39
+ public override set ( value : Type ) : this {
40
+ return super . set ( Immutability . deepFreeze ( value ) ) ;
41
+ }
42
+ }
You can’t perform that action at this time.
0 commit comments