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

Unify trim/delete/insert events as 'move' events. #1948

Closed
wants to merge 1 commit into from

Conversation

PerBothner
Copy link
Contributor

This solves GitHub issue #1946.

if (this.selectionStart) {
this.selectionStart[1] -= amount;
if (this.selectionStart && this.selectionStart[1] >= event.start
&& (! event.end || this.selectionStart[1] < event.end)) {
Copy link
Member

@Tyriar Tyriar Mar 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I think the current way is much more readable and explicit in explaining what is actually happening, the need to check for end? and handle it is one of the main reasons I think this.

Another good example:

// Where is it moving?
model.onMove({start: 0, amount: 1});

A negative amount is also a little confusing unless you go and read the definition of IMoveEvent.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts @jerch?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gonna answer below to stay in the thread flow...

@PerBothner
Copy link
Contributor Author

I see the main reason for unifying them is that I believe anywhere you'd need a handler for one would need a handler for all three. Having to write 3 handlers is both more verbose and more error-prone (likely to forget one or make a mistake in one).

@jerch
Copy link
Member

jerch commented Mar 7, 2019

Well I dont quite the point of this idea, tbh. Is this just for API unification? Imho this is more a matter of taste (code style) than it shows real benefits. It also has drawbacks. A "one event fits all purposes" paradigm kinda defeats language features like strong typing (well for TS at least during compile time), you will have to read the docs to grasp the correct meaning of an event with parameters xy. With separate events you still need to know what a particular event means, but TS can assist you through several levels of invocations.
If you really need to deal with several events in one block of code, you can still register to all of the needed events. Again TS can help you in your code block with the type system.

Thats all not possible with a single event type, where you instead have to implement the meaning orthogonal to the type system. Much like redux's actions with TS, they kinda feel silly in TS as they cannot not leverage the type system well.

@PerBothner
Copy link
Contributor Author

I claim there is no functional difference between a 'trim' and a 'delete' event, and there is no place in the code (or possible addons) where you would want to handle one and not the other, or handle them differently: 'trim' is just a special case of 'delete'. When it comes to 'insert' vs 'delete', the only difference is one of sign, and I also believe there is no place where you would want to handle one and not the other.

This to me argues strongly for unifying these events.

@Tyriar
Copy link
Member

Tyriar commented Mar 8, 2019

'trim' is just a special case of 'delete'

This is a good point and I could see us merging these, but it would only result in more GC. Right now I find things fairly readable and merging these events would mean a new object would need to be created for every trim as the trim event just passes in the amount with the event right now. Since thousands+ of these can fire a second that's a lot of IDeleteEvent (or IMoveEvent) objects needed to be created and GC'd.

We'll just have to be diligent in making sure we listen to everything 🙂

@Tyriar Tyriar closed this Mar 8, 2019
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

Successfully merging this pull request may close these issues.

3 participants