Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,8 @@
"store",
"save state",
"Toreda"
]
],
"dependencies": {
"@toreda/strong-types": "^0.28.5"
}
}
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './stateValue';
export * from './state';
1 change: 1 addition & 0 deletions src/options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export interface StateData {}
25 changes: 25 additions & 0 deletions src/state.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {StateValue} from './stateValue';
import {StateData} from './options';

export class State {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the state class make sure to include an optional StateData argument in the form step for which includes any preexisting state.
also make sure to include the adapter logic. the state class acts as a proxy and gets called by the user but internally passes all the calls, which are just save and retrieve for now, to the adapter. why use an adapter? we want settings and important values stored on device whenever possible and each platform handles it differently. writing adapters gives us a standardized interface to work with keys while also writing custom logic per platform.

public readonly stateValue: StateValue;

constructor(options?: StateData) {
this.stateValue = new StateValue();
}

async save(stateValue: StateValue): Promise<void> {
const map = new Map();

if (this.stateValue.key) {
map.set(this.stateValue.key, this.stateValue.value);
}
}

async retrieve(key): Promise<unknown> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make retrieve a generic so that it’s called with a type:
ex: async function retrieve(…)
we will want specific type helpers which pass a type in like retrieveString which returns retrieve(…)

if (key) {
return key.value;
}
return null;
}
}
11 changes: 11 additions & 0 deletions src/stateValue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {Text, textMake} from '@toreda/strong-types';

export class StateValue {
public readonly key: Text;
public readonly value: unknown;

constructor() {
this.key = textMake('');
this.value = this.value;
}
}
15 changes: 14 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -880,14 +880,22 @@
version "2.2.0"
resolved "https://registry.yarnpkg.com/@toreda/eslint-config/-/eslint-config-2.2.0.tgz#ee3e0bb8d2263461ea214e04c728f498f2b09278"

"@toreda/log@^0.6.16":
"@toreda/log@^0.6.12", "@toreda/log@^0.6.16":
version "0.6.16"
resolved "https://registry.yarnpkg.com/@toreda/log/-/log-0.6.16.tgz#bdca453a08242b655804035d27cf788bcd9b91e1"

"@toreda/prettier-config@^1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@toreda/prettier-config/-/prettier-config-1.0.1.tgz#bd6c47352aa99560617f0f4a29f16ab7c3070b86"

"@toreda/strong-types@^0.28.5":
version "0.28.5"
resolved "https://registry.yarnpkg.com/@toreda/strong-types/-/strong-types-0.28.5.tgz#a62bc6f27c0f4a7835b0a50422eee3aea4956607"
integrity sha512-l6yUw1kaQP/lM2z8O5qr7XNDRI3ik1X874uBdKML164H42AIyyw8i69LV9ecd0xLGeMsLzzWJ4bjUDqYcQfmvQ==
dependencies:
"@toreda/log" "^0.6.12"
big.js "^6.1.1"

"@toreda/types@^2.11.0":
version "2.11.0"
resolved "https://registry.yarnpkg.com/@toreda/types/-/types-2.11.0.tgz#7209b0a178799e852b164836404168357a2c3c6c"
Expand Down Expand Up @@ -1664,6 +1672,11 @@ base@^0.11.1:
mixin-deep "^1.2.0"
pascalcase "^0.1.1"

big.js@^6.1.1:
version "6.1.1"
resolved "https://registry.yarnpkg.com/big.js/-/big.js-6.1.1.tgz#63b35b19dc9775c94991ee5db7694880655d5537"
integrity sha512-1vObw81a8ylZO5ePrtMay0n018TcftpTA5HFKDaSuiUDBo8biRBtjIobw60OpwuvrGk+FsxKamqN4cnmj/eXdg==

binary-extensions@^1.0.0:
version "1.13.1"
resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-1.13.1.tgz#598afe54755b2868a5330d2aff9d4ebb53209b65"
Expand Down