Skip to content

Commit

Permalink
Wait for iframe to load before updating preview
Browse files Browse the repository at this point in the history
Instead of waiting time period, which is non-deterministic on certain browsers.

Fixes #40
  • Loading branch information
eee-c committed Jul 3, 2013
1 parent f0da5a6 commit 2d9c3ea
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
6 changes: 2 additions & 4 deletions lib/editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,13 @@ class Editor {

/// Update the preview layer with the current contents of the editor
/// layer.
// worry about waitForAce?
updatePreview() {
if (this.edit_only) return;

this.removePreview();
var iframe = this.createPreviewIframe();

var wait = new Duration(milliseconds: 100);
new Timer(wait, (){
var iframe = this.createPreviewIframe();
iframe.onLoad.first.then((_) {
if (iframe.contentWindow == null) return;

iframe
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: ice_code_editor
version: 0.0.6
version: 0.0.7
description: Code Editor + Preview
authors:
- Chris Strom <chris@eeecomputes.com>
Expand Down
1 change: 1 addition & 0 deletions test/editor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ editor_tests() {

var preview_ready = new Completer();
editor.onPreviewChange.listen((e){
if (preview_ready.isCompleted) return;
preview_ready.complete();
});
return preview_ready.future;
Expand Down
1 change: 1 addition & 0 deletions test/full_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ full_tests() {

var preview_ready = new Completer();
editor.onPreviewChange.listen((e){
if (preview_ready.isCompleted) return;
preview_ready.complete();
});
return preview_ready.future;
Expand Down

0 comments on commit 2d9c3ea

Please sign in to comment.