From 83cc6961a3a65f39f9bf16e26bd77554023b521b Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Thu, 23 May 2013 10:10:50 +0200 Subject: [PATCH] Signal events when adding types to avals and properties to objects Issue #156 --- lib/infer.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/infer.js b/lib/infer.js index 6df8c8bd..414b9096 100644 --- a/lib/infer.js +++ b/lib/infer.js @@ -15,11 +15,11 @@ (function(mod) { if (typeof exports == "object" && typeof module == "object") // CommonJS return mod(exports, require("acorn/acorn"), require("acorn/acorn_loose"), require("acorn/util/walk"), - require("./def")); + require("./def"), require("./signal")); if (typeof define == "function" && define.amd) // AMD - return define(["exports", "acorn/acorn", "acorn/acorn_loose", "acorn/util/walk", "./def"], mod); - mod(self.tern || (self.tern = {}), acorn, acorn, acorn.walk, tern.def); // Plain browser env -})(function(exports, acorn, acorn_loose, walk, def) { + return define(["exports", "acorn/acorn", "acorn/acorn_loose", "acorn/util/walk", "./def", "./signal"], mod); + mod(self.tern || (self.tern = {}), acorn, acorn, acorn.walk, tern.def, tern.signal); // Plain browser env +})(function(exports, acorn, acorn_loose, walk, def, signal) { "use strict"; // Delayed initialization because of cyclic dependencies. @@ -33,7 +33,7 @@ // as prototype for AVals, Types, and Constraints because it // implements 'empty' versions of all the methods that the code // expects. - var ANull = exports.ANull = { + var ANull = exports.ANull = signal.mixin({ addType: function() {}, propagate: function() {}, getProp: function() { return ANull; }, @@ -46,7 +46,7 @@ propagatesTo: function() {}, typeHint: function() {}, propHint: function() {} - }; + }); function extend(proto, props) { var obj = Object.create(proto); @@ -74,6 +74,7 @@ return; } + this.signal("addType", type); this.types.push(type); var forward = this.forward; if (forward) withWorklist(function(add) { @@ -447,8 +448,11 @@ return this.maybeProps[prop] = new AVal; }, broadcastProp: function(prop, val, local) { - // If this is a scope, it shouldn't be registered - if (local && !(this instanceof Scope)) registerProp(prop, this); + if (local) { + this.signal("addProp", prop, val); + // If this is a scope, it shouldn't be registered + if (!(this instanceof Scope)) registerProp(prop, this); + } if (this.onNewProp) for (var i = 0; i < this.onNewProp.length; ++i) { var h = this.onNewProp[i];