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

object-record

v0.1.1

Published

a simple object-record makes it possible to time travel among changes to a a complex javascript json object

Downloads

2

Readme

Object-Record

A simple javascript lib that records changes of a javascript object in an effective way, making it possible to navigate among those changes

Installation

npm install --save object-record
or
yarn add object-record

Documentation

  • [createObjectHistory] initialize an object recorder with an initial object as starting point of your object history together with some configurations, such as the history size, by default it's 50
    	let objHistory = createObjectHistory({
          	obj: startObj,
    		history: {
    			count: 3
    		}
    	})
    The returned value of createObjectHistory is a javascript object, consisting of functions for updating and navigating object history
    1. [update(newObject, cause)] this function should be called each time there happens a change to your object.

      	/*
      	@newObj 	is the new object after a change
      	@cause		is the optional reason why this change occurred.
      
      	@return     the indexing of current item in history is updated as the newObj
      	*/		
      	update(newObj, cause) {
      
      	}
    2. [back()] this function is used to backwards navigate from current object one in history.

      	/*
      	@return     the indexing of current item in history is updated as the one before current one if possible
      	*/		
      	back() {
      
      	}
    3. [forward()] this function is used to forward navigate from current object one in history.

      	/*
      	@return     the indexing of current item in history is updated as the one after current one if possible
      	*/		
      	forward() {
      
      	}
    4. [go(steps)] this helper function is used to continuously navigate many steps from current object one in history.

      	/*
      	@steps		if steps > 0, forward navigate so many steps. Otherwise, backwards navigate so many steps
      	@return     the indexing of current item in history is updated so many steps forward or backwards based on steps
      	*/		
      	go(steps) {
      
      	}
    5. [current()] this function is used to retrive the current object one in history.

      	/*
      	@return     the current object in history list, how many before it and how many after it
      	*/		
      	current() {
      
      	}

Implementation

The implementation of history list of object changes is written with spesical attention to effective memory usage. Therefore execept the starting object, no javascript object is directly stored in memory. In stead, we only store the difference between the current js object and the new one when update(newObj, cause) is being called. And those difference can be used to rebuild js object while navigating amoung object history

User Case

A typical scenario for applying the object-record is an alternative implementation of time travling of Redux state.

1.[History Updating] Each time Redux dispatch is called, the current state in store is updated by reducers, therefore we can call objHistory.update(currentState, action) to keep record of all changes.

	function dispatch(action) {
		...
		try {
	      isDispatching = true
	      currentState = currentReducer(currentState, action)
	      objHistory.update(currentState, action)
	    } finally {
	      isDispatching = false
	    }
	    ...
	}

2.[Time travelling] Redux store exports an extra function called, travel to clients of Redux so that UI could be time travelling in state changes of application store:

		...
		  function travel(nr) {
		    let cs = objHistory.go(nr).cur.obj
		    if (cs) {
		      currentState = cs
		      const listeners = currentListeners = nextListeners
		      for (let i = 0; i < listeners.length; i++) {
		        const listener = listeners[i]
		        listener()
		      }
		    }
		    
		  }

		...

		return {
		    *travel*,
		    dispatch,
		    subscribe,
		    getState,
		    replaceReducer,
		    [$$observable]: observable
		}

Time Travelling in Redux with object-record

Open Source Code

Source code for this npm package is available idavollen@github

Enjoy!

License

MIT