Skip to content
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

define() overwriting differently named modules - User Error #1094

Closed
bryanerayner opened this issue Apr 21, 2014 · 1 comment
Closed

define() overwriting differently named modules - User Error #1094

bryanerayner opened this issue Apr 21, 2014 · 1 comment

Comments

@bryanerayner
Copy link

Solved

Edit: The issue had to do with John Resig's Class module, not RequireJS. That's what I was hoping for anyway.

I'm not sure whether or not this is user error, or an error with RequireJS, but it sure is confusing. I'm not sure how the bug could be recreated, but I can give you the source if necessary. If it's not a bug and is user error, it would be nice to have an answer.

All of these files are in the same directory. I define a base class in one, some derivatives in two others, and then an Angular JS module which packages them together in an Angular factory for use in controllers. This file containing the bug, or revealing a bug in RequireJS, is design-tools.js.

Somehow, design-tools is overwriting the derivative classes (tool-selection and tool-creation). When I define the dependencies in the order
['dep1'... 'depN', 'tool-selection', 'tool-creation']

tool-creation gets loaded twice (in the factory function, arguments[5] is tool-selection, and arguments[6] is also tool-selection)

If I change the order to
['dep1'... 'depN', 'tool-creation', 'tool-selection']
tool-selection gets loaded twice (both arguments[5] and arguments[6] are tool-selection).

I don't want to assume there are bugs with RequireJS, but if this is user error on my part, I must have done a really good job at breaking things :)

Can anyone help determine the cause of this error? I'm just going to list the define() calls here from the different files in the same folder, and hopefully someone can resolve this. I'm resorting to moving tool-creation and tool-selection into different sub-directories in an attempt to resolve the issue.

index.js (loaded first)

define([
    './design-tools'
], function () {});

design-tools.js

var needs = ['angular', './module', 'lodash', 'jrClass', './tool'];

needs = needs.concat([
    './tool-creation',
    './tool-selection'
]);

define(needs, function(ng, module, _, Class, Tool){

// Do stuff...

// Slice tool-creation and tool-selection off the end of arguments[] and configure them

}

module.js

define(['angular', 'keystateService', 'mouseEventsService', '../../services/index'], function (ng, keystateService, mouseEventsService) {
    'use strict';
    return ng.module('app.design.controllers.tools',
        [
            'keystateService',
            'mouseEventsService',
            'app.design.services'
        ]);
});

tool.js

define(['jrClass', 'lodash'], function (Class, _) {
var Tool;
Tool = Class.extend({ /* Some things */});
return Tool;
});

tool-creation.js

define(['angular', 'lodash', './tool', '../../services/classes/EventMap'], function (ng, _, Tool, EventMap) {
// Define the CreationTool class, return it

    var CreationTool;
    CreationTool = Tool.extend({
       //Stuff
     });

    return CreationTool;
});

tool-selection.js

define(['angular', 'lodash', './tool', '../../services/classes/EventMap'], function (ng, _, Tool, EventMap) {
// Define the SelectionTool class, return it

    var SelectionTool;
    SelectionTool = Tool.extend({
       //Stuff
     });

    return SelectionTool;
});

Hopefully this can get resolved.

@bryanerayner bryanerayner changed the title define() overwriting differently named modules - Error define() overwriting differently named modules - User Error Apr 21, 2014
@jrburke
Copy link
Member

jrburke commented May 1, 2014

Closing as description said it is solved.

@jrburke jrburke closed this as completed May 1, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants