npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

redux-time-machine

v2.0.1

Published

Convert your redux in a time machine. Basic to implement do-undo system in your application.

Downloads

1

Readme

ReduxTimeMachine

Redux Time Machine. Convert your redux in a time machine. Basic to implement do-undo system in your application.

Build Status NPM Version Chat on Gitter

Installation

ReduxTimeMachine is available as an NPM package. You can install ReduxTimeMachine in your project's directory as usual:

$ npm install redux-time-machine --save

Usage

ReduxTimeMachine


StateHubTimeMachine class api

ReduxTimeMachine provides you with a class to instanciate your time machine hub node.

StateHubTimeMachine is a Generic class and can be configured in advance so TypeScript can provide the right information.

Generics

On creating an instance of StateHub you need to provide the following Generics:

  1. State - Provide your state interface.
  2. Dispatchers - Provide your dispatchers interface.
  3. HubModel - Provide the Hub model interface.
  4. Result - Empty object where the node builder will store the used methods.
import { StateHubTimeMachine } from 'redux-time-machine';

const stateHubTimeMachine = new StateHubTimeMachine<State, Dispatchers, Hub, {}>();

For more information see StateHub Node API

How ReduxTimeMachine works.

ReduxTimeMachine abstracts the way to store the past, present and future values.

Present value

The present value is the current state value.

Past values

The past value is an array where ReduxTimeMachine pushes every old state when present state value has changed.

Future values

The future value is an array where ReduxTimeMachine pushes every state if the user navigated back to a past value.

Initial Value
{
    test: 'test'
}
On creating the ReduxTimeMachine node
{
    test: {
        past: [],
        present: 'test',
        future: []
    }
}

ReduxHub Node API

See ReduxHub Node API

dispatchers

In addition to the dispatchers created as a ReduxHub Node, ReduxTimeMachine has other predefined actions to navigate backwards and forwards over the state.

undo

When this dispatcher is executed:

  • The current state value is moved to the future.
  • The last state value in past is moved to the present value.

State before dispatching undo

{
    test: {
        past: ['test', 'test1', 'test2'],
        present: 'test3',
        future: []
    }
}

Dispatching undo

node.dispatchers.undo();

State after dispatching undo

{
    test: {
        past: ['test', 'test1'],
        present: 'test2',
        future: ['test3']
    }
}
redo

When this dispatcher is executed:

  • The current state value is moved to the future.
  • The last state value in past is moved to the present value.

State before dispatching redo

{
    test: {
        past: ['test', 'test1'],
        present: 'test2',
        future: ['test3']
    }
}

Dispatching redo

node.dispatchers.redo();

State after dispatching redo

{
    test: {
        past: ['test', 'test1', 'test2'],
        present: 'test3',
        future: []
    }
}
jumpToPast

This dispatcher receives a number that is the index in the past array you want to move back to.

When this dispatcher is executed:

  • The value stored in the past array position index passed to the dispatcher will be stored into the present value.
  • The previous values to the position index will remain in past array.
  • The values after position index will be added at the beginning of the future array.

State before dispatching jumpToPast

{
    test: {
        past: ['test', 'test1'],
        present: 'test2',
        future: ['test3']
    }
}

Dispatching jumpToPast

node.dispatchers.jumpToPast(0);

State after dispatching jumpToPast

{
    test: {
        past: [],
        present: 'test',
        future: ['test1', 'test2', 'test3']
    }
}
jumpToFuture

This dispatcher receives a number that is the index in the past array you want to move back to.

When this dispatcher is executed:

  • The value stored in the future array position index passed to the dispatcher will be stored into the present value.
  • The previous values to the position index will be added to the past array.
  • The values after position index will remain in the future array.

State before dispatching jumpToFuture

{
    test: {
        past: ['test', 'test1'],
        present: 'test2',
        future: ['test3', 'test4']
    }
}

Dispatching jumpToFuture

node.dispatchers.jumpToFuture(1);

State after dispatching jumpToFuture

{
    test: {
        past: ['test', 'test1', 'test2', 'test3'],
        present: 'test4',
        future: []
    }
}

getState

This method returns present node state.

node.getState();

API documentation

API Documentation can be generated executing npm run docs. The documentation generated can be found inside the docs folder.

Build the source

This library has been written using TypeScript. If you need to use it in your project but you are not working with TypeScript you can always to build the code using npm run build This command will lint your code, run the tests and compile to TypeScript.

Contributing

This project is maintained by a community of developers. Contributions are welcome and appreciated. You can find ReduxTimeMachine on GitHub; feel free to start an issue or create a pull requests: https://github.com/tcorral/redux-time-machine

For more information, read the contribution guide.

License

Copyright (c) 2019 Tomas Corral. Copyright (c) 2019 ReduxTimeMachine Contributors. Licensed under the MIT License.