Skip to content

Confusing updateModel name #302

@StevenLangbroek

Description

@StevenLangbroek

So, funny story. About a year ago I wrote a really complex form. I haven't touched the form or Stickit since then. A bug was being reported, and we were seeing some weird behavior with (a) model changes being triggered twice, and (b) what i thought was a custom "set this dom change to this model attribute in this way" function had unintended side-effects.

We loop through certain fields in a model, and for each one add a binding to our form, the hash looks like this:

bindings[escaped_key] =
  observe : "reporting_api_credentials.#{key}.value"
  key : key
  update: ($el) -> $el.val()
  updateModel: (val, event, options) -> @setCredentials("reporting_api_credentials", options.key, val)

The confusing bit is, we misused the updateModel hook to run custom setter logic, without returning false, causing the model update logic to run again (both in our own setCredentials method, and because of not returning false in stickit core).

I feel this should be solved in the following way, and would love your input before I open a PR this week:

  • rename updateModel to shouldModelUpdate
  • offer actual setVal hook to change how attributes are being set

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