Skip to content

Commit 42674b9

Browse files
committed
feat(ref): make ref return a deeply readonly object
1 parent 46b36e7 commit 42674b9

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"dependencies": {
6161
"dbl-linked-list-ds": "^2.0.0",
6262
"in-node": "^1.0.0",
63-
"ts-scheduler": "^8.0.0"
63+
"ts-scheduler": "^8.0.0",
64+
"utility-types": "^3.7.0"
6465
}
6566
}

src/main/Ref.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/**
22
* Created by tushar on 2019-05-25
33
*/
4+
import {DeepReadonly} from 'utility-types'
45
import {FIO, Task} from './FIO'
56

67
export class Ref<A> {
@@ -9,10 +10,10 @@ export class Ref<A> {
910
}
1011
private constructor(private value: A) {}
1112

12-
public read(): Task<A> {
13-
return FIO.try(() => this.value)
13+
public read(): Task<DeepReadonly<A>> {
14+
return FIO.try(() => this.value as DeepReadonly<A>)
1415
}
15-
public update(ab: (a: A) => A): Task<A> {
16-
return FIO.try(() => (this.value = ab(this.value)))
16+
public update(ab: (a: DeepReadonly<A>) => A): Task<A> {
17+
return FIO.try(() => (this.value = ab(this.value as DeepReadonly<A>)))
1718
}
1819
}

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6281,6 +6281,11 @@ util-extend@^1.0.1:
62816281
resolved "https://registry.yarnpkg.com/util-extend/-/util-extend-1.0.3.tgz#a7c216d267545169637b3b6edc6ca9119e2ff93f"
62826282
integrity sha1-p8IW0mdUUWljeztu3GypEZ4v+T8=
62836283

6284+
utility-types@^3.7.0:
6285+
version "3.7.0"
6286+
resolved "https://registry.yarnpkg.com/utility-types/-/utility-types-3.7.0.tgz#51f1c29fa35d4267488345706efcf3f68f2b1933"
6287+
integrity sha512-mqRJXN7dEArK/NZNJUubjr9kbFFVZcmF/JHDc9jt5O/aYXUVmopHYujDMhLmLil1Bxo2+khe6KAIVvDH9Yc4VA==
6288+
62846289
uuid@^3.3.2:
62856290
version "3.3.2"
62866291
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.3.2.tgz#1b4af4955eb3077c501c23872fc6513811587131"

0 commit comments

Comments
 (0)