Giter VIP home page Giter VIP logo

diffpatcher's Introduction

diffpatcher

Build Status

Browser support

Diffpatcher is a small library that lets you treat hashes as if they were git repositories.

diff

Diff function that takes two hashes and returns delta hash.

var diff = require("diffpatcher/diff")

diff({ a: { b: 1 }, c: { d: 2 } },      // hash#1
     { a: { e: 3 }, c: { d: 4 } })      // hash#2

// => {                                 // delta
//      a: {
//        b: null,        // -
//        e: 3            // +
//      },
//      c: {
//        d: 4            // ±
//      }
//    }

As you can see from the example above delta makes no real distinction between proprety upadate and property addition. Try to think of additions as an update from undefined to whatever it's being updated to.

patch

Patch fuction takes a hash and a delta and returns a new hash which is just like orginial but with delta applied to it. Let's apply delta from the previous example to the first hash from the same example

var patch = require("diffpatcher/patch")

patch({ a: { b: 1 }, c: { d: 2 } },     // hash#1
      {                                 // delta
        a: {
          b: null,        // -
          e: 3            // +
        },
        c: {
          d: 4            // ±
        }
      })

// => { a: { e: 3 }, c: { d: 4 } }      // hash#2

That's about it really, just diffing hashes and applying thes diffs on them.

rebase

And as Linus mentioned everything in git can be expressed with rebase, that also pretty much the case for diffpatcher. rebase takes target hash, and rebases parent onto it with diff applied.

Install

npm install diffpatcher

diffpatcher's People

Contributors

gozala avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.