-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
convert Deck to strongly typed value class #17718
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
Conversation
b3b8b54 to
3dec54c
Compare
AnkiDroid/src/main/java/com/ichi2/ui/AppCompatPreferenceActivity.kt
Outdated
Show resolved
Hide resolved
3dec54c to
0f7f2df
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One question on the 1 and 2 discrepancy
AnkiDroid/src/main/java/com/ichi2/anki/dialogs/EditDeckDescriptionDialog.kt
Outdated
Show resolved
Hide resolved
0f7f2df to
b5d4aa3
Compare
|
Test added for each property |
292c595 to
4f95714
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The typings for a number of properties are incorrect, and I'm concerned.
previewGoodSecs is an Int. if you insert it into JSON as a String, it's quoted
|
|
||
| "limit" -> { | ||
| ar.getJSONArray(0).put(1, value) | ||
| deck.firstFilter.limit = value as String |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this a string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the reason is that I misunderstood the way this part of the code worked. I thought all values were strings unless converted to other values. I'll update all of that
c9e9db4 to
b7ba1ae
Compare
This comment was marked as resolved.
This comment was marked as resolved.
92ec6e9 to
f87527a
Compare
|
Sorry but I fail to understand what you mean by "break compat". |
f87527a to
e9928af
Compare
|
@ankidroid/core Thoughts? I'm fine with light wrappers. I'm a medium-strength 'no' here, but want to check for consensus
When we deviate, it should be for a good reason (ideally, the changes should be pushed upstream, then ingested downstream, or added as extension methods/helper classes outside
Making the code nicer to read/better factored is probably slowing us down here in the long run. Maybe the documentation is worthwhile, but this change goes much deeper than adding a wrapper over existing functionality. |
|
I prefer the alternative that makes me think less, which in this case is copying libanki as much as possible.
Completely agreed with that. |
|
Hello 👋, this PR has had no activity for more than 2 weeks and needs a reply from the author. If you think this is a mistake please comment and ping a maintainer to get this merged ASAP! Thanks for contributing! You have 7 days until this gets closed automatically |
|
I'm happy to take on splitting out the first few commits which are non-controversial Would be useful to wait until #18015 is in. Most of the conflicts are done, but there will be a little more on the test side. |
|
Hello 👋, this PR has had no activity for more than 2 weeks and needs a reply from the author. If you think this is a mistake please comment and ping a maintainer to get this merged ASAP! Thanks for contributing! You have 7 days until this gets closed automatically |
|
Happy to close if I haven't split this off & merged within 2 months, overall change is worthwhile |
The first interest of this change is that we are not deep cloning all
decks when creating a Deck object which should save a little bit of
time, especially loading time on collection with a lot of decks.
Instead, we have a better typing at zero runtime cost.
The second interest is that we are certain that the fact that the Deck
is implemented as a JSONObject is hidden from the developer using this
class. Instead, they can only use the provided extension, or add the
one they needs.
While most changes are relatively trivial, moving the implementation
from everywhere in the code to Deck.kt, there are some extra changes
that were needed.
I moved `getLongOrNull` to PythonExtension given that it implements
the behavior of a Python function we want to reuse, this seems more
consistent.
As value class can't be lateinit, I hardcoded
AppCompatPreferenceActivity as being a getter for the backing field
`_deck: Deck?`.
I added in testutils/JsonUtils helper method that accepts a json
holder, and a string representing the expected json, to simplify the
use of those methods.
The code used sometime `optLong("id")` and sometime
`getLong("id")`. There seems to be no reason for the difference
between both use case, and just be random choice from the
developer. Anyway, if a deck lacks an id, any place using
`getLong("id")` would have caused the code to crash, so replacing the
`optLong` by `getLong` would, in the worst case, move the time at
which the user is asked to clean their database.
There seems to be a single key we sometime set to JSONObject.NULL, it
was `delays`. For the sake of typing, the property `delays` in `deck`
is thus of type `JSONArray?`. When the value `null` is assigned to
this property, `NULL` is saved in the object, and reciprocally.
There is no need to check whether `deck` has "empty" key before
removing it. It's not even more efficient.
e9928af to
593bea9
Compare
Deck is now declared as an interface so that it can be inherited. `Deck` contains a facotry to decide whether to return a normal deck or a filtered one.
This test ensures that every changes possibly done in the deck options are correctly applied
593bea9 to
d59bd33
Compare
|
Hello 👋, this PR has had no activity for more than 2 weeks and needs a reply from the author. If you think this is a mistake please comment and ping a maintainer to get this merged ASAP! Thanks for contributing! You have 7 days until this gets closed automatically |
|
I'll fixup |
I loved David's recent work in using value class. And thought that we could finally kill the overhead cost of DeepClone in JSONObject. So I transformed
Deckinto a value class, and added the needed properties so that the other part of the code can use Deck without considering it as a JSONObject.