Wrap DOM node before using as argument to component constructor

23 views
Skip to first unread message

julian

unread,
Oct 6, 2013, 1:43:37 PM10/6/13
to cuj...@googlegroups.com
hi.

does wire have a better way of doing what i'm attempting below?
what i would prefer is to not have to pass a reference to zepto to FooView.  
rather, i'd like to (somehow) in the spec, send the node through a "pipeline" that consists of just the zepto function, and use the result of the pipeline as the sole argument to FooView's constructor.  possible?  is there a best practice with wire? 
thanks in advance!

julian

// spec

define
({
   zepto: {
       module: 'Zepto'
   },
  fooView: {
      create: {
          module: 'FooView',
          args: [{$ref: 'zepto'}, {$ref: 'first!.foo-view'}]      
       }
   
}      
});

// FooView.js

define
([], function () {
  function FooView () {}
  FooView.prototype = {
      doSomethingThenShow: function ($, node) {
           var $node;
           // ...
           // do something
           // ...
           $node = $(node);
           $node.show();
      }
  }
  return FooView;
});


Charilaos Skiadas

unread,
Oct 6, 2013, 2:05:49 PM10/6/13
to cuj...@googlegroups.com
Maybe you can do something with composed functions?

https://github.com/cujojs/wire/blob/master/docs/functions.md#composing-functions
> --
> You received this message because you are subscribed to the Google Groups "cujojs" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to cujojs+un...@googlegroups.com.
> To post to this group, send email to cuj...@googlegroups.com.
> Visit this group at http://groups.google.com/group/cujojs.
> To view this discussion on the web visit https://groups.google.com/d/msgid/cujojs/8cc8fa08-3601-476d-a666-146d9937fe1d%40googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Haris Skiadas

julian

unread,
Oct 6, 2013, 2:55:40 PM10/6/13
to
yes, i think composed functions might be part of the solution.  i tried composition but couldn't figure out how to pass the result of "first!.foo-view" into Zepto.  i couldn't find an example of this sort of thing being done.  also looked into transforms.

unscriptable

unread,
Oct 7, 2013, 4:25:37 PM10/7/13
to cuj...@googlegroups.com
Hey julian,

Something like this would work, but is probably not intuitive.  It's using zepto as a constructor.

define({
   zepto
: {
       
module: 'Zepto'
   
},

   $fooViewNode
: {
       
// construct a zepto-wrapped node:
       create
: { module: 'Zepto', args: {$ref: 'first!.foo-view'} }

   
},
   fooView
: {
       create
: {
           
module: 'FooView',

           args
: [{$ref: '$fooViewNode'}]      
       
}
   
}      
});

-- John

On Sunday, October 6, 2013 2:53:46 PM UTC-4, julian wrote:
yes, i think composed functions might be part of the solution.  i tried composition but couldn't figure out how to pass the result of "first!.foo-view" into Zepto.  i couldn't find an example of this sort of thing being done.  also looked into transforms.

On Sunday, October 6, 2013 11:05:49 AM UTC-7, Charilaos Skiadas wrote:

Brian Cavalier

unread,
Oct 7, 2013, 4:58:42 PM10/7/13
to cuj...@googlegroups.com
Yeah, unscriptable's example is really the only way to do it without writing a wire plugin.  If you to go the plugin route, let me know.  It would be pretty simple.

julian

unread,
Oct 7, 2013, 6:17:56 PM10/7/13
to cuj...@googlegroups.com
@john - thanks for the solution you proposed.  i need to wrap many nodes though, so i'd like not to incur the overhead of creating an entry in the spec for each one.  
@brian - i think i may have to go the plugin route in order to make wrapping as transparent as possible.  i just read through https://github.com/cujojs/wire/blob/master/docs/plugins.md#plugin-api.  are there any other resources that might help? 
could i pass the result from using the dom plugin (to locate an element) to the zepto plugin? 
Reply all
Reply to author
Forward
0 new messages