• 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.

    Base Revive (gallery-base-revive) on cdn

    Last Updated: 11/9/11
    + 0 -

    Lee

    YUI Contributor

    See 3 more by this user.

    Created: 11/9/11
    Last CDN Push: 11/17/11
    Build Tag: gallery-2011.11.17-14-56
    Project: YUI 3
    License: YUI BSD
    YUI Version: 3.4.1
    Free for use.

    BaseRevive provides a non-destructive destroy by simply marking an object as destroyed but prevents events from being detached and any of the destructors from executing. Objects can be revived (undestroyed) by calling the revive() method provided by the extension.

    Designed primarily as an extension for Y.Model, it allows models to maintain a 'dirty' state while still being able to fire events and participate in relationships (using the gallery-model-relate extension) until the model is deleted from the persistence layer via the 'delete' sync method (model.destroy({'delete': true})); Once the model is deleted from the persistence layer, calling the destroyFinal() method will prevent the model from being revived.

    Note: In order to be able to destroy and revive objects multiple times, the destroy event is modified to no longer be a 'fireOnce' event. If you are listening to the destroy event via on or after, the event handler may be executed more than once. If your object does cleanup on the destroy event, it is recommended you use a once or onceAfter event or move your cleanup logic into a destructor if possible.

    • Tags:
    • base
    • destroy
    • revive
    • model
    • gallery-model-relate
    • bwg
    • undestroy
    • Download
    • Docs
    • Homepage
    • Bugs
    • Source
    • Example
    • Forum
    • History

    Example of using BaseRevive with Y.Model

    Code Sample

    <script src="http://yui.yahooapis.com/3.4.1/build/yui/yui-min.js"></script>
    YUI({
        //Last Gallery Build of this module
        gallery: 'gallery-2011.11.17-14-56'
    }).use('model', 'gallery-base-revive', function(Y) {
        var SampleModel = Y.Base.create('sampleModel', Y.Model, [Y.BaseRevive], {}, {
            ATTRS: {
                firstName: {},
                lastName: {}
            }
        });
     
        var m = new SampleModel({
            firstName: 'Joe',
            lastName: 'Foo'
        });
     
        m.after('change', function(e) {
            Y.each(e.newVal, function(val, atrr) {
                Y.log(attr + ' changed to ' + val);
            });
        });
     
        m.after('revive', function(e) {
          Y.log('I am ALIVE!!!');
        });
     
        m.destroy();
     
        m.get('destroyed'); // true
     
        m.set('lastName', 'Zombie'); // logs 'lastName changed to Zombie' in console
     
        m.revive(); // logs 'I am ALIVE!!!' in console
     
        m.get('destroyed'); // false
     
        m.destroyFinal(); // destroys the object and executes full destructor logic.
     
        m.get('destroyed'); // true
     
        m.revive(); // nothing happens since we called destroyFinal
     
        m.get('destroyed'); // true
    });

    © 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