Prevent user from overwriting read-only handle #136
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR should partially fix #130
Currently, users are able to overwrite the konva handle from outside the component. As svelte-konva relies on the handle never being overwritten, this can cause various issues.
In Svelte there is no way of specifying a read-only binding as a normal user (although certain special elements such as HTML inputs do have read-only bindings). So the next best thing is to shadow the handle variable, which still enables the user to overwrite the handle prop of the component but not affecting the component itself in any way.
This leads to the implication that a user may unknowingly overwrite the handle prop (which is by all means wrong usage) but not receive any error due to svelte-konva not doing any runtime checks for such cases. This can lead to confusing behavior in case the user overwrites the handle with another Konva instance of the shape where the handle prop has now a different object instance compared to the konva instance of the component itself.