Skip to content

Commit

Permalink
Fix multi define a same module
Browse files Browse the repository at this point in the history
  • Loading branch information
lifesinger committed Jul 6, 2012
1 parent 24a1e63 commit 4ce3cf7
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 27 deletions.
11 changes: 8 additions & 3 deletions dist/sea-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -929,9 +929,12 @@ seajs._config = {
if (resolvedUri) {
// If the first module in a package is not the cachedModules[derivedUri]
// self, it should assign it to the correct module when found.
if (resolvedUri === derivedUri &&
(cachedModules[derivedUri] || {}).status === STATUS.SAVED) {
cachedModules[derivedUri] = null
if (resolvedUri === derivedUri) {
var refModule = cachedModules[derivedUri]
if (refModule && refModule.packageUri &&
refModule.status === STATUS.SAVED) {
cachedModules[derivedUri] = null
}
}

var module = save(resolvedUri, meta)
Expand All @@ -941,6 +944,7 @@ seajs._config = {
// cachedModules[derivedUri] may be undefined in combo case.
if ((cachedModules[derivedUri] || {}).status === STATUS.FETCHING) {
cachedModules[derivedUri] = module
module.packageUri = derivedUri
}
}
else {
Expand Down Expand Up @@ -1066,6 +1070,7 @@ seajs._config = {
// See: test/issues/un-correspondence
if (firstModuleInPackage && module.status === STATUS.FETCHED) {
cachedModules[uri] = firstModuleInPackage
firstModuleInPackage.packageUri = uri
}
firstModuleInPackage = null

Expand Down
32 changes: 16 additions & 16 deletions dist/sea.js

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions src/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,12 @@
if (resolvedUri) {
// If the first module in a package is not the cachedModules[derivedUri]
// self, it should assign it to the correct module when found.
if (resolvedUri === derivedUri &&
(cachedModules[derivedUri] || {}).status === STATUS.SAVED) {
cachedModules[derivedUri] = null
if (resolvedUri === derivedUri) {
var refModule = cachedModules[derivedUri]
if (refModule && refModule.packageUri &&
refModule.status === STATUS.SAVED) {
cachedModules[derivedUri] = null
}
}

var module = save(resolvedUri, meta)
Expand All @@ -227,6 +230,7 @@
// cachedModules[derivedUri] may be undefined in combo case.
if ((cachedModules[derivedUri] || {}).status === STATUS.FETCHING) {
cachedModules[derivedUri] = module
module.packageUri = derivedUri
}
}
else {
Expand Down Expand Up @@ -352,6 +356,7 @@
// See: test/issues/un-correspondence
if (firstModuleInPackage && module.status === STATUS.FETCHED) {
cachedModules[uri] = firstModuleInPackage
firstModuleInPackage.packageUri = uri
}
firstModuleInPackage = null

Expand Down
2 changes: 1 addition & 1 deletion test/issues/define-override/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<script>

seajs.config({
base: './'
base: '.'
});

seajs.use('main');
Expand Down
5 changes: 4 additions & 1 deletion test/modules/require-async/program.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
define(function(require) {

var test = require('../../test')
var path = 'http://seajs.org/test/modules/require-async/'

var path = typeof global !== 'undefined' ? // node environment
'http://seajs.org/test/modules/require-async/' :
'./'

require.async(['./a', path + 'b.js', path + 'c.js'], function(a, b, c) {

Expand Down
2 changes: 1 addition & 1 deletion test/runtime/order-no-matter/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
define("increment",["math"],function(a,b){var c=a("./math").add;b.increment=function(a){return c(a,1)}});
define("math",[],function(a,b){b.add=function(){var a=0,b=0,c=arguments.length;while(b<c)a+=arguments[b++];return a}});
define("main",["../../test","increment"],function(a){var b=a("../../test"),c=a("./increment").increment;debugger;b.assert(c(1)===2,"The result of inc(1) is 2."),b.done()});
define("main",["../../test","increment"],function(a){var b=a("../../test"),c=a("./increment").increment;b.assert(c(1)===2,"The result of inc(1) is 2."),b.done()});
9 changes: 7 additions & 2 deletions test/vendor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
var MODULES_PATH = 'https://a.alipayobjects.com/static/arale/'
//var MODULES_PATH = 'http://modules.seajs.org/'

if (location.href.indexOf('/~lifesinger/') > 0) {
var isLocal = location.href.indexOf('/~lifesinger/') > 0

if (isLocal) {
MODULES_PATH = 'http://' + location.host + '/~lifesinger/seajs/spm/modules/'
}

Expand All @@ -29,6 +31,9 @@
})


define({ isMobile: isMobile })
define({
isMobile: isMobile,
isLocal: isLocal
})

})()

0 comments on commit 4ce3cf7

Please sign in to comment.