Giter Site home page Giter Site logo

pocktails's Introduction

Pocktails

Real-time JSON Models

Define Models on the Server & manipulate them on the Client.

The Models auto-sync with all other connected clients & changes are persisted on server.

This is just a silly prototype. Don't use this in production.

Usage Example

The following example illustrates a real-time, collaborative & persistent Todo List with pocktails:

Server

// Pass `io` as an initialized socket.io instance.
const pocktails = new Pocktails(io)

pocktails.defineModel('todos', {
  items: [
    // Init a good-first todo:
    { id: '64bbd83a-b1ed-4254-9aee-1e4e6d85fdb7', content: 'Get Milk' }
  ]
})

// Revive models from previous disk-persisted operations:
pocktails.reviveAll()

Client

<script src="node_modules/pocktails/sdk/pathval.js"></script>
<script src="node_modules/pocktails/sdk/sdk.js"></script>
<script>
  const pocktails = new Pocktails()

  pocktails.addEventListener('handshake', () => {
    // logs the 'todos' model defined on server:
    console.log(pocktails.models.todos)
  })

  // Edit existing todo:
  pocktails.set('todos', 'items.1.content', 'Get Beer')

  // Add a new todo:
  pocktails.push('todos', 'items', {
    id: '84car114-xxrh-8873-9vt2-3a4x4d99rtx1',
    content: 'Get Eggs'
  })

  // Optionally, remove the 1st (pre-existing) todo:
  pocktails.splice('todos', 'items', 0, 1)
</script>
  • Changes auto-sync across all connected clients.
  • Changes are persisted on-disk. Restarting the server revives the Todo List as it was before the server was stopped.

Run Examples

Run above example (and others):

$ npm run examples
# and visit http://localhost:3000/examples

Authors

@nicholaswmin

pocktails's People

Contributors

nicholaswmin avatar

Stargazers

 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.