-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Migrating from RequireJS to ES6 Modules #36595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0f17c98
chore: Original JS files copied from xmodule/js/src/video directory
farhan 0d2f3d5
refactor: Update and migrate Video Block JS files into xmodule/assets
farhan d379540
test: Enable Karma Js tests (#37351)
salman2013 a0765d3
Merge branch 'master' into farhan/move-video-js-to-assets
farhan af8d3e1
Update package.json
farhan 8280662
Merge branch 'master' into farhan/move-video-js-to-assets
farhan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,52 @@ | ||
| 'use strict'; | ||
|
|
||
| /** | ||
| * Provides convenient way to process big amount of data without UI blocking. | ||
| * | ||
| * @param {array} list Array to process. | ||
| * @param {function} process Calls this function on each item in the list. | ||
| * @return {array} Returns a Promise object to observe when all actions of a | ||
| * certain type bound to the collection, queued or not, have finished. | ||
| */ | ||
| let AsyncProcess = { | ||
| array: function(list, process) { | ||
| if (!_.isArray(list)) { | ||
| return $.Deferred().reject().promise(); | ||
| } | ||
|
|
||
| if (!_.isFunction(process) || !list.length) { | ||
| return $.Deferred().resolve(list).promise(); | ||
| } | ||
|
|
||
| let MAX_DELAY = 50, // maximum amount of time that js code should be allowed to run continuously | ||
| dfd = $.Deferred(); | ||
| let result = []; | ||
| let index = 0; | ||
| let len = list.length; | ||
|
|
||
| let getCurrentTime = function() { | ||
| return (new Date()).getTime(); | ||
| }; | ||
|
|
||
| let handler = function() { | ||
| let start = getCurrentTime(); | ||
|
|
||
| do { | ||
| result[index] = process(list[index], index); | ||
| index++; | ||
| } while (index < len && getCurrentTime() - start < MAX_DELAY); | ||
|
|
||
| if (index < len) { | ||
| setTimeout(handler, 25); | ||
| } else { | ||
| dfd.resolve(result); | ||
| } | ||
| }; | ||
|
|
||
| setTimeout(handler, 25); | ||
|
|
||
| return dfd.promise(); | ||
| } | ||
| }; | ||
|
|
||
| export default AsyncProcess; |
This file contains hidden or 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,81 @@ | ||
| 'use strict'; | ||
|
|
||
| import _ from 'underscore'; | ||
|
|
||
|
|
||
| /** | ||
| * Creates a new object with the specified prototype object and properties. | ||
| * @param {Object} o The object which should be the prototype of the | ||
| * newly-created object. | ||
| * @private | ||
| * @throws {TypeError, Error} | ||
| * @return {Object} | ||
| */ | ||
| let inherit = Object.create || (function() { | ||
| let F = function() {}; | ||
|
|
||
| return function(o) { | ||
| if (arguments.length > 1) { | ||
| throw Error('Second argument not supported'); | ||
| } | ||
| if (_.isNull(o) || _.isUndefined(o)) { | ||
| throw Error('Cannot set a null [[Prototype]]'); | ||
| } | ||
| if (!_.isObject(o)) { | ||
| throw TypeError('Argument must be an object'); | ||
| } | ||
|
|
||
| F.prototype = o; | ||
|
|
||
| return new F(); | ||
| }; | ||
| }()); | ||
|
|
||
| /** | ||
| * Component module. | ||
| * @exports video/00_component.js | ||
| * @constructor | ||
| * @return {jquery Promise} | ||
| */ | ||
| let Component = function() { | ||
| if ($.isFunction(this.initialize)) { | ||
| // eslint-disable-next-line prefer-spread | ||
| return this.initialize.apply(this, arguments); | ||
| } | ||
| }; | ||
|
|
||
| /** | ||
| * Returns new constructor that inherits form the current constructor. | ||
| * @static | ||
| * @param {Object} protoProps The object containing which will be added to | ||
| * the prototype. | ||
| * @return {Object} | ||
| */ | ||
| Component.extend = function(protoProps, staticProps) { | ||
| let Parent = this; | ||
| let Child = function() { | ||
| if ($.isFunction(this.initialize)) { | ||
| // eslint-disable-next-line prefer-spread | ||
| return this.initialize.apply(this, arguments); | ||
| } | ||
| }; | ||
|
|
||
| // Inherit methods and properties from the Parent prototype. | ||
| Child.prototype = inherit(Parent.prototype); | ||
| Child.constructor = Parent; | ||
| // Provide access to parent's methods and properties | ||
| Child.__super__ = Parent.prototype; | ||
|
|
||
| // Extends inherited methods and properties by methods/properties | ||
| // passed as argument. | ||
| if (protoProps) { | ||
| $.extend(Child.prototype, protoProps); | ||
| } | ||
|
|
||
| // Inherit static methods and properties | ||
| $.extend(Child, Parent, staticProps); | ||
|
|
||
| return Child; | ||
| }; | ||
|
|
||
| export default Component; |
This file contains hidden or 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,35 @@ | ||
| 'use strict'; | ||
|
|
||
| /** | ||
| * i18n module. | ||
| * @exports video/00_i18n.js | ||
| * @return {object} | ||
| */ | ||
|
|
||
| let i18n = { | ||
| Play: gettext('Play'), | ||
| Pause: gettext('Pause'), | ||
| Mute: gettext('Mute'), | ||
| Unmute: gettext('Unmute'), | ||
| 'Exit full browser': gettext('Exit full browser'), | ||
| 'Fill browser': gettext('Fill browser'), | ||
| Speed: gettext('Speed'), | ||
| 'Auto-advance': gettext('Auto-advance'), | ||
| Volume: gettext('Volume'), | ||
| // Translators: Volume level equals 0%. | ||
| Muted: gettext('Muted'), | ||
| // Translators: Volume level in range ]0,20]% | ||
| 'Very low': gettext('Very low'), | ||
| // Translators: Volume level in range ]20,40]% | ||
| Low: gettext('Low'), | ||
| // Translators: Volume level in range ]40,60]% | ||
| Average: gettext('Average'), | ||
| // Translators: Volume level in range ]60,80]% | ||
| Loud: gettext('Loud'), | ||
| // Translators: Volume level in range ]80,99]% | ||
| 'Very loud': gettext('Very loud'), | ||
| // Translators: Volume level equals 100%. | ||
| Maximum: gettext('Maximum') | ||
| }; | ||
|
|
||
| export default i18n; |
This file contains hidden or 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,83 @@ | ||
| 'use strict'; | ||
|
|
||
| /** | ||
| * Provides convenient way to work with iterable data. | ||
| * @exports video/00_iterator.js | ||
| * @constructor | ||
| * @param {array} list Array to be iterated. | ||
| */ | ||
| let Iterator = function(list) { | ||
| this.list = list; | ||
| this.index = 0; | ||
| this.size = this.list.length; | ||
| this.lastIndex = this.list.length - 1; | ||
| }; | ||
|
|
||
| Iterator.prototype = { | ||
|
|
||
| /** | ||
| * Checks validity of provided index for the iterator. | ||
| * @access protected | ||
| * @param {numebr} index | ||
| * @return {boolean} | ||
| */ | ||
| _isValid: function(index) { | ||
| return _.isNumber(index) && index < this.size && index >= 0; | ||
| }, | ||
|
|
||
| /** | ||
| * Returns next element. | ||
| * @param {number} [index] Updates current position. | ||
| * @return {any} | ||
| */ | ||
| next: function(index) { | ||
| if (!(this._isValid(index))) { | ||
| index = this.index; | ||
| } | ||
|
|
||
| this.index = (index >= this.lastIndex) ? 0 : index + 1; | ||
|
|
||
| return this.list[this.index]; | ||
| }, | ||
|
|
||
| /** | ||
| * Returns previous element. | ||
| * @param {number} [index] Updates current position. | ||
| * @return {any} | ||
| */ | ||
| prev: function(index) { | ||
| if (!(this._isValid(index))) { | ||
| index = this.index; | ||
| } | ||
|
|
||
| this.index = (index < 1) ? this.lastIndex : index - 1; | ||
|
|
||
| return this.list[this.index]; | ||
| }, | ||
|
|
||
| /** | ||
| * Returns last element in the list. | ||
| * @return {any} | ||
| */ | ||
| last: function() { | ||
| return this.list[this.lastIndex]; | ||
| }, | ||
|
|
||
| /** | ||
| * Returns first element in the list. | ||
| * @return {any} | ||
| */ | ||
| first: function() { | ||
| return this.list[0]; | ||
| }, | ||
|
|
||
| /** | ||
| * Returns `true` if current position is last for the iterator. | ||
| * @return {boolean} | ||
| */ | ||
| isEnd: function() { | ||
| return this.index === this.lastIndex; | ||
| } | ||
| }; | ||
|
|
||
| export default Iterator; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.