Skip to content
Browse files

clean up examples and readme

  • Loading branch information...
1 parent a2c318a commit 40a5bdfe6ceefded4d1437daecb2ddb8d6019f05 @Benvie committed May 24, 2012
Showing with 12 additions and 122 deletions.
  1. +7 −3 README.md
  2. +0 −107 examples/flattener.js
  3. +5 −12 examples/object-emitter.js
View
10 README.md
@@ -7,14 +7,18 @@ Tools for making meta-objects. These are broken down into two categories. One ca
* __callable__ - Takes an object and returns a callable and constructable version of it, which use the __$$call__ and __$$construct__ properties on the object.
* __multiherit__ - Creates a meta class from multiple constructors that combines all of them into one. Prototypal inheritance with multiple prototypes and multiple constructors.
* __tracer__ - Creates a clone object from the provided object that emits __all__ things that happen to it. It's like databinding on crack.
-* __interceptor__ - Turns normal getters/setters on prototypes, get/set/length into indexed properties like buffers, and get/set/has/list into named properties like DOM css objects.
+* __doppelgangar__ - An object with mutatable persona. That is, it has a single JavaScript identity (used in `===` for example) but allows you to arbitrarily reassign what object it mirrors, at any time.
+
+### Lower level interfaces
+* __interceptor__ - Turns normal getters/setters on prototypes, get/set/length into indexed properties like buffers, and get/set/has/list into named properties like DOM css objects.
* __proxy__ - Simplifies creation of ES6 proxies by handling everything you don't want to and providing ways to forward and subtly modify a target object.
* __membrane__ - Accepts the same parameters that would be provided to __proxy__ but returns an object that will automatically wrap and unwrap all sub-objects gotten from property access, function calling, constructors, etc.
-* __doppelgangar__ - An object with mutatable persona. That is, it has a single JavaScript identity (used in `===` for example) but allows you to arbitrarily reassign what object it mirrors, at any time.
-* __WrapMap__ - Mostly internal use tool for wrapping/unwrapping objects, used by membranes.
+### Semi-standalone classes
+
+* __WrapMap__ - Mostly internal use tool for wrapping/unwrapping objects, used by membranes. It builds upon WeakMaps with the goal of providing object identity management for cases where objects are being wrapped by some other object (usually but not always a proxy) by preventing redundent, rewrapping, unwrapping if wrapped or return, and checking for primitive values to prevent accident type errors.
* __Emitter__ - A cross-between Node's emitters and the DOM event system. Used by tracer.
View
107 examples/flattener.js
@@ -1,107 +0,0 @@
-var membrane = require('../').membrane;
-
-function flattener(target){
- return membrane(flattenerHandler).wrap(target);
-}
-
-var flattenerHandler = {
- names: function(fwd, target){
- return props(target)
- },
- keys: function(fwd, target){
- fwd.trap = 'enumerate';
- return fwd().filter(function(s){
- return !(s in Object.prototype)
- });
- },
- owns: function(fwd, target, name){
- fwd.trap = 'has';
- return fwd();
- },
- describe: function(fwd, target, name){
- return Object.getPropertyDescriptor(target, name);
- }
-};
-
-function showAll(target){
- return membrane(showAllHandler).wrap(target);
-}
-
-
-function getList(fwd, target){
- var list = props(target).filter(function(s){
- return !Object.prototype.hasOwnProperty(s);
- });
- if (typeof target === 'function') {
- return list.filter(function(s){
- return !Function.prototype.hasOwnProperty(s);
- });
- } else {
- return list;
- }
-}
-
-var showAllHandler = {
- names: getList,
- keys: getList,
- enumerate: getList,
- owns: function(fwd, target, name){
- fwd.trap = 'has';
- return fwd();
- },
- describe: function(fwd, target, name){
- var v = Object.getPropertyDescriptor(target, name);
- if (v) return new Desc(v, true);
- },
-};
-
-
-Object.defineProperties(Object, {
- getPropertyDescriptor: new Desc(function getPropertyDescriptor(o,n){
- while (Object(o) === o) {
- var desc = Object.getOwnPropertyDescriptor(o,n);
- if (desc) return desc;
- o = Object.getPrototypeOf(o);
- }
- }),
- getPropertyNames: new Desc(function getPropertyNames(o){
- var names = [];
- while (Object(o) === o) {
- names = names.concat(Object.getOwnPropertyNames(o));
- o = Object.getPrototypeOf(o);
- }
- return unique(names);
- })
-});
-
-function Desc(v,e){
- if (e) this.enumerable = true;
- if (v && v.get || v.set) {
- this.get = v.get;
- this.set = v.set;
- } else if ('value' in v) {
- this.value = v.value;
- this.writable = true;
- } else {
- this.value = v;
- this.writable = true;
- }
-}
-Desc.prototype = { configurable: true }
-
-function unique(a){
- return Object.keys(a.reduce(function(r,s){ r[s]=1; return r }, {}));
-}
-
-var desc = Object.getPropertyDescriptor;
-var props = Object.getPropertyNames;
-
-
-var x = showAll(global);
-var z = new x.process.EventEmitter;
-var o = {};
-z.y = o;
-z.y.a = {}
-console.log(z.y === o);
-console.log(z);
-console.log(x);
View
17 examples/object-emitter.js
@@ -1,28 +1,21 @@
var tracer = require('../').tracer;
var emitter = tracer(function Test(){ this.name = 'bob' }, 'Test');
-emitter.on('*', function(event){
- var args = [event.type, event.path.join('.')];
- if (event.property) args.push(event.property);
- console.log.apply(console, args);
-});
+emitter.on('*', console.log.bind(console));
var Test = emitter.Test;
var bob = new Test;
console.log(bob);
bob.stuff = { x: ['a',',b','c'] }
-console.log(bob.stuff.x[0]);
+//console.log(bob.stuff.x[0]);
if (typeof document !== 'undefined') {
// the wrapper can be used with DOM elements provided you always work through the wrappers
- var emitter = tracer(document, 'document');
- emitter.on('*', function(event){
- var args = [event.type, event.path.join('.')];
- if (event.property) args.push(event.property);
- console.log.apply(console, args);
- });
+ var emitter = tracer(document, 'document');
+ emitter.on('*', console.log.bind(console));
+
var doc = emitter.document;
var div = doc.createElement('div');
doc.body.appendChild(div);

0 comments on commit 40a5bdf

Please sign in to comment.
Something went wrong with that request. Please try again.