Skip to content

Add rough graph changes handling by full page reload #1763

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

Merged
merged 3 commits into from
Aug 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 33 additions & 19 deletions build_runner/lib/src/server/hot_reload_client/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ abstract class JsMap<K, V> {
external V get(K key);
}

@JS('Error')
abstract class JsError {
@JS()
external String get message;

@JS()
external String get stack;
}

@anonymous
@JS()
class DartLoader {
Expand All @@ -111,11 +120,15 @@ class DartLoader {

@JS()
external void forceLoadModule(
String moduleId, void Function(HotReloadableModule module) callback);
String moduleId,
void Function(HotReloadableModule module) callback,
void Function(JsError e) onError);

@JS()
external void loadModule(
String moduleId, void Function(HotReloadableModule module) callback);
String moduleId,
void Function(HotReloadableModule module) callback,
void Function(JsError e) onError);
}

@JS(r'$dartLoader')
Expand All @@ -128,23 +141,24 @@ List<K> keys<K, V>(JsMap<K, V> map) {
return List.from(_jsArrayFrom(map.keys()));
}

Future<Module> _reloadModule(String moduleId) {
var completer = Completer<Module>();
dartLoader.forceLoadModule(
moduleId,
allowInterop((HotReloadableModule module) =>
completer.complete(ModuleWrapper(module))));
return completer.future;
}

Future<Module> _loadModule(String moduleId) {
var completer = Completer<Module>();
dartLoader.loadModule(
moduleId,
allowInterop((HotReloadableModule module) =>
completer.complete(ModuleWrapper(module))));
return completer.future;
}
Future<Module> Function(String) _futurifyLoaderFunction(
void Function(String, void Function(HotReloadableModule),
void Function(JsError))
loaderFunction) =>
(moduleId) {
var completer = Completer<Module>();
var stackTrace = StackTrace.current;
loaderFunction(
moduleId,
allowInterop((HotReloadableModule module) =>
completer.complete(ModuleWrapper(module))),
allowInterop((e) => completer.completeError(
HotReloadFailedException(e.message), stackTrace)));
return completer.future;
};

var _reloadModule = _futurifyLoaderFunction(dartLoader.forceLoadModule);
var _loadModule = _futurifyLoaderFunction(dartLoader.loadModule);

void _reloadPage() {
window.location.reload();
Expand Down
Loading