GithubHelp home page GithubHelp logo

object-mutation-observer's Introduction

Quickstart

    const linked = {
        link: 'a',
        obj: {}
    }
    const obj = {
        "1": 2,
        a: "b",
        linked1: linked,
        linked2: linked,
        nested: {
            c: "c"
        },
        recursive: { obj: this },
        array: [2, 4, 3, 5, 1, 6],
        sorted: [1, 2, 3, 4, 5, 6],
        [Symbol()]: {
            symbol: {
                bool: true
            },
            linked
        }
    };
    obj.recursive = { obj };
    
    const observer = new ObjectMutationObserver({ emit: 'async', resolveChangeAncestors: 'early' }));
    const proxy = observer.watch(obj);
    observer.watch(proxy, v=> console.log(v));
    proxy.f = 'b';
    // console:
    // {
    //     event: 'change', // Type of event
    //     type: 'set', // Subtype of event
    //     target: proxy, // The object that had changes on it
    //     key: 'f', // The property that was modfied
    //     previous: undefined, // The previous value
    //     current: 'b', // The new value
    //     reference: proxy, // The object the listener was attached to
    //     paths: ["/f", "/recursive/obj/f"] // The paths relative to the listened to object
    // }

Goals

  • Must not leak implementation code into the original objects
  • Must allow multiple listeners
  • Must allow attaching listeners at any time and at any level by passing the object to listen to
  • Must not prevent garbage collection of objects
  • Should capture all mutations
  • Should be indistinguishable from original object. No Code Changes required ie obj.a = '1' must not need to be changed to set(obj.a, '1') * Exception for optional wrapping methods to tag execution started/ended ie Array.sort started/ended
  • Should work with all objects and keys including functions and symbols
  • Should work with recursive objects and objects with multiple ancestors
  • Should resolve all paths relative to change

object-mutation-observer's People

Contributors

0x6563 avatar github-actions[bot] avatar

Stargazers

Sean P. Myrick V19.1.7.2 avatar  avatar

Watchers

 avatar Sean P. Myrick V19.1.7.2 avatar

Forkers

seanpm2001

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.