GithubHelp home page GithubHelp logo

imclab / patcher.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mikolalysenko/patcher.js

0.0 1.0 0.0 155 KB

JSON diffing and patching library

Home Page: http://0fps.wordpress.com

License: Other

patcher.js's Introduction

              _        _               _     
             | |      | |             (_)    
  _ __   __ _| |_  ___| |__   ___ _ __ _ ___ 
 | '_ \ / _` | __|/ __| '_ \ / _ \ '__| / __|
 | |_) | (_| | |_| (__| | | |  __/ | _| \__ \
 | .__/ \__,_|\__|\___|_| |_|\___|_|(_) |___/
 | |                                 _/ |    
 |_|                                |__/     

=================================================

   A JSON patching and diffing library
   
    (c) 2011 Mikola Lysenko
   
=================================================

1. About

patcher.js is a simple javascript library for diffing and
patching JSON documents.  This can be useful, for example,
in a networked environment where retransmitting large JSON
documents is too expensive.


2. Example:

>
> //Start with two distinct objects on the server
> // prev represents a copy of the state of the object on the client
> // next represents a copy of the state of the object on the server
> //
> //1. Compute a patch
> patch = patcher.computePatch(prev, next);
> 
> //2. Send patch over the network
>
> //3. Apply the patch on the client
> patcher.applyPatch(prev, patch);
> 
> //Final invariant:
> //   prev represents an equivalent object to JSON.parse(JSON.stringify(next))
>



3.  API

There are two functions in patcher.js:

  function computePatch(prev, next, update_in_place);

  The argument prev is the object which the patch targets.
  
    * If update_in_place is set to true, then the function
    will simultaneously update both prev and next at the same
    time.
    * If prev and next are equal, then the method returns null
    * Constructing this patch requires time linear on the 
    size of the two documents.
    * Patches are computed at the level of the objects and
    arrays.  String modifications are simply retransmitted
    
  
  
  function applyPatch(obj, patch)
  
  This function applies a patch to the JSON document obj


4. Future

  * More test cases!
  * Use data types cleverly
  * Binary serialization

patcher.js's People

Contributors

mikolalysenko avatar

Watchers

JT5D 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.