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

Options are stored on the model, this is bad when 2 views use diff options. #311

Open
jeffijoe opened this issue Sep 25, 2015 · 2 comments

Comments

@jeffijoe
Copy link

Example:

class SubView extends View {
   initialize() {
      // Custom selector.
      Validation.bind(this.model, { selector: 'data-validate' });
   }
}

class MyView extends View {
   initialize() {
      // Standard.
      Validation.bind(this.model);
   }

   onRender() {
     // 2 views sharing the same model.
     let subview = new SubView({model: this.model});
     ....
   }
}

This breaks the parent view, because the last .binds options are the ones that are used in all views bound to the same model.

This is pretty critical as I have a lot of subviews that are basically components.

@rally25rs
Copy link

I just spent hours debugging into the validation code to come to this same conclusion. If 3 different views all call

Validation.bind(this, {
  invalid: this.onInvalid.bind(this)
}

then the model becomes invalid, the same invalid function (whichever was last registered) will be called 3 times, but the correct view will be passed to it as the first parameter.

It really makes it hard to have a Marionette Behavior that reacts to validation issues. If a sub-region of a view has a Validation.bind then it prevents the parent from working correctly unless they share the same options.invalid and options.valid function.

@blikblum
Copy link
Contributor

The view bind design is just flawed. I looked into ways to fix it but would increase code complexity.

At the time i gave up and now i think is better to decouple things (do not store bound view to a model property)

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

No branches or pull requests

3 participants