Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arguments / constructor #37

Closed
offthegrass opened this issue Apr 26, 2015 · 6 comments
Closed

Arguments / constructor #37

offthegrass opened this issue Apr 26, 2015 · 6 comments
Labels

Comments

@offthegrass
Copy link
Contributor

with this example from the demo:

mixins: -> [
  ....
  new StorageMixin Values, 'value', => @data().id
]
class StorageMixin extends BlazeComponent
  constructor: (@collection, @fieldName, @selector) ->

I would like to change

new StorageMixin Values

to something like

new StorageMixin @data().collection

so I can do

{{> MyComponent collection='Values'}}

I do want the component to re-render if the collection changes, so do I use args in the MyComponent constructor? what is the correct way to do this?

@offthegrass offthegrass changed the title Passing Arguments / constructor Apr 26, 2015
@offthegrass
Copy link
Contributor Author

{{#MyComponent args collection='Values'}}
constructor: (args) ->
        @collection = eval(args.hash.collection)

this works.

@mitar
Copy link
Member

mitar commented May 1, 2015

Why eval there? This looks really wrong, strange, unnecessary?

@rclai
Copy link

rclai commented May 1, 2015

Use window[args.hash.collection] instead dude.

@mitar
Copy link
Member

mitar commented May 1, 2015

Oh, you want to access a global symbol? Oh. :-)

I prefer then putting in the top level of a file:

globals = @

And then you can use globals[args.hash.collection].

@mitar
Copy link
Member

mitar commented May 1, 2015

You could also use: https://github.com/dburles/mongo-collection-instances

@offthegrass
Copy link
Contributor Author

thanks for the tips. that package looks useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants