浏览代码

Merge pull request #8 from cksource/t/6

t/6: Introduced the Promise class
Grzegorz Pabian 10 年之前
父节点
当前提交
8411aac6e3
共有 2 个文件被更改,包括 51 次插入0 次删除
  1. 27 0
      packages/ckeditor5-utils/src/promise.js
  2. 24 0
      packages/ckeditor5-utils/tests/promise/promise.js

+ 27 - 0
packages/ckeditor5-utils/src/promise.js

@@ -0,0 +1,27 @@
+/**
+ * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* globals window */
+
+'use strict';
+
+/**
+ * An ES6 compatible Promise class, used for deferred and asynchronous computations.
+ *
+ * @class Promise
+ */
+
+CKEDITOR.define( function() {
+	// For now we're using the native browser implementation of Promise, an ES6 feature. Just IE is not supporting it so
+	// a polyfill will have to be developed for it.
+	//
+	// http://caniuse.com/#feat=promises
+
+	if ( !window.Promise ) {
+		throw 'The Promise class is not available natively. CKEditor is not compatible with this browser.';
+	}
+
+	return window.Promise;
+} );

+ 24 - 0
packages/ckeditor5-utils/tests/promise/promise.js

@@ -0,0 +1,24 @@
+/**
+ * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* globals describe, it, expect */
+
+'use strict';
+
+var modules = bender.amd.require( 'promise' );
+
+describe( 'Promise', function() {
+	it( 'should resolve properly', function() {
+		var Promise = modules.promise;
+
+		var promise = new Promise( function( resolve ) {
+			resolve( 1 );
+		} );
+
+		return promise.then( function( value ) {
+			expect( value ).to.equal( 1 );
+		} );
+	} );
+} );