Skip to content
This repository was archived by the owner on Aug 14, 2024. It is now read-only.

Commit 66cf31a

Browse files
committed
refactor(README.md): Added memory and memorized documentation
1 parent 8ab338c commit 66cf31a

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

README.md

+47
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,32 @@ const result = (await RC.write(void 0, writeOpts)).unwrap();
6161
assert.strictEqual(result, void 0);
6262
```
6363

64+
memoize:
65+
66+
```ts
67+
import * as RC from "@nodesecure/rc";
68+
69+
const configurationPayload = (
70+
await RC.read(void 0, { createMode: "ci" })
71+
).unwrap()
72+
73+
RC.memoize(configurationPayload, { overwrite: false });
74+
```
75+
76+
memoized:
77+
78+
```ts
79+
import * as RC from "@nodesecure/rc";
80+
81+
const configurationPayload = (
82+
await RC.read(void 0, { createMode: "ci", memoize: true })
83+
).unwrap();
84+
85+
const result = RC.memoized({
86+
default: {}
87+
}).unwrap();
88+
```
89+
6490
> 👀 .read and .write return Rust like [Result](https://doc.rust-lang.org/std/result/) object. Under the hood we use [ts-results](https://github.com/vultix/ts-results) to achieve this.
6591
6692
## API
@@ -125,6 +151,27 @@ export interface writePartialPayload {
125151

126152
export type writeOptions = writeCompletePayload | writePartialPayload;
127153
```
154+
### memoize(payload: Partial<RC>, options: IMemoizeOptions = {}): void
155+
By default, the memory API overwrites the previous stored payload. When the `OVERWRITE` option is `false`, it merges new properties with existing properties.
156+
157+
```ts
158+
export interface IMemoizeOptions {
159+
/** * @default true */
160+
overwrite?: boolean;
161+
}
162+
```
163+
The `overwrite` option is used to specify whether data should be overwritten or merged.
164+
165+
### memoized(options: IMemoizedOptions): Partial<RC> | null
166+
This method returns null, when the default value is null, otherwise, it returns the current value of `memoizedValue`.
167+
168+
```ts
169+
export interface IMemoizedOptions {
170+
/** * @default null */
171+
defaultValue: Partial<RC> | null;
172+
}
173+
```
174+
If the `defaultValue` property is at null, then this value will be returned when `memoized` is called.
128175

129176
### homedir(): string
130177

src/functions/memoize.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export interface IMemoizeOptions {
1111
overwrite?: boolean;
1212
}
1313

14-
interface IMemoizedOptions {
14+
export interface IMemoizedOptions {
1515
/** * @default null */
1616
defaultValue: Partial<RC> | null;
1717
}

0 commit comments

Comments
 (0)