-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3345 from gunn/ember-libraries
Create Ember.libraries for keeping track of versions for debugging.
- Loading branch information
Showing
5 changed files
with
113 additions
and
17 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
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,40 @@ | ||
// Provides a way to register library versions with ember. | ||
|
||
Ember.libraries = function() { | ||
var libraries = []; | ||
var coreLibIndex = 0; | ||
|
||
var getLibrary = function(name) { | ||
for (var i = 0; i < libraries.length; i++) { | ||
if (libraries[i].name === name) { | ||
return libraries[i]; | ||
} | ||
} | ||
}; | ||
|
||
libraries.register = function(name, version) { | ||
if (!getLibrary(name)) { | ||
libraries.push({name: name, version: version}); | ||
} | ||
}; | ||
|
||
libraries.registerCoreLibrary = function(name, version) { | ||
if (!getLibrary(name)) { | ||
libraries.splice(coreLibIndex++, 0, {name: name, version: version}); | ||
} | ||
}; | ||
|
||
libraries.deRegister = function(name) { | ||
var lib = getLibrary(name); | ||
if (lib) libraries.splice(libraries.indexOf(lib), 1); | ||
}; | ||
|
||
libraries.each = function (callback) { | ||
libraries.forEach(function(lib) { | ||
callback(lib.name, lib.version); | ||
}); | ||
}; | ||
return libraries; | ||
}(); | ||
|
||
Ember.libraries.registerCoreLibrary('Ember', Ember.VERSION); |
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
var libs = Ember.libraries; | ||
|
||
test('Ember registers itself', function() { | ||
equal(libs[0].name, "Ember"); | ||
}); | ||
|
||
test('core libraries come before other libraries', function() { | ||
var l = libs.length; | ||
|
||
libs.register("my-lib", "2.0.0a"); | ||
libs.registerCoreLibrary("DS", "1.0.0-beta.2"); | ||
|
||
equal(libs[l].name, "DS"); | ||
equal(libs[l+1].name, "my-lib"); | ||
|
||
libs.deRegister("my-lib"); | ||
libs.deRegister("DS"); | ||
}); | ||
|
||
test('only the first registration of a library is stored', function() { | ||
var l = libs.length; | ||
|
||
libs.register("magic", 1.23); | ||
libs.register("magic", 2.23); | ||
libs.register("magic", 3.23); | ||
|
||
equal(libs[l].name, "magic"); | ||
equal(libs[l].version, 1.23); | ||
equal(libs.length, l+1); | ||
|
||
libs.deRegister("magic"); | ||
}); | ||
|
||
test('libraries can be de-registered', function() { | ||
var l = libs.length; | ||
|
||
libs.register("lib1", "1.0.0b"); | ||
libs.register("lib2", "1.0.0b"); | ||
libs.register("lib3", "1.0.0b"); | ||
|
||
libs.deRegister("lib1"); | ||
libs.deRegister("lib3"); | ||
|
||
equal(libs[l].name, "lib2"); | ||
equal(libs.length, l+1); | ||
|
||
libs.deRegister("lib2"); | ||
}); |