Skip to content

Refactor the client's generic type parameters #27

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

Merged
merged 2 commits into from
Mar 25, 2017

Conversation

jhansche
Copy link
Contributor

The way it was written, a single client could only ever be used for a single
<T extends ParseObject> type parameter. That means to have multiple
LiveQuery objects for multiple ParseObject classes, we're forced to create
multiple ParseLiveQueryClient objects, each with its own <T> type parameter.

Since the client itself does not actually require being locked to a single
type, we can move those type parameters to individual methods instead.

The unit test does not fail before or after the test, but this is more of a change of convenience.

Joe Hansche added 2 commits March 24, 2017 16:33
Ensures that we are able to subscribe to multiple ParseQuery, regardless
of class.

The current tests work fine, because the client is declared as
ParseLiveQueryClient<ParseObject>, so subclasses are accepted. But many
method parameters have to be cast to more specific (or in some cases, less
specific) class types.

The problem with this approach is that you are forced to use the top-level
`ParseLiveQueryClient<ParseObject>` type parameter, which means all other
type parameters must match `ParseObject`, including `ParseQuery<ParseObject>`,
and the callback events all have to take `ParseObject` and then it would have
to be cast to the desired heterogeneous types.

The goal would be that the type parameter is only enforced during subscription,
not at the Client declaration level:

    ParseLiveQueryClient client = ...
    handle1 = client.subscribe(ParseQuery.getQuery(Subclass1.class));
    handle2 = client.subscribe(ParseQuery.getQuery(Subclass2.class));

In its current state, `handle1` and `handle2` would be forced to use an event
callback locked to `<ParseObject>`, and cast the objects to `Subclass1` and
`Subclass2`.  OR the only other option is to create two separate
ParseLiveQueryClient objects (which therefore requires multiple websocket
connections).
The way it was written, a single client could only ever be used for a single
`<T extends ParseObject>` type parameter. That means to have multiple
LiveQuery objects for multiple ParseObject classes, we're forced to create
multiple ParseLiveQueryClient objects, each with its own `<T>` type parameter.

Since the client itself does not actually require being locked to a single
type, we can move those type parameters to individual methods instead.
@rogerhu
Copy link
Contributor

rogerhu commented Mar 24, 2017

cool this sounds like the right approach =)

@rogerhu
Copy link
Contributor

rogerhu commented Mar 24, 2017

Can you update the README docs too? :)

@rogerhu rogerhu merged commit f6e5c4d into parse-community:master Mar 25, 2017
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.

2 participants