GithubHelp home page GithubHelp logo

crazy4groovy / datasette Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thenativeweb/datasette

0.0 2.0 0.0 340 KB

datasette is a key-value container for arbitrary data.

JavaScript 100.00%

datasette's Introduction

datasette

datasette is a key-value container for arbitrary data.

Installation

$ npm install datasette

Quick start

The first thing you need to do is to integrate datasette into your application. For that add a reference to the datasette module.

const datasette = require('datasette');

Next, you can create a new data container. For that you need to call the create function.

const cc = datasette.create();

Setting data

To set data, call the data container's set function and specify the key and the value you want to store.

cc.set('foo', { bar: 'baz' });

To set multiple keys and values at once, you can also hand over an object that contains the data.

cc.set({
  foo: 23,
  bar: 42
});

This is equivalent to calling set two times with separate key value pairs.

Getting data

To get data, call the data container's get function and specify the key you would like to retrieve.

const value = cc.get('foo');

Note: Each time you call get, you will get a cloned result to avoid conflicting state changes on a shared reference.

Dealing with events

Every time a value is created, changed or deleted, the data container will emit a changed event. Use the on or once functions to subscribe to this event.

cc.on('changed', (key, value) => {
  // ...
});

If you are only interested in changed events for a specific key, subscribe to the changed::* event instead.

cc.on('changed::foo', value => {
  // ...
});

Note: If you set the same key value pair two times, the data container will not emit an event on the second set call.

To unsubscribe from event notifications, use the off function.

Suppressing events

If you don't want a set call to result in an emitted event, you can specify an options object and set its silent property to true.

cc.set('foo', 'bar', { silent: true });

Running the build

To build this module use roboter.

$ bot

License

The MIT License (MIT) Copyright (c) 2013-2017 the native web.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

datasette's People

Contributors

crazy4groovy avatar goloroden avatar

Watchers

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