Can we add AMD support?

Aug 23, 2012 at 6:00 PM

I am using an AMD loader and would like to load datajs as a module.

Aug 31, 2012 at 6:10 PM

Hi Arthur,

    This is something we would consider, thanks for the bringing this up. In the meantime you should be able to branch the code and make datajs use the define function if available.  For example, if you modify the datajs.js file in the source code and change it to this, and then rebuild: 

// Copyright (c) Microsoft.  All rights reserved.
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
// files (the "Software"), to deal  in the Software without restriction, including without limitation the rights  to use, copy,
// modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// WARRANTIES OF MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

// datajs.js

(function (window, undefined) {
    
    var datajs = window.datajs || {};
    var odatajs = window.datajs || {};

    // AMD support
    if (typeof define === 'function' && define.amd) {        
        define('datajs', datajs);
        define('odata', odata);
    } else {
        window.datajs = datajs;
        window.odata = odata; 
    }
    
    // INCLUDE: odata-utils.js
    // INCLUDE: odata-net.js
    // INCLUDE: odata-handler.js
    // INCLUDE: odata-xml.js
    // INCLUDE: odata-atom.js
    // INCLUDE: odata-metadata.js
    // INCLUDE: odata-json.js
    // INCLUDE: odata-batch.js
    // INCLUDE: odata.js

    // INCLUDE: store-dom.js
    // INCLUDE: store-indexeddb.js
    // INCLUDE: store-memory.js
    // INCLUDE: store.js

    // INCLUDE: deferred.js
    // INCLUDE: cache-source.js
    // INCLUDE: cache.js

})(this);

You should be able to use the datajs and odata variables as AMD modules instead of globals if the define function is available..

Regards,

Alex Trigo.

Aug 31, 2012 at 6:30 PM

Thanks.

From: ATrigo [email removed]
Sent: Friday, August 31, 2012 11:11 AM
To: Arthur Greef
Subject: Re: Can we add AMD support? [datajs:392839]

From: ATrigo

Hi Arthur,

This is something we would consider, thanks for the bringing this up. In the meantime you should be able to branch the code and make datajs use the define function if available. For example, if you modify the datajs.js file in the source code and change it to this, and then rebuild:

// Copyright (c) Microsoft.  All rights reserved.
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
// files (the "Software"), to deal  in the Software without restriction, including without limitation the rights  to use, copy,
// modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// WARRANTIES OF MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
// datajs.js
 
(function (window, undefined) {
    
    var datajs = window.datajs || {};
    var odatajs = window.datajs || {};
 
    // AMD support
    if (typeof define === 'function' && define.amd) {        
        define('datajs', datajs);
        define('odata', odata);
    } else {
        window.datajs = datajs;
        window.odata = odata; 
    }
    
    // INCLUDE: odata-utils.js
    // INCLUDE: odata-net.js
    // INCLUDE: odata-handler.js
    // INCLUDE: odata-xml.js
    // INCLUDE: odata-atom.js
    // INCLUDE: odata-metadata.js
    // INCLUDE: odata-json.js
    // INCLUDE: odata-batch.js
    // INCLUDE: odata.js
 
    // INCLUDE: store-dom.js
    // INCLUDE: store-indexeddb.js
    // INCLUDE: store-memory.js
    // INCLUDE: store.js
 
    // INCLUDE: deferred.js
    // INCLUDE: cache-source.js
    // INCLUDE: cache.js
 
})(this);
 

You should be able to use the datajs and odata variables as AMD modules instead of globals if the define function is available..

Regards,

Alex Trigo.