Permalink
Browse files

refactor to use Crockford's json2 as an AMD module and remove git sub…

…module
  • Loading branch information...
1 parent 7dbc5ab commit b691ef5d666ae756a2da52ccb72e8fd580693882 John Hann committed Jun 6, 2012
Showing with 546 additions and 36 deletions.
  1. +0 −3 .gitmodules
  2. +5 −7 README.md
  3. +5 −3 json.js
  4. +31 −6 lib/_json.js
  5. +0 −1 support/json
  6. +489 −0 support/json2.js
  7. +16 −16 test/json.html
View
@@ -1,3 +0,0 @@
-[submodule "support/json"]
- path = support/json
- url = https://github.com/douglascrockford/JSON-js.git
View
@@ -14,13 +14,6 @@ poly.js is unique amongst ES5-ish shims because it:
* is configurable to suit your code
* can be minified using a has-aware optimizer
-After cloning poly, be sure to update the submodules if you want to include
-JSON support. Run the following from the root of the poly directory:
-
-```
-git submodule init && git submodule update
-```
-
Features
----
@@ -202,3 +195,8 @@ if (typeof "".trim != 'function') {
curl({ preloads: preloads });
```
+JSON2
+===
+
+JSON support via Douglas Crockford's JSON2 lib at:
+https://github.com/douglascrockford/JSON-js.git
View
@@ -8,7 +8,9 @@
* Licensed under the MIT License at:
* http://www.opensource.org/licenses/mit-license.php
*
- * TODO: document that JSON module is always downloaded unless dev explicitly
- * mentions it in build instructions
+ * TODO: document that JSON module is always downloaded st run-time unless
+ * dev explicitly mentions it in build instructions
*/
-define(['./lib/_async!./lib/_json'], function () {});
+define(['./lib/_async!./lib/_json'], function (JSON) {
+ return JSON;
+});
View
@@ -11,18 +11,43 @@
(function (global) {
define(['require', 'curl/_privileged'], function (require, priv) {
- var Promise, promise;
-
- Promise = priv['Promise'];
- promise = new Promise();
+ var cbs, ebs, promise;
function has (feature) {
return global.JSON;
}
if (!has('json')) {
- require(['js!../support/json/json2.js!exports=JSON'], promise.resolve, promise.reject);
- return { promise: promise };
+
+ cbs = [];
+ ebs = [];
+
+ promise = {
+ then: function (cb, eb) {
+ if (cb) cbs.push(cb);
+ if (eb) ebs.push(eb);
+ }
+ };
+
+ function callback (list, val) {
+ promise.then = list == cbs
+ ? function (cb, eb) { cb(val); }
+ : function (cb, eb) { eb(val); }
+ for (var i = 0; i < list.length; i++) list[i](val);
+ }
+
+ function resolve (val) {
+ callback(cbs, val);
+ }
+
+ function reject (ex) {
+ callback(ebs, ex);
+ }
+
+ require(['../support/json2'], resolve, reject);
+
+ return promise;
+
}
});
Submodule json deleted from fc535e
Oops, something went wrong.

0 comments on commit b691ef5

Please sign in to comment.