forked from kgrgreer/foam3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. New test to ensure that src/core/*.js all appear in src/core.json 2. New dev dependency: es6-shim (required for Promises on ancient versions of NodeJS) 3. Document events and dynamic in core.json 4. (global) contextify core/event.js code 5. Move Jasmine helper "Help" to more meaningful name: "interop" 5.a) Implement NodeJS/browser shims for including code, loading files, and booting core. 6. Port tests (context, event) to use interop 7. Clean up core/event.js tests to deal with global namespace pollution
- Loading branch information
Showing
8 changed files
with
177 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
[ | ||
"core/context.js" | ||
"core/context.js", | ||
"core/event.js", | ||
"core/dynamic.js" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
var GLOBAL = global || this; | ||
var NODEJS = typeof module !== 'undefined' && module.exports; | ||
|
||
if (NODEJS) require('es6-shim'); | ||
|
||
// TODO(markdittmer): Make the non-NodeJS case match with wherever we expect | ||
// Jasmine's SpecRunner.html. | ||
var SRC_DIR = NODEJS ? process.cwd() + '/src' : 'src'; | ||
|
||
GLOBAL.loadSrcScript = function(path) { | ||
return new Promise(function(resolve, reject) { | ||
if (NODEJS) { | ||
var requirePath = SRC_DIR + '/' + path; | ||
var success = true; | ||
try { | ||
require(requirePath); | ||
} catch (e) { | ||
success = false; | ||
reject(e); | ||
} | ||
if (success) resolve(); | ||
} else { | ||
var document = GLOBAL.document; | ||
var script = document.createElement('script'); | ||
script.addEventListener('load', function() { resolve(); }); | ||
script.addEventListener('error', function() { reject(); }); | ||
script.setAttribute('src', SRC_DIR + '/' + path + '.js'); | ||
document.head.appendChild(script); | ||
} | ||
}); | ||
}; | ||
|
||
GLOBAL.readSrcFile = function(path, callback) { | ||
return new Promise(function(resolve, reject) { | ||
if (NODEJS) { | ||
var fileContents = require('fs').readFileSync(SRC_DIR + '/' + path); | ||
resolve(fileContents); | ||
} else { | ||
var xhr = new XMLHttpRequest(); | ||
xhr.open(SRC_DIR + '/' + path); | ||
xhr.addEventListener('load', function() { resolve(xhr.responseText); }); | ||
xhr.addEventListener('error', function(error) { reject(error); }); | ||
xhr.send(); | ||
} | ||
}); | ||
}; | ||
|
||
var coreFileNamesPromise = | ||
GLOBAL.readSrcFile('core.json').then(function(coreFilesJSON) { | ||
return JSON.parse(coreFilesJSON); | ||
}); | ||
|
||
GLOBAL.loadCoreTo = function(lastCoreFileName) { | ||
return coreFileNamesPromise.then(function(coreFileNames) { | ||
var cont = true; | ||
return coreFileNames.reduce(function(promise, coreFileName) { | ||
if (!cont) return promise; | ||
promise = promise.then(GLOBAL.loadSrcScript(coreFileName)); | ||
if (coreFileName === lastCoreFileName) cont = false; | ||
return promise; | ||
}, Promise.resolve()); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.