-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Comments
I would welcome this, have never like two-way binding. |
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. |
As a followup to my last comment, this seems to work pretty well for getting a computed: {
tmp: user => {
return Object.assign({}, user);
}
}, |
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. |
Is this literally requesting an option to disable the |
yep |
…s, based on options Closes sveltejs#54
add option to disable two-way binding
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 ariseThe text was updated successfully, but these errors were encountered: