make module import safer

This commit is contained in:
Kevin Jahns 2015-12-02 20:04:59 +01:00
parent 334db3234b
commit 709779425c
3 changed files with 16 additions and 20 deletions

2
dist

@ -1 +1 @@
Subproject commit 5da36f07cebfdcad53b845c0c3924c22f4894f2f Subproject commit 08f0702fcde82f22663752d3b8e31803f819c094

View File

@ -550,7 +550,7 @@ module.exports = function (Y/* :any */) {
} }
* addOperation (op) { * addOperation (op) {
yield* this.os.put(op) yield* this.os.put(op)
if (!this.store.y.connector.isDisconnected() && this.store.forwardAppliedOperations) { if (!this.store.y.connector.isDisconnected() && this.store.forwardAppliedOperations && op.id[0] !== '_') {
// is connected, and this is not going to be send in addOperation // is connected, and this is not going to be send in addOperation
this.store.y.connector.broadcast({ this.store.y.connector.broadcast({
type: 'update', type: 'update',

View File

@ -25,17 +25,14 @@ function requestModules (modules) {
// determine if this module was compiled for es5 or es6 (y.js vs. y.es6) // determine if this module was compiled for es5 or es6 (y.js vs. y.es6)
// if Insert.execute is a Function, then it isnt a generator.. // if Insert.execute is a Function, then it isnt a generator..
// then load the es5(.js) files.. // then load the es5(.js) files..
var extention = Y.Struct.Insert.execute.constructor === Function ? '.js' : '.es6' var extention = typeof regeneratorRuntime !== 'undefined' ? '.js' : '.es6'
var promises = [] var promises = []
for (var i = 0; i < modules.length; i++) { for (var i = 0; i < modules.length; i++) {
var modulename = 'y-' + modules[i].toLowerCase() var modulename = 'y-' + modules[i].toLowerCase()
if (Y[modules[i]] == null) { if (Y[modules[i]] == null) {
if (requiringModules[modules[i]] == null) { if (requiringModules[modules[i]] == null) {
try {
require(modulename)(Y)
} catch (e) {
// module does not exist // module does not exist
if (typeof window !== 'undefined') { if (typeof window !== 'undefined' && window.Y !== 'undefined') {
var imported = document.createElement('script') var imported = document.createElement('script')
imported.src = Y.sourceDir + '/' + modulename + '/' + modulename + extention imported.src = Y.sourceDir + '/' + modulename + '/' + modulename + extention
document.head.appendChild(imported) document.head.appendChild(imported)
@ -47,8 +44,7 @@ function requestModules (modules) {
}) })
promises.push(requireModule.promise) promises.push(requireModule.promise)
} else { } else {
throw e require(modulename)(Y)
}
} }
} else { } else {
promises.push(requiringModules[modules[i]].promise) promises.push(requiringModules[modules[i]].promise)