Giter Club home page Giter Club logo

basilisk's Introduction

Basilisk is a value library for Javascript. It allows you to create immutable data in a familiar way, and to derive new versions from that data.

Full documentation is available on readthedocs

var Person = basilisk.makeStruct(['name', 'age']),
    example = new Person({ name: 'Joe', age: 32 }),
    older = example.with_('age', example.age + 2);

Making code which updates deeply nested structures simple and clear is library's main aim.

// we make a quick alias, to reduce clutter in the code.
var b$ = basilisk.query,

    Person = basilisk.makeStruct(['name', 'age', 'addresses']),
    Address = basilisk.makeStruct(['city', 'country']),

    example = new Person({
        name: 'Joe',
        age: 32, 

        addresses = basilisk.Vector.from([
            new Address({ city: 'London', country: 'United Kingdom' }),
            new Address({ city: 'Cape Town', country: 'South Africa' })
        ])
    }),
    example2, example3;

// first we create a new object, with a US address added.

example2 = b$.swap(example, ['addresses'], function (current) {
    return current.push(new Address({ city: 'Boston', country: 'USA' }));
});

// and if we have to replace a part of that new address.

example3 = b$.replace(example2, ['addresses', b$.at(2), 'city'], 'New York');

What's included

  • Structs with new-version helpers.
  • Persistent data structures (Vector, HashMap, StringMap) with a Javascript flavor.
  • A Query/Update utility to make deep changes in a data store easy to understand.

Examples

There is a simple example application called Listicle.

Documentation

Read all about it on readthedocs.

Installing Basilisk

Note that you need to have an ES5 Shim in place to use Basilisk on older browsers.

  • Bower: bower install basilisk
  • Node: npm install basilisk

Contributions

Contributions are very welcome! Basilisk is MIT Licensed, so you can use Basilisk in your applications without worry.

Inspired by

Basilisk is heavily inspired by Rich Hickey's talks.

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.