JooseX.Attribute.Trigger - call a function after attribute has been changed via setter call
Class('Some.Class', {
has : {
someAttribuute : {
init : 'foo',
trigger : function (newValue, oldValue) {
this.triggerCalled = true
}
}
}
})
var instance = new Some.Class()
instance.triggerCalled == false //trigger wasn't called yet
instance.setSomeAttibute('bar')
instance.triggerCalled == true //trigger was called
JooseX.Attribute.Trigger
is a role, which triggers a function call, after an attribute was changed via setter call.
It is called as a method (in the scope of the instance), and receives the new value as 1st argument, and old value as 2nd.
Trigger is also called when an attribute's value is passed to the constructor.
Note, that trigger will not be called for the value of attribute's init
option, as it only translates the value to the prototype of the class
Nickolay Platonov nplatonov@cpan.org
Copyright (c) 2009, Nickolay Platonov
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.