Code Monkey home page Code Monkey logo

z's Introduction

| a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y | z |

Z is for Zed

@cursorsdottsx/z

What? What's Zed? Ctrl Zed of course. Go Ctrl + Z your objects by employing a Version Control System for your JavaScript objects.

Zed is the most advanced object VCS because there are no other fucking objects VCS's on NPM. That's how useless it is!

Nevertheless this package has all you need to dictate your object's state through time.

Easy to install

Zed can be installed with the typical NPM or Yarn:

npm install @cursorsdottsx/z
yarn add @cursorsdottsx/z

Easy to use

const Zed = require("@cursorsdottsx/z").default;
import Zed from "@cursorsdottsx/z";

Yay you actually installed this! Time to use it! Zed is available as a global class:

const object = { foo: "bar" }; // hm a regular object is boring af

const zed = new Zed(object); // ah thats better

console.log(zed.latest.foo); // => "bar"

zed.latest.foo = "baz";

zed.commit("Change to baz");

console.log(zed.latest.foo); // => "baz"

zed.revert();

console.log(zed.latest.foo); // => "bar"

Zed also supports branching and reverting to a snapshot by id!

If you don't want the extra overhead of those things, you can alwayse use Zed.Simple:

const object = { foo: "bar" }; // hm a regular object is boring af

const zed = new Zed.Simple(object); // ah thats better

console.log(zed.latest.foo); // => "bar"

zed.latest.foo = "baz";

zed.commit("Change to baz");

console.log(zed.latest.foo); // => "baz"

zed.revert();

console.log(zed.latest.foo); // => "bar"

It acts the same as Zed without multiple histories, but there are some changes to revert as you will see in the docs.

Don't want to use zed.latest all the time just to change the object? Well you can extend Zed or Zed.Simple!

That's right, Zed will behave differently when extended!

class VersionedObject extends Zed {
    constructor() {
        super(zedOptions);
    }
}

const object = new VersionedObject();

object.property = "foo";

object.commit("I like foos");

object.property = "bar";

object.commit("bars are better");

object.revert();

object.property; // => "foo"

This is also inherently more type safe and goes well with TypeScript!

Some boring ass documentation

new Zed(object, options)

  • object – The object to track.
  • options – Options for Zed.
    • master – Name of the master branch.
    • message – Repo initialization message.

Creates a new Zed instance.

Zed.prototype.latest

The current snapshot (badly named I know).

Zed.prototype.commit(message)

  • message – Optional commit message.

Commits the current Zed object to the timeline.

Zed.prototype.revert(id)

  • id – Optional snapshot id to revert to.

Oh shit you messed up! Reverts the timeline to the last snapshot (or the snapshot with the id provided).

Zed.prototype.branch(name, options)

  • name – Name of the new branch.
  • options – Options for the new branch.
    • m – Overwrite the branch that already exists.
    • b – Checkout the new branch.

Creates a new branch in the timeline.

Zed.prototype.checkout(name)

  • name – Name of the branch.

Switches to another branch.


new Zed.Simple(object, options)

  • object – The object to track.
  • options – Options for Zed.
    • master – Name of the master branch.
    • message – Repo initialization message.

Creates a new Zed instance.

Zed.Simple.prototype.latest

The current snapshot (badly named I know).

Zed.Simple.prototype.commit(message)

  • message – Optional commit message.

Commits the current Zed object to the timeline.

Zed.Simple.prototype.revert(times, force)

  • times – How many times do we wanna roll' back?
  • force – Force rollback to earliest change if needed.

Oh shit you messed up! Reverts the timeline to the last snapshot.

npm abc's homepage

z's People

Contributors

mchccn avatar

Stargazers

 avatar

Watchers

 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.