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

flyd-undo

v0.0.1

Published

Flyd undo by tracking state histories.

Downloads

2

Readme

flyd-undo

This is a flyd utility that makes it easier to create an undo/redo system in your UI. You create a stream of state and actions on that state, and this function will track past versions. Pass in undo and redo streams to push and pop the current version of the state.

This function creates a stream of objects with three properties: current, backward, and forward. The current key holds the current state. The backward key holds an array of previous states (up to a defined limit). And the forward state holds a cache of states that have been undone for the purpose of redo. Thus, the behavior of the flyd-undo function is:

  • Undoing causes the current state to move onto the top of the forward stack, and moves the state from the top of the backward stack into the current slot.
  • Redoing causes the the current state to move to the top of the backward stack, and moves the state from the top of the forward stack into the current slot.
  • Performing any action causes a new state to be created. The previous state gets pushed to the top of the backward stack, and the new state replaces it in the current slot.
  • Performing any action also removes all states from the forward stack (removing the ability for previous redos)

API

flydUndo({
  default // default, starting state on pageload
, undo // a stream of undo events that trigger a new undo action
, redo // a stream of redo events that trigger a new redo action
, actions // an array of pairs of streams and updater functions similar to scanMerge. Every updater function takes the previous state and the value from the stream and returns a new state.
})

Example

import R from 'ramda'
import 'flyd' from flyd
import flydUndo from 'flyd-undo'

// This example is a circle drawer
// Click the canvas to create a new circle

// Event stream of undo button clicks
const clickUndo$ = flyd.stream()
// Event stream of redo button clicks
const clickRedo$ = flyd.stream()
// Event stream of clicking on an svg area to create a circle
const clickSvg$ = flyd.stream()

const circles$ = flydUndo({
  default: []
, undo: clickUndo$
, redo: clickRedo$
, actions: [
    [clickSvg$,  appendCircle]
  ]
})

function appendCircle(circles, clickEvent) {
  return R.append(
    {radius: 10, cx: clickEvent.clientX, cy: clickEvent.clientY}
  , circles
  )
}

circles$().current // []
circles$().backward // []
circles$().forward // []

clickSvg$({clientX: 10, clientY: 10}) // trigger click event

circles$().current // [{cx: 10, cy: 10, radius: 10}]
circles$().backward // [[]]
circles$().forward // []

clickSvg$({clientX: 50, clientY: 50}) // trigger click event

circles$().current // [{cx: 50, cy: 50, radius: 10}, {cx: 10, cy: 10, radius: 10}]
circles$().backward // [[{cx: 10, cy: 10, radius: 10}], []]
circles$().forward // []

clickUndo$(true) // trigger undo event

circles$().current // [{cx: 10, cy: 10, radius: 10}]
circles$().backward // [[]]
circles$().forward // [[{cx: 50, cy: 50, radius: 10}, {cx: 10, cy: 10, radius: 10}]]

clickUndo$(true) // trigger another undo event

circles$().current // [[]]
circles$().backward // []
circles$().forward // [[{cx: 10, cy: 10, radius: 10}], [{cx: 50, cy: 50, radius: 10}, {cx: 10, cy: 10, radius: 10}]]

clickRedo$(true) // trigger redo event

circles$().current // [{cx: 10, cy: 10, radius: 10}]
circles$().backward // []
circles$().forward // [[{cx: 50, cy: 50, radius: 10}, {cx: 10, cy: 10, radius: 10}]]

clickSvg$({clientX: 70, clientY: 70}) // trigger another circle creation (an action)

circles$().current // [{cx: 70, cy: 70, radius: 10}, {cx: 10, cy: 10, radius: 10}]
circles$().backward // [[{cx: 10, cy: 10, radius: 10}]]
circles$().forward // []

Dev

  • Build with babel index.es6 > index.js
  • Run tests with npm run test or zuul --local 8888 --ui mocha-qunit -- test