Skip to content
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

Merged
merged 24 commits into from
Apr 14, 2017
Merged

Conversation

robbecker-wf
Copy link
Member

@robbecker-wf robbecker-wf commented Apr 10, 2017

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

  • Unit tests pass
  • run pub serve test and play with localhost:8080/unload.html

@aviary2-wf
Copy link

Raven

Number of Findings: 0

@rmconsole-wf
Copy link
Contributor

rmconsole-wf commented Apr 10, 2017

General Information

Ticket(s):

Code Review(s): #15

Additional Information

Reviewers: robbecker-wf, seanburke-wf, tomconnell-wf, stephenbush-wf
Watchlist Notifications: None

	When this pull is merged I will use the following information:
	Version: font_face_observer 2.0.0
	Release Ticket(s): HY-4693, HY-4694


Last updated on Friday, April 14 04:09 PM CST

@robbecker-wf robbecker-wf changed the title Fix unloading Fix unloading, refactor and cleanup Apr 13, 2017
@rm-astro-wf rm-astro-wf changed the title Fix unloading, refactor and cleanup HY-4737 Fix unloading, refactor and cleanup Apr 13, 2017
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
Copy link
Member Author

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()
Copy link
Member

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);
Copy link
Member

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. 📦

Copy link
Member Author

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});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥇

final bool didTimeout;

/// Construct a new FontLoadResult
Copy link
Member

@tomconnell-wf tomconnell-wf Apr 14, 2017

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.

Copy link
Member Author

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is tiny, but you could use quiver.

image

Copy link
Member Author

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


/// 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() {
Copy link
Member

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?

Copy link
Member

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.

Copy link
Member Author

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.
Copy link
Member

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'

Copy link
Member Author

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.

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removeme?

// _loadedFonts.keys.forEach(await (k) async {
_FontRecord record = _loadedFonts[k];
// wait for the load future to complete
await record.futureLoadResult;
Copy link
Member

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?

// if we get here, the font load has timed out
// make sure the font is unloaded
_unloadFont(key, record);
// TODO return a failed future
Copy link
Member

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?

Copy link
Member Author

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';
Copy link
Member

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?

Copy link
Member Author

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.
Copy link
Member

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) {
Copy link
Member

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!

Copy link
Member Author

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.

@seanburke-wf
Copy link

+1 SDK bump

@semveraudit-wf
Copy link

No audit for base 374f1c4

Powered by semver-audit-service. Please report any problems by filing an issue.
Browse public API.

@seanburke-wf
Copy link

@rmconsole-wf

@semveraudit-wf
Copy link

No audit for base 374f1c4

Powered by semver-audit-service. Please report any problems by filing an issue.
Browse public API.

@seanburke-wf
Copy link

+1 the changes

@semveraudit-wf
Copy link

No audit for base 374f1c4

Powered by semver-audit-service. Please report any problems by filing an issue.
Browse public API.

@stephenbush-wf
Copy link

stephenbush-wf commented Apr 14, 2017

+10 Seems legit!

  • run pub serve test and play with localhost:8080/unload.html

@seanburke-wf
Copy link

+1 on the comment change

@seanburke-wf
Copy link

QA +1

  • Testing instruction
  • Dev +1's
  • Dev/QA +10 with detail of what was tested
  • Unit test created/updated
  • All unit tests pass
  • Rosie has run and reports the proper release ticket

@Workiva/release-management-p for merge into master

@rmconsole-wf
Copy link
Contributor

+1 from RM

@rmconsole-wf rmconsole-wf merged commit 4065525 into master Apr 14, 2017
@rmconsole-wf rmconsole-wf deleted the fix_unloading branch April 14, 2017 21:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants