nilbus / Backbone.dualStorage

A dual (localStorage and REST) sync adapter for Backbone.js
Other
798 stars 108 forks source link

dualStorage and requireJS : Underscore is missing #125

Open Simmoniz opened 10 years ago

Simmoniz commented 10 years ago

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 commented 10 years ago

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?

elmbrent commented 9 years ago

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

nilbus commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

Thank you @dschien!

elmbrent commented 9 years ago

Thankyou @dschien

elmbrent commented 9 years ago

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

nilbus commented 9 years ago

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

dreamalligator commented 8 years ago

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