cujojs / wire

A light, fast, flexible Javascript IOC container

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dynamically wire()'ed scopes are not made resolvable

AnAppAMonth opened this issue · comments

Objects (components and scopes) are made resolvable by calling Scope.prototype._makeResolvable(). This method is called in the following places:

  1. Scope.prototype._createScopeItem()
  2. scope.componentFactory.initInstance()
  3. pluginApi.addComponent()
  4. pluginApi.addInstance()

The first call causes _makeResolvable() to be called for each statically created component and scope (those created by wiring a spec); and the second call causes it to be called for each component, either statically or dynamically created. By "dynamically created" I mean it's created by calling wire() in a plugin method.

So for statically created components, _makeResolvable() is called twice (both 1 and 2 are called); for statically created scopes, 1 is called; for dynamically created components, 2 is called; and for dynamically created scopes, none is called, so the scope isn't resolvable.

For example, if I have the following statement in a plugin method:
wire({example:{literal:'example'}}, 'myscope');
This scope is created but not made resolvable.

Additionally, pluginApi.addComponent() calls scope.componentFactory.processComponent(), which in turn calls scope.componentFactory.initInstance(). So in this case _makeResolvable is also called twice (2 and 3).

Additionally, components that are dynamically wired and are plain values or reference another component, for example, by calling wire(3, 'newcomp') or wire({$ref: 'another'}, 'newcomp') in a plugin, are not made resolvable.

Thanks for the detailed report, @halfninety. I'll look into this today and report back with more info.