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

Option to prevent two-way binding? #54

Closed
Rich-Harris opened this issue Nov 30, 2016 · 6 comments
Closed

Option to prevent two-way binding? #54

Rich-Harris opened this issue Nov 30, 2016 · 6 comments

Comments

@Rich-Harris
Copy link
Member

A lot of people have internalized the FUD around two-way binding to the extent that they're turned off Svelte altogether, notwithstanding the fact that it's optional and explicitly opt-in. I wonder if the compiler should have an option that prevents bindings from being used, so the 'we lost our second round of financing because a junior dev added a bind: directive' scenario doesn't arise

@proyb6
Copy link

proyb6 commented Nov 30, 2016

I would welcome this, have never like two-way binding.

@chrisdavies
Copy link

I like two-way binding when I want it. Here's a scenario that I often run into:

I have an edit form. I want it to edit a copy, and only commit the edits when the user saves. I want 2-way binding on that copy, but it shouldn't update the original (in some global array somewhere).

The way I like to do this is to pass the original into my form component, and in my form component's initialize method, I create a copy of the data.

It would be nice to be able to access the passed-in values in a components data method:

import UserCard from './user_card.html';
export default {
  data(params) {
    return {
      tmp: copyObject(params.user)
    }
  },
  components: {UserCard}
}

This would be really handy.

@chrisdavies
Copy link

As a followup to my last comment, this seems to work pretty well for getting a tmp property that is a copy of a the user object:

    computed: {
      tmp: user => {
        return Object.assign({}, user);
      }
    },

@TehShrike
Copy link
Member

When I use Redux with Ractive, I disable two-way binding to avoid accidentally mutating state. If/when I hook up Redux to Svelte, I imagine I'd want the same option.

@Rich-Harris Rich-Harris added this to the one day milestone Dec 10, 2016
@PaulBGD
Copy link
Member

PaulBGD commented Jul 11, 2017

Is this literally requesting an option to disable the bind: directive?

@Rich-Harris
Copy link
Member Author

yep

esarbanis added a commit to esarbanis/svelte that referenced this issue Dec 27, 2017
Rich-Harris added a commit that referenced this issue Dec 30, 2017
add option to disable two-way binding
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants