Skip to content

Should we add registerSubclass? #350

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

Closed
fischerscode opened this issue Apr 7, 2020 · 10 comments
Closed

Should we add registerSubclass? #350

fischerscode opened this issue Apr 7, 2020 · 10 comments

Comments

@fischerscode
Copy link
Contributor

fischerscode commented Apr 7, 2020

This issue is part of #194

Should we add registerSubclass to match the Android/IOS SDK?

Pros:

  • usage of custom ParseObject classes would be much simpler

Cons:

  • huge change
  • existing code might break by updating the SDK
@fischerscode fischerscode changed the title Should we add registerSubclass Should we add registerSubclass? Apr 7, 2020
@phillwiggins
Copy link
Member

Can you explain the pros in a bit more depth?

@fischerscode
Copy link
Contributor Author

Often the user can provide a copy-object. This is used to create new objects based on a custom ParseObject class.
By holding this copy-objects in the background, we would be able to create every object based on the right sub class.
As far as I know, included objects in a query are always of type ParseObject. This would be avoidable, too.

In summary: the user would not have to care about providing such copy-objects.

@phillwiggins
Copy link
Member

Apologies for the late reply. I still don't actually understand this. Do you have you any examples where this is done already? I understand the Parse Android SDK does but as far as I'm aware there's not too much benefit when using Flutter as we don't have reflection to iterate through class structures?

@fischerscode
Copy link
Contributor Author

fischerscode commented Apr 15, 2020

I did was not working on this for a while, too.
But I've started implementing this feature now.
To get an idea what I am talking about, you can checkout my branch.
If you run something like this after the Parse().initialize();

ParseCoreData.instance
      ..registerSubClass("Test", () => Test1())
      ..registerSubClass("Test2", () => Test2())
      ..registerSubClass("Test3", () => Test3());

The SDK will use your custom classes for objects with the classnames 'Test', 'Test2' and 'Test3'.

This should allow you to do something like this:
Test2 test = object.get<Test2>('test');
Without this changes an error gets thrown: type 'ParseObject' is not a subtype of type 'Test2'

@fischerscode
Copy link
Contributor Author

...adding a Constructor to QueryBuilder where the object the registered sub-classes get uses automatically would be useful, too.

@phillwiggins
Copy link
Member

phillwiggins commented Apr 15, 2020 via email

@fischerscode
Copy link
Contributor Author

Well, I think something as simple as this should work.

@fischerscode
Copy link
Contributor Author

@phillwiggins
I've added some more changes to my branch.
I think while working with registerSubclass, there will appear unexpected behavior (the subclass is not used), as I am sure, I have not found every critical initialization of a ParseObject jet.

Should I keep this changes in my fork for now and create a PR once I have managed to build an app using registerSubclass OR should I create a PR to 1.27 now/soon?
I'm fine with both options.

@phillwiggins
Copy link
Member

phillwiggins commented Apr 15, 2020 via email

@fischerscode
Copy link
Contributor Author

This feature got merged with #368 .

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

No branches or pull requests

2 participants