Fix AMD module loading
Phoscur opened this issue · 10 comments
I'm sorry that I can't give you any more specific information, but my build broke updating from version 0.0.9* to 0.0.13.
The uglyfied build gives this error:
Uncaught Error: Mismatched anonymous define() module: function (){"use strict";function e(e){return function(t){i&&i(e+": "+t)}}function t(e){return function(){if("function"==typeof e){var t=[].slice.call(arguments);e.apply(this,t)}}}var n=null,r={},i=null,o=function(e,t,n){this.address=e;this.name=t;this.connected=!1;this.serviceUUIDs=n;this.services={}};o.prototype.hasService=function(e){var t=!1;this.serviceUUIDs.some(function(n){if(n===e){t=!0;return!0}});return t};o.prototype.connect=function(r,i){n.connect(this,t(r),t(i),e("connect error"))};o.prototype.disconnect=function(){n.disconnect(this,e("disconnect error"))};var a=function(e,t,n){this.uuid=e;this.handle=t;this.primary=n;this.characteristics={}},s=function(e,t,n){this.uuid=e;this.handle=t;this.properties=n;this.descriptors={}};s.prototype.read=function(r){n.readCharacteristic(this,t(r),e("read characteristic error"))};s.prototype.write=function(r,i){n.writeCharacteristic(this,r,t(i),e("write characteristic error"))};s.prototype.enableNotify=function(r,i){n.enableNotify(this,t(r),t(i),e("enable notify error"))};s.prototype.disableNotify=function(r){n.disableNotify(this,t(r),e("disable notify error"))};var l=function(e,t){this.uuid=e;this.handle=t};l.prototype.read=function(r){n.readDescriptor(this,t(r),e("read descriptor error"))};l.prototype.write=function(r,i){n.writeDescriptor(this,r,t(i),e("write descriptor error"))};return{raiseError:function(e){i&&i(e)},addAdapter:function(e,t){r[e]=t;n=t},init:function(o,a,s){i=a;s&&(n=r[s]);n?n.init(t(o),e("init error")):e("init error")("adapter not found")},startScan:function(t){n.stop(e("stop scan error"));var r={};n.scan(function(e){if(!r[e.address]){r[e.address]=e;t&&t(e)}}.bind(this),e("scan error"))},stopScan:function(){n.stop(e("stop scan error"))},asyncWait:function(e,t){var n=0,r=!1;this.addCallback=function(t){n++;r=!0;return function(){t&&t.apply(null,arguments);0==--n&&e&&e()}};this.error=function(){t&&t.apply(null,arguments);0==--n&&e&&e()};this.finish=function(){!r&&e&&e()}},Device:o,Service:a,Characteristic:s,Descriptor:l}}
http://requirejs.org/docs/errors.html#mismatch
(The development build error does not reveal any more information. And yes I hate RequireJS for being so verbose and yet not helpful at all.)
I was not able to track down your breaking changes.
*I'm still using the 0.0.9, I fixed myself - reverting to 0.0.10 solves the issue
Thanks for the information.
Which adapter are you using and does the error occur immediately or when you run a specific function?
I'm using the evothings adapter and it doesn't run at all, it's a build/loading error.
Thanks, I'll take a look.
This issue is due to me renaming the core bleat file to bleat.core and omitting to update the umd loaders for AMD. Sorry about that.
I'm putting together a requirejs exampe and would be interested in how you are loading evothings/cordova/bleat in your code.
Are you 'require'ing cordova or have a reference to the cordova library in your html? I've found race conditions with the latter approach using requirejs.
ble beacon service file header:
define(['./services', 'Bacon', 'bleat', 'bleat-evothings'], function (services, Bacon, bleat) {
'use strict';
/*global cordova:false, TextEncoder, TextDecoder*/
return services.service('bleContextScanner', ['$rootScope', function ($rootScope) {
// ommitted angular module structure: iaApp loads core, core loads services.
main.js
(function () {
"use strict";
require(['angular', 'ionic-angular', 'ngCordova-nfc', 'core/index', 'domready!'], function (angular) {
angular.bootstrap(document, ['iaApp']);
});
})();
I notice, in contrast to the nfc cordova plugin, I'm loading the Bluetooth dependencies very late.
Please elaborate on your concurrency issues.
Thanks for posting that.
The amd example I just pushed is flakey and I see timeouts waiting for the deviceready event.
I was after a clean example of requirejs + evothings and it was the best I could get working :/
I think, I don't have your problems running after domready and without shimming cordova?
Not sure though? How can I test this?
Try running the requirejs example if you don't mind. Are you ios or android?
Sorry, this took so long. I hope I can spare time to help you flesh out the RequireJS example.
I'm developing for Android, but I use mainly desktop browsers for development.
The current version (0.15) still has issues using RequireJS.
Running the example, I get "init error: adapter not found" and the evothings file doesn't get loaded at all.
So this is as expected. I managed to update my project to use bleat.core instead of bleat(.full). I guess the last problem I had using 0.15 was another concurrency thing with the double definition of bleat.evothings.