component / reactive

Tiny reactive template engine
382 stars 48 forks source link

Global functions #153

Closed ooflorent closed 10 years ago

ooflorent commented 10 years ago

I'm trying to call a function like:

<div>{ _('%d / %d', var1, var2) }</div>

I tried several dirty hacks such as:

Is there any way to define a function available in all views?


Update: I'm always getting the following error:

// Uncaught TypeError: object is not a function VM2169:3
(function(reactive
/**/) {
return ['_']('%d / %d', reactive.get('current'), reactive.get('total')) 
})

But defining obj._ does not throw...

defunctzombie commented 10 years ago

There is no way to do this. Views are self contained and this is by design.

ooflorent commented 10 years ago

But defining _ into the model, the view or the adapter should work right? Because it seems not.

defunctzombie commented 10 years ago

Possibly the detection for what is a valid identifier is broken. That would be a separate issue from global functions. And yes, I think it should work so is likely a bug.

ooflorent commented 10 years ago

Should I open a new issue?

defunctzombie commented 10 years ago

Yep :) if you can make a failing example that would be best. On Aug 12, 2014 8:48 AM, "Florent Cailhol" notifications@github.com wrote:

Should I open a new issue?

— Reply to this email directly or view it on GitHub https://github.com/component/reactive/issues/153#issuecomment-51933586.