ipfs-shipyard / js-ipfs-versidag

Concurrent version history based on a Merkle-DAG on top of IPFS and IPLD
MIT License
4 stars 1 forks source link

anyone can give a real world demo ? #2

Open bluelovers opened 4 years ago

bluelovers commented 4 years ago

anyone can give a real world demo ?

and what value of meta should be ?

import IPFS from 'ipfs';
import createIpfsVersidag from '../';

IPFS.create().then(async (ipfs) => {
    const myVersidag = createIpfsVersidag({
        ipfs,
        tieBreaker: (node1, node2) => node1.meta - node2.meta,
    });

    const myVersidagA = await myVersidag.add('Hi', 1);
    const myVersidagB = await myVersidagA.add('Hello', 2);
    const myVersidagC = await myVersidagA.add('Hi World', 3);
    const myVersidagD = await myVersidagB.merge(myVersidagC.headCids, 'Hello World');

    const versions = await myVersidagD.resolve();
    // [
    //   { version: 'Hello World' },
    //   { version: 'Hi World', meta: 3 }
    //   { version: 'Hello', meta: 2 }
    //   { version: 'Hi', meta: 1 }
    // ]
});
momack2 commented 4 years ago

This tool is showing how you can construct a DAG (directed acyclic graph) using append only logs. Some useful tools to dive deeper on this:

bluelovers commented 4 years ago

can't display data in https://explore.ipld.io/

https://github.com/bluelovers/ws-ipfs-versidag/blob/master/packages/ipfs-versidag/test/demo.ts