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

Add property map in model state to store values in between handler calls #132

Merged
merged 4 commits into from
Oct 15, 2021

Conversation

planger
Copy link
Member

@planger planger commented Oct 7, 2021

Also removes superfluous import in layout operation handler

Fixes eclipse-glsp/glsp#401

Also removes superfluous import in layout operation handler

Fixes eclipse-glsp/glsp#401
Copy link
Contributor

@martin-fleck-at martin-fleck-at left a comment

Choose a reason for hiding this comment

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

Change looks good to me in general and I like the idea of the generic map in the state for simple custom use cases. However, I have a few minor remarks which you maybe want to consider. Thank you Philip!

@@ -34,6 +36,7 @@
protected String clientId;

protected Map<String, String> options;
protected final Map<String, Object> memento = new HashMap<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

I am a bit worried about the name memento since it kind of implies a 'store state - restore state' functionality. From what I understand this is necessary since we only have the model state as persistence for handlers so this is really for custom data. Maybe 'properties', 'data', 'userData', 'appData', 'sessionData' or something similar would be a good alternative? But I leave that up to you.

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right. I used memento because I was only thinking about stateless handlers and for them it is sort-of a memento.
I think I'll go with properties.

}

@Override
public Optional<Object> getMemento(final String key) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not something that needs to be done immediately but in my experience 'Object' is almost never really useful and the second step after calling this method would be to cast the Object to something you can actually use. Therefore I believe it would be great to already provide that casting step as part of an additional method Optional<T> getMemento(String key, Class<T> type) or something similar to ease the usage of the user storage - maybe a similar method can be provided for clearing.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice, sure that makes the API more convenient.

@planger planger changed the title Add memento map in model state Add property map in model state to store values in between handler calls Oct 15, 2021
@planger planger merged commit 695a9c7 into master Oct 15, 2021
@planger planger deleted the planger/issues/401 branch October 15, 2021 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generic map in GModelState to allow handlers store arbitrary things in model state
3 participants