Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Re : Best practice for passing references to a can.Component instance

$
0
0
The beautiful thing about using a data, event driven architecture is that you generally don't ever actually need to interact with the components that consume that data, only the data itself. You have a couple of options here, but the goal is to make the scope can.Map within an accessible scope. This can be done by passing can.Map instances as attributes, or during scope setup.

Example:
  1. var foo = can.Map.extend({
  2.       a: 5,
  3.       b: 10,
  4.       sum: can.compute(function() {
  5.             return this.attr('a') + this.attr('b');
  6.       })
  7. });
  8. var bar = new foo();
  9. can.Component.extend({
  10.       tag: 'test',
  11.       scope: function(attr, parentScope, element) {
  12.             attr.bar = bar;
  13.             return attr;
  14.       })
  15. });
  16. bar.attr('a', 20);

Anyway, you get the idea.


Viewing all articles
Browse latest Browse all 3491

Trending Articles