Skip to content
This repository has been archived by the owner on Apr 11, 2023. It is now read-only.

dualStorage and requireJS : Underscore is missing #125

Open
Simmoniz opened this issue Sep 11, 2014 · 9 comments
Open

dualStorage and requireJS : Underscore is missing #125

Simmoniz opened this issue Sep 11, 2014 · 9 comments
Labels

Comments

@Simmoniz
Copy link

Since dualStorage uses underscore fonctionnalities, would the line #9 should look like this ?

})(this, function(Backbone, _) {

I am getting error "_ is not defined"

(within the amd version -> "backbone.dualstorage.amd.js")

@nilbus
Copy link
Owner

nilbus commented Sep 11, 2014

Yes, I think you're right. I don't use AMD, so could you make the change, and send a pull request if that fixes the problem?

@nilbus nilbus added the Bug label Sep 11, 2014
@nilbus nilbus modified the milestone: 2.0 May 1, 2015
@elmbrent
Copy link

Can we please have an example with Require.JS I cannot for the life of me getting it working.

@nilbus
Copy link
Owner

nilbus commented Aug 25, 2015

I don't use require.js, but I think these people have. @GermanDZ @matthieugayon @elad @dschien @thoaionline

Could one of you please provide an example of how you use Backbone.dualStorage with require.js?

/cc @BananaNeil

@dschien
Copy link

dschien commented Aug 26, 2015

Hi @Simmoniz,

Below some snippets. They are copy pasted from my working code and contain unresolved reference. You will need to clean them up.

Versions:
"dependencies": {
"jquery": "~2.1.0",
"handlebars": "1.3.0",
"requirejs": "~2.1.10",
"requirejs-plugins": "~1.0.2",
"underscore": "~1.5.2"

"glob": "~3.2.8",
"grunt": "~0.4.1",
"grunt-contrib-copy": "~0.4.1",
"grunt-contrib-watch": "~0.5.1",
"grunt-contrib-jshint": "~0.6.0",
"grunt-contrib-handlebars": "~0.5.10",
"grunt-contrib-jasmine": "~0.5.1",
"grunt-handlebars": "0.0.6",
"grunt-contrib-compass": "~0.4.0",
"grunt-bower-task": "~0.2.3",
"bower": "~0.10.0",
"grunt-bower-requirejs": "~0.6.0",
"grunt-template-jasmine-requirejs": "~0.1.4",
"grunt-contrib-uglify": "~0.2.2",
"grunt-contrib-requirejs": "~0.4.1",
"grunt-jsdoc": "~0.4.0",
"grunt-contrib-clean": "~0.5.0",
"grunt-shell": "~0.3.1",
"grunt-bump": "0.0.11",
"grunt-preprocess": "~3.0.1"

My config.js:

require.config({
    catchError: true,

    baseUrl: './',
    paths: {
        backbone: 'js/lib/backbone',
        dualstorage: 'js/lib/backbone.dualstorage.amd',
        underscore: 'js/lib/underscore',
    },
    shim: {
        underscore: {
            exports: '_'
        },
        backbone: {
            deps: [
                'underscore',
                'jquery'
            ],
            exports: 'Backbone'
        },
        dualstorage: {
            deps: ['underscore', 'backbone']
        },
    },
    // for ripple
    waitSeconds: 0
});

My grunt task looks like this:

js: {
        options: {
            name: 'config',
            baseUrl: '<%= dirs.build %>/<%= grunt.config.get("build_dist_folder") %>/',
            mainConfigFile: '<%= dirs.build %>/<%= grunt.config.get("build_dist_folder") %>/config.js',
            out: '<%= dirs.build %>/<%= grunt.config.get("build_dist_folder") %>/optimized.js',
            include: [
                'app/MainApp',
            ]
        }
    },

Example of class using underscore:

define([
    'settings',
    'backbone',
    'underscore'
], function (config, Backbone) {
    var globals = { /* */};      
    _.extend(globals, config);
    return globals;

Hope this helps. Good luck

@nilbus
Copy link
Owner

nilbus commented Aug 26, 2015

Thank you @dschien!

@elmbrent
Copy link

Thankyou @dschien

@elmbrent
Copy link

@nilbus I went offline but none of the models / collections where not being loaded? Does it save the information to local-storage?

@nilbus
Copy link
Owner

nilbus commented Aug 26, 2015

@elmbrent Please open a new issue, so we don't clutter this one with an unrelated conversation.

@dreamalligator
Copy link
Contributor

@elmbrent use --save or --save-dev

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants