Giter Club home page Giter Club logo

meta-objects's Introduction

meta-objects

A library of utilities, patterns, and experiments building on top of the new Harmony Proxy API, part of the ES6.

Built for http://nodejs.org currently, running with the flags '--harmony_proxies --harmony weakmaps'. Most of this should work in Firefox as well but currently is untested.

What are Proxies? This isn't about HTTP

ES6 is the in-progress draft specification for the next version of ECMAScript. A number of new features are being introduced, chief among them being the powerful new Proxy object. A Proxy is an empty shell object, containing no properties of its own. Instead, a handler is defined which implements a set of predefined traps.

Externally the Proxy looks like a regular object, but in fact it is an amorphous thing can look like any arbitrary structure and can change from one access to the next, one operation to the next.

Fundamental Traps

JS will throw errors if it tries to use one of these and can't.

    getOwnPropertyDescriptor: [name]             =>  descriptor
    getPropertyDescriptor:    [name]             =>  descriptor
    getOwnPropertyNames:      []                 =>  [ string ]
    getPropertyNames:         []                 =>  [ string ]
    defineProperty:           [name, descriptor] =>  any
    delete:                   [name]             =>  boolean
    fix:                      []                 =>  { static version }

Derived Traps

JS will use default fallbacks for these which rely on the fundamental traps.

    has:       [name]                => boolean    name in proxy
    hasOwn:    [name]                => boolean    ({}).hasOwnProperty.call(proxy, name)
    get:       [receiver, name]      => any        receiver.name
    set:       [receiver, name, val] => boolean    receiver.name = val
    enumerate: []                    => [string]   for (name in proxy)
    keys:      []                    => [string]   Object.keys(proxy)

Managable Patterns for making Proxies

That's a lot of properties to implement. Proxies are something that calls for tools and libraries to enable their use. This project's goal is to create simpler tools for using Proxies and to experiment with what's possible using them.

API

This will likely change over time.

Handlers

Handlers are objects which are used in Proxy.create[Function] and don't do anything on their own. Many of these handlers are proxies themselves, known as meta handlers. Due to how the Proxy API works, a meta handler will have all access funneled to one single get trap.

  • Forwarding(target) Sends actions to real object, most other things build on this
  • Dispatching(dispatcher, defaultHandler, trapFilter) Meta handler which funnels all access through one entry point. Accepts a default handler so action is optional.
  • Membrane(dispatcher, defaultHandler, wrapper) Meta handler designed to wrap any non-primitive objects that come under its purview, and unwrap objects as they leave.

Proxies

Proxy factories which handle most of the work for you and return created proxies.

  • Mirror(target, dispatcher) Mirror implements the Forwarding handler to create a proxy that will handle everything itself, but gives you first dibs to make your own changes.
  • Membrane(dispatcher, target) Basic implementation of membrane using membrane proxy. A membrane proxy will wrap all properties and return values in membrane proxies. All wrapped objects from a membrane will report to the same dispatcher.
  • Tracer(target) Hacky experimentation in making a all-op tracer that doesn't break everything.

Utilities

trapUtils

  • nameArgs(trap, args) Tags raw arguments and trap name and converts to named list.
  • filterBy(by, value) Filter trap list by a property name and match. Useful for retrieving trap filter lists.
  • groupBy(by) Create a reorganized trap list keyed on a property.

proxyUtils

  • proxyFor(target, handler) Single interface for creating object and function proxies. Only does the bare minimum, this requires a handler.

meta-objects's People

Stargazers

 avatar

Watchers

 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.