Skip to content

Commit

Permalink
feat(ref): make ref return a deeply readonly object
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharmath committed May 26, 2019
1 parent 46b36e7 commit 42674b9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"dependencies": {
"dbl-linked-list-ds": "^2.0.0",
"in-node": "^1.0.0",
"ts-scheduler": "^8.0.0"
"ts-scheduler": "^8.0.0",
"utility-types": "^3.7.0"
}
}
9 changes: 5 additions & 4 deletions src/main/Ref.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* Created by tushar on 2019-05-25
*/
import {DeepReadonly} from 'utility-types'
import {FIO, Task} from './FIO'

export class Ref<A> {
Expand All @@ -9,10 +10,10 @@ export class Ref<A> {
}
private constructor(private value: A) {}

public read(): Task<A> {
return FIO.try(() => this.value)
public read(): Task<DeepReadonly<A>> {
return FIO.try(() => this.value as DeepReadonly<A>)
}
public update(ab: (a: A) => A): Task<A> {
return FIO.try(() => (this.value = ab(this.value)))
public update(ab: (a: DeepReadonly<A>) => A): Task<A> {
return FIO.try(() => (this.value = ab(this.value as DeepReadonly<A>)))
}
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6281,6 +6281,11 @@ util-extend@^1.0.1:
resolved "https://registry.yarnpkg.com/util-extend/-/util-extend-1.0.3.tgz#a7c216d267545169637b3b6edc6ca9119e2ff93f"
integrity sha1-p8IW0mdUUWljeztu3GypEZ4v+T8=

utility-types@^3.7.0:
version "3.7.0"
resolved "https://registry.yarnpkg.com/utility-types/-/utility-types-3.7.0.tgz#51f1c29fa35d4267488345706efcf3f68f2b1933"
integrity sha512-mqRJXN7dEArK/NZNJUubjr9kbFFVZcmF/JHDc9jt5O/aYXUVmopHYujDMhLmLil1Bxo2+khe6KAIVvDH9Yc4VA==

uuid@^3.3.2:
version "3.3.2"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.3.2.tgz#1b4af4955eb3077c501c23872fc6513811587131"
Expand Down

0 comments on commit 42674b9

Please sign in to comment.