Files
meteor/docs/rules/eventmap-params.md
Dominik Ferber faefe6c5d1 refactor: rename rules
The previous names were confusing, long and partially redundant.
The new names are:
- blaze-consistent-eventmap-params -> eventmap-params
- no-blaze-lifecycle-assignment -> no-template-lifecycle-assignments
- template-naming-convention -> template-names

BREAKING CHANGE: Rule names have changed.
2016-03-09 18:38:23 +01:00

1.6 KiB

Consistent event handler parameters (eventmap-params)

Force consistent event handler parameters in event maps

Rule Details

Prevent the use of differently named parameters in event handlers to achieve more consistent code

The following patterns are considered warnings:

Template.foo.events({
  // 'foo' does not match 'event'
  'submit form': function (foo) {}
})

Template.foo.events({
  // 'bar' does not match 'templateInstance'
  'submit form': function (event, bar) {}
})

Template.foo.events({
  // neither 'foo' nor 'bar' are correct
  'submit form': function (foo, bar) {}
})

The following patterns are not warnings:

Template.foo.events({
  'submit form': function (event) {}
})

Template.foo.events({
  'submit form': function (event, templateInstance) {}
})

Options

You can optionally set the names of the parameters.
You can set the name of the event parameter using eventParamName and the name of the template-instance parameterusing templateInstanceParamName.
Here are examples of how to do this:

/*
 eslint meteor/eventmap-params: [2, {"eventParamName": "evt"}]
 */
Template.foo.events({
  'submit form': function (evt) {}
})

/*
 eslint meteor/eventmap-params: [2, {"templateInstanceParamName": "tmplInst"}]
 */
Template.foo.events({
  'submit form': function (event, tmplInst) {}
})

/*
 eslint meteor/eventmap-params: [2, {"eventParamName": "evt", "templateInstanceParamName": "tmplInst"}]
 */
Template.foo.events({
  'submit form': function (evt, tmplInst) {}
})

Further Reading