-
Notifications
You must be signed in to change notification settings - Fork 5
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
HY-4737 Fix unloading, refactor and cleanup #15
Conversation
# Conflicts: # lib/font_face_observer.dart
RavenNumber of Findings: 0 |
General InformationTicket(s): Code Review(s): #15 Additional InformationReviewers: robbecker-wf, seanburke-wf, tomconnell-wf, stephenbush-wf
|
smithy.yml
Outdated
@@ -1,7 +1,7 @@ | |||
project: static | |||
language: dart | |||
|
|||
runner_image: drydock-prod.workiva.org/workiva/smithy-runner-dart:91483 | |||
runner_image: drydock-prod.workiva.net/workiva/smithy-runner-dart:124921 |
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.
update to Dart 1.22.1
@@ -46,8 +46,14 @@ FontFaceObserver( | |||
Future<FontLoadResult> check() async | |||
|
|||
// Load a font from the given URL by adding a font-face rule | |||
// returns the same Future<bool> from isLoaded() | |||
// returns the same Future<FontLoadResult> from check() |
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.
💯
Future<int> FontFaceObserver.unloadGroup(String group); | ||
|
||
// Unload a specific font by key and group | ||
Future<bool> FontFaceObserver.unload(String key, String group); |
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.
Might want a unloadAll someday. Could be useful for mobile, to be called when receiving low memory warnings. 📦
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.
I thought about unloadAll but consider it potentially unsafe to use since fonts may be loaded from different areas and shared. If one calls unload all, it may unload a font that some place else is actively using. Perhaps this could be carefully added in a followup.
{this.mimeType: 'application/octet-stream', | ||
this.encoding, | ||
this.data, | ||
this.isDataBase64Encoded: true}); |
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.
🥇
lib/font_face_observer.dart
Outdated
final bool didTimeout; | ||
|
||
/// Construct a new FontLoadResult |
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.
👎 says exactly what the code does.
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.
truth. I'm looking at the dartdoc output and improving the readme and doc strings now.
return false; | ||
} | ||
bool _isNullOrWhitespace(String s) { | ||
return s == null || s.trim().isEmpty; |
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.
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.
I wanted to avoid that dependency here
lib/font_face_observer.dart
Outdated
|
||
/// Recalculcate the sum of total uses and total list of groups for this | ||
/// font record and update the data-groups attribute on the style element. | ||
void _recalc() { |
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.
Since this takes no parameters, the naming gives no clue to what is recalc'ed. _recalcGroupUses?
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.
I'll dogpile on this while I am here. I almost feel like this should take a groupUses and return the groupData, then it could just be a function that doesn't have to mutate state. But, I'd better leave talk of functional programming to the pros.
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.
I chose to rename to _updateGroupUseCounts
. How's that feel?
/// DOM or drawn into a canvas. If you need to load fonts with an authenticated | ||
/// request, you can handle the networking part yourself and then still use | ||
/// FontFaceObserver to detect when it is ready by passing in the font as a | ||
/// base64 data or Blob URI. |
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.
This is a nice doc string. It would be nice to have an example of how to get base64 data or the 'Blob URI'
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.
Agree. I'm currently working on dartdoc. I'll add.
lib/font_face_observer.dart
Outdated
List<String> keysToRemove = new List<String>(); | ||
List<_FontRecord> records = new List<_FontRecord>(); | ||
for (String k in _loadedFonts.keys.toList()) { | ||
// _loadedFonts.keys.forEach(await (k) async { |
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.
removeme?
lib/font_face_observer.dart
Outdated
// _loadedFonts.keys.forEach(await (k) async { | ||
_FontRecord record = _loadedFonts[k]; | ||
// wait for the load future to complete | ||
await record.futureLoadResult; |
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.
Would it be better to have a callback when the future completes, instead of blocking on it?
lib/font_face_observer.dart
Outdated
// if we get here, the font load has timed out | ||
// make sure the font is unloaded | ||
_unloadFont(key, record); | ||
// TODO return a failed future |
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.
Need to do this still?
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.
we do not
/// for a given [family] at a certain [cssSize] (default 100px) | ||
String _getStyle(String family, {String cssSize: '100px'}) { | ||
String _stretch = supportsStretch ? stretch : ''; | ||
return '$style $weight $_stretch $cssSize $family'; |
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.
Is the double space if stretch is '' going to be problem?
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.
It should not be.
/// one of which will trigger a scroll event when the font loads and the | ||
/// dimensions of the test string change. These rulers are checked periodically | ||
/// waiting for the font to become available. The Timer is returned so it may | ||
/// be cancelled and not check infinitely. |
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.
🏆
widthSerif = width; | ||
_checkWidths(); | ||
}); | ||
|
||
_rulerSerif.setFont(_getStyle('"$family",AdobeBlank,serif')); | ||
|
||
_rulerMonospace.onResize((width) { | ||
_rulerMonospace.onResize((num width) { |
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.
Be nice to your code reviewers; let's turn on linting in a distinct pr, next time!
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.
sorry, scope creeped this PR.
+1 SDK bump |
No audit for base 374f1c4
|
No audit for base 374f1c4
|
+1 the changes |
No audit for base 374f1c4
|
+10 Seems legit!
|
+1 on the comment change |
QA +1
@Workiva/release-management-p for merge into master |
+1 from RM |
Problem
Font unloading doesn't work well since it doesn't track uses for loaded fonts correctly across groups and doesn't handle the async possibility of loading/unloading when things are in progress.
Solution
Refactor to track uses per group, and wait for loading to finish before unloading.
I added dartdoc strings and turned doc generation and publishing back on.
I turned on the semver audit service.
I turned on nearly all of the analysis options and strong mode.
+10 instructions
pub serve test
and play with localhost:8080/unload.html