autonome / json-sync Goto Github PK
View Code? Open in Web Editor NEWThis project forked from sayrer/json-sync
Partial Updates for JSON resources
License: MIT License
This project forked from sayrer/json-sync
Partial Updates for JSON resources
License: MIT License
This file contains a simple synchronization method for JSON objects based on the file synchronization algorithm presented by Norman Ramsey and Elod Csirmaz in An Algebraic Approach to File Synchronization <http://www.eecs.harvard.edu/~nr/pubs/sync-abstract.html> Abstract: "We present a sound and complete proof system for reasoning about operations on filesystems. The proof system enables us to specify a file-synchronization algorithm that can be combined with several different conflict-resolution policies. By contrast, previous work builds the conflict-resolution policy into the specification, or worse, does not specify the behavior formally. We present several alternatives for conflict resolution, and we address the knotty question of timestamps." We map this algorithm to JSON records by giving object and array values the same treatment that Ramsey and Csirmaz give file system directories. This algorithm requires that we keep a snapshot around, such as the last response from a server. var snapshotJSON = { "x": 42, "a": 1, "b": { "c": 2, "d": { "e": 3, "f": 4 }, "g": 5 }, "h": 6.6, "i": [7, 8, 9], "j": 10, "k": { "m": 11 }, "n": 66, } After local updates have occured, the JSON object will have changed. Our algorithm determines a sequence of updates to the snapshot that result in an object approximating the current state. We can perform this detection without logging each change by ignoring sequences deemed to be insignificant. For example, the field "x" with value 42 could be deleted and subsequently added with a value of 43. Our algorithm will not track these changes. The key is present in both JSON objects, so the change will be represented as an edit. var currentJSON = { "x": 43, /* edited */ "a": 1, "new": 11, /* created */ "b": { "c": 2, "new2": 22, /* created */ "d": { "e": 3, /*"f": 4*/ /* removed */ }, "g": 55, /* edited */ }, /* "h": 6.6, */ /* removed */ "i": [7, 8, 9, 99], /* added array element */ "j": 10, "k": 42, /* replaced object with primitive */ "n": { "new3": 77 }, /* replaced primitive with object */ } todo: Synchronizer object at the bottom of the file needs to be completed. Arrays need an identity function for their elements, so the algorithm can be more intuitive when elements move around. I bet you can design a better wire format!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.