@@ -15,12 +15,11 @@ const smalltalk = require('smalltalk');
1515const { promisify} = require ( 'es6-promisify' ) ;
1616const jssha = require ( 'jssha' ) ;
1717const restafary = require ( 'restafary/client' ) ;
18+ const tryToCatch = require ( 'try-to-catch' ) ;
1819
1920window . load = window . load || load ;
2021window . exec = window . exec || exec ;
2122
22- const loadJSON = promisify ( load . json ) ;
23-
2423const Story = require ( './story' ) ;
2524const _clipboard = require ( './_clipboard' ) ;
2625const _setEmmet = require ( './_set-emmet' ) ;
@@ -121,7 +120,7 @@ Edward.prototype._init = function(fn) {
121120 callback ( ) ;
122121 } ) ;
123122 } ,
124- ( ) => {
123+ async ( ) => {
125124 this . _Emitter = Emitify ( ) ;
126125 this . _Ace = ace . edit ( this . _Element ) ;
127126 this . _Modelist = ace . require ( 'ace/ext/modelist' ) ;
@@ -135,23 +134,24 @@ Edward.prototype._init = function(fn) {
135134 this . _addCommands ( ) ;
136135 this . _Ace . $blockScrolling = Infinity ;
137136
138- load . json ( this . _PREFIX + '/edit.json' , ( error , config ) => {
139- const {
140- options = { } ,
141- } = config ;
142- const preventOverwrite = ( ) => {
143- for ( const name of Object . keys ( this . _Config . options ) ) {
144- options [ name ] = this . _Config . options [ name ] ;
145- }
146- } ;
147-
148- fn ( ) ;
149- preventOverwrite ( ) ;
150-
151- this . _Config = config ;
152-
153- edward . setOptions ( options ) ;
154- } ) ;
137+ const config = await load . json ( this . _PREFIX + '/edit.json' ) ;
138+
139+ const {
140+ options = { } ,
141+ } = config ;
142+
143+ const preventOverwrite = ( ) => {
144+ for ( const name of Object . keys ( this . _Config . options ) ) {
145+ options [ name ] = this . _Config . options [ name ] ;
146+ }
147+ } ;
148+
149+ fn ( ) ;
150+ preventOverwrite ( ) ;
151+
152+ this . _Config = config ;
153+
154+ edward . setOptions ( options ) ;
155155 } ,
156156 ] ) ;
157157} ;
@@ -461,7 +461,7 @@ Edward.prototype._loadOptions = async function() {
461461 if ( this . _Options )
462462 return this . _Options ;
463463
464- const data = await loadJSON ( url ) ;
464+ const data = await load . json ( url ) ;
465465
466466 this . _Options = data ;
467467
@@ -495,14 +495,14 @@ Edward.prototype._diff = function(newValue) {
495495
496496Edward . prototype . _setEmmet = _setEmmet ;
497497
498- Edward . prototype . _addExt = function ( name , fn ) {
498+ Edward . prototype . _addExt = async function ( name , fn ) {
499499 if ( this . _Ext )
500500 return add ( null , this . _Ext ) ;
501501
502- load . json ( this . _PREFIX + '/json/ext.json' , ( error , data ) => {
503- this . _Ext = data ;
504- add ( error , this . _Ext ) ;
505- } ) ;
502+ const [ error , data ] = await tryToCatch ( load . json , this . _PREFIX + '/json/ext.json' ) ;
503+ this . _Ext = data ;
504+
505+ add ( error , this . _Ext ) ;
506506
507507 function add ( error , exts ) {
508508 if ( error )
0 commit comments