The Gallery is deprecated. No new Gallery components may be submitted, and modifying existing components is disabled. For more information please read the Gallery Deprecation blog post. This is a static snapshot of the Gallery for archive purposes.
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.
<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>');
});
});
});
All code on this site is licensed under the BSD License unless stated otherwise.