• Register
  • Log In
  • Home
  • Quick Start
    • Configurator
    • Download YUI 3
  • Documentation
    • User Guides
    • Examples
    • API Docs
    • Environments
    • Tutorials
  • Community
    • Gallery
    • Blog
    • Forums
    • YUI Theater
    • Calendar
  • Contribute
    • YUI on GitHub »
    • File a Ticket
    • View Tickets
    • Dashboard
  • Other Projects
    • Shifter »
    • Yogi »
    • YUI 2
    • YUI Doc »
    • YUI Test
    • YUI Website
    • YUI Compressor »
    • YUI Builder »
    • YUI PHP Loader
    • Grid Builder »
    • Skin Builder »
  • YUI
  • >
  • Community
  • >
  • Gallery

Gallery

Modules

  • Home
  • Featured
  • Popular
  • New
  • All

Documentation

  • Yogi Documentation
  • Shifter Documentation
  • Developer Guide
  • Module Setup

Tag Cloud

Context Navigation

    YUI Library is not responsible for bugs or support with this module. It is available as a free service. For support please contact the module owner with the provided links.

    Multiple Model Sync (gallery-model-sync-multi) on cdn

    Last Updated: 10/12/12
    + 0 -

    Steven Olmsted

    YUI Contributor

    See 42 more by this user.

    Created: 10/5/12
    Last CDN Push: 10/10/12
    Build Tag: gallery-2012.10.10-19-59
    Project: YUI 3
    License: YUI BSD
    YUI Version: 3.7.2
    Free for use.

    This is a class extension for Y.Model allowing multiple model sync implementations to be used by a single model. When a class is created extending Y.Model, this class extension must come after all other class extensions which implement sync. Model classes using this extension should have a static SYNCS property. The SYNCS property will be an object of key/value pairs. There should be a value for each other sync implementation extension. The keys can be any name you want to give that implementation. When calling the sync methods such as load or save, the options argument object should be given a sync property which matches the name of one of the SYNCS to use.

    Note that different sync extensions can conflict in other ways, for example Y.ModelSync.Local and Y.ModelSync.REST both use a 'root' property in different ways. This extension only deals with the sync method and does nothing about these other potential conflicts.

    • Tags:
    • multi
    • multiple
    • solmsted
    • sync
    • model
    • Download
    • Docs
    • Homepage
    • Bugs
    • Source
    • Example
    • Forum
    • History

    Code Sample

    <script src="http://yui.yahooapis.com/3.7.2/build/yui/yui-min.js"></script>
    // Defining a custom Model object within a custom module.
    YUI.add('my-model', function (Y, moduleName) {
        Y.MyModel = Y.Base.create(moduleName, Y.Model, [
            Y.ModelSync.Local,
            Y.ModelSync.YQL,
            Y.ModelSync.Multi // This comes after the other sync extensions.
        ], {
            parse : function (results) {
                return results && results.entry && results.entry.length && results.entry[0];
            },
            // This query will select the most recent edits to Wikipedia.
            query: "select * from atom where url='http://en.wikipedia.org/w/index.php?title=Special:RecentChanges&feed=atom'",
            root: moduleName
        }, {
            SYNCS: { // The SYNCS property gives each sync extension a unique name.
                local: Y.ModelSync.Local,
                yql: Y.ModelSync.YQL
            }
        });
    }, '', {
        requires: [
            'gallery-model-sync-local',
            'gallery-model-sync-multi',
            'gallery-model-sync-yql',
            'model'
        ]
    });
     
    // The application starts here.
    YUI({
        //Last Gallery Build of this module
        gallery: 'gallery-2012.10.10-19-59'
    }).use('my-model', 'node', function (Y) {
        // Create an instance of the custom model.
        var myModel = new Y.MyModel();
     
        myModel.load({
            sync: 'yql' // Specify which sync layer is used for load.
        }, function (error) {
            if (error) {
                Y.log(error, 'error');
                return;
            }
     
            myModel.save({
                sync: 'local' // Specify which sync layer is used for save.
            }, function (error) {
                if (error) {
                    Y.log(error, 'error');
                    return;
                }
     
                // Display the content from localStorage to prove it worked.
                // It should show a json string containing data about the most recent edit to Wikipedia.
                Y.one('body').append('<pre>' + localStorage.getItem('my-model') + '</pre>');
            });
        });
    });

    © 2006-2013 Yahoo! Inc. All rights reserved.
    All code on this site is licensed under the BSD License unless stated otherwise.
    About This Site · Security Contact Info