Giter Club home page Giter Club logo

delegable-proxy's Introduction

delegable-proxy

Multi-level deepened proxy, works sync.

Build Status npm version Maintainability Test Coverage

Main purpose

For convenience sake we want to work with common lists and objects but keep track of every change to commit them to the underlying storage. Object.observe() and Array.observe() are pretty much the exact thing we want, but both work async via polling.

The proxy returns the type of mutation (add, del, mod) and which position (in root object) is affected.

Example

import DelegableProxy from 'delegable-proxy'

const example = [{'message': 'hello world'}]
const data = DelegableProxy.wire(example, (action, pos) => {
  console.log(action, pos)
})
data.push({'message': 'hi there!'})
data.push({'message': 'knock knock!'})

RunKit

https://runkit.com/586ca4b68acd620014d54362/586ca4b68acd620014d54363

Known issues

  • The way Array.splice works, leads to a lot of mutations on inner arrays. Better use the slow delete foo[42].bar.stuff[0].
  • We do not recommend to use this library in a production environment. This was just a fun project, some kind of PoC for us. We still use it in a dev environment which is only used internally.

Usage

# add the library
yarn add delegable-proxy

# build the library
yarn build

# run the tests
yarn test

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.