Skip to content

Commit

Permalink
Signal events when adding types to avals and properties to objects
Browse files Browse the repository at this point in the history
Issue #156
  • Loading branch information
marijnh committed May 23, 2013
1 parent 5a8ff69 commit 83cc696
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lib/infer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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; },
Expand All @@ -46,7 +46,7 @@
propagatesTo: function() {},
typeHint: function() {},
propHint: function() {}
};
});

function extend(proto, props) {
var obj = Object.create(proto);
Expand Down Expand Up @@ -74,6 +74,7 @@
return;
}

this.signal("addType", type);
this.types.push(type);
var forward = this.forward;
if (forward) withWorklist(function(add) {
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit 83cc696

Please sign in to comment.