Skip to content

get rid of params wrapper - directly access params via instance vars #51

Closed

Description

@catmando

instead of params.foo we should just say @foo

why?

  1. its 25 times faster
  2. its much more consistent - all component state is in instance vars regardless of how it is set
  3. the params wrapper method is not private (but it should be)
  4. less typing
  5. it just feels more natural to ruby.

Don't worry - you can get the legacy behavior by adding param_accessor_style :legacy to any component (including the base component.) You can also say param_accessor_style :both to get both behaviors. If you need to switch back to the now standard behavior say param_accessor_style :hyperstack

So for example you can say param_accessor_style :legacy in your base component, and then as you update components to new style in that component say param_accessor_style :hyperstack.

The param declaration macro is unchanged, but has a new alias option.

param :foo, alias: :internal_name

If you like to distinguish between params and other instance variables you can use this feature like this:

param :foo, alias: :param_foo for example

see #52 for a complete example

Activity

  1. barriehadfield commented on Nov 14, 2018

    @barriehadfield
    Contributor

    Update:

    param :foo becomes @Foo
    param :foo_bar becomes @FooBar
    

    The CamelCase is used to highlight that the param is immutable.

  2. 22 remaining items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions