Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add state storage #31

Closed
ro31337 opened this issue May 14, 2016 · 0 comments
Closed

Add state storage #31

ro31337 opened this issue May 14, 2016 · 0 comments

Comments

@ro31337
Copy link
Owner

ro31337 commented May 14, 2016

StateStorage keeps state data, updates state when underlying storage updates. Objects in application can be stateful. StateStorage is basic structure that implements persistent state (won't go away on app restart).

Key for constructor below is already existing new StateKey(...).toString() - something that identifies particular command for particular user for particular platform.

StateStorage implementation:

constructor(key) - Constructor. key - state key, for example telegram_31337_4566bd48-d369-4594-aa1e-fb5dae1acf43.
load() - Loads state from the actual storage. Returns promise which is executed when changes were initially loaded.
save() - updates the storage with current state, returns promise. Will only overwrite the children enumerated in state.
setState({ ... }) - updates selected properties.
state - actual state.
dispose - unsubscribes itself from storage updates (off method for Firebase).

Usage example:

new StateStorage('telegram_31337_4566bd48-d369-4594-aa1e-fb5dae1acf43')
    .load()
    .then((storage) => {
        console.dir(storage.state); // => {}
        storage.setState({ a: 1, b: 2 });
        storage.save().then(() => {
            console.log('saved');
        })
    });
ro31337 pushed a commit that referenced this issue May 18, 2016
ro31337 added a commit that referenced this issue May 18, 2016
@ro31337 ro31337 closed this as completed May 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant