You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Refactor the client's generic type parameters (#27)
* Add tests for hetergeneous subscriptions
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).
* Refactor the client's generic type parameters
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.
0 commit comments