1

Inside a component, I am happily using the syntax below to load additional components, if and when needed:

<!-- Import example component -->
<link rel='ractive' href='internal-example.html' name='InternalExample'>

My question is, how can I access this example component instance created by Ractive Load inside another component?

Important:

I can define where the main components will be stored and I can see ...anotherMainComponent.components.InternalExample but it doesn't appear to be a instance, since I can't use get or set

Instead it appears to be a "component definition" to be reused (which is fine to me).

Paulo Coghi
  • 13,724
  • 14
  • 68
  • 90

1 Answers1

1

You can use the findComponent method:

// assuming `ractive` is the top-level instance
// (i.e. `ractive = new MyComponent(...)`)
var internalExample = ractive.findComponent( 'InternalExample' );

ractive.findAllComponents is a related method - docs here and here.

Rich Harris
  • 28,091
  • 3
  • 84
  • 99
  • I am glad to see how Ractive is evolving. I am developing plugins to extend Ractive Load features to use it in production grade and large scale softwares (as the one my company is creating). Once my company permits me, I plan to create repositories and return our improvements to Ractive – Paulo Coghi Apr 28 '15 at 18:59
  • looking forward to it :) – Rich Harris Apr 28 '15 at 21:07