Class LrObservableTable
addObserver
method, and discontinue interest via the removeObserver
method. You can create an observable table by calling LrBinding.makePropertyTable()
. Some other API functions may create observable tables for you.
Summary
Functions
- observableTable:addObserver( condition, table, func )
-
Registers an observer for a property table. The observer is notified when a specified value in the observed table changes, and responds by invoking a handler function.
There are two forms of this function: One simply registers a callback function; the other associates that callback function with a table (any arbitrary table) so that the observer can later be removed via
removeObserver
.First supported in version 1.3 of the Lightroom SDK.
For example (simple form):
local propertyTable = LrBinding.makePropertyTable( functionContext )
local function colorSpaceChanged( propertyTable, key, value )
-- do something with new value
end
propertyTable:addObserver( 'colorSpace', colorSpaceChanged )For example (longer form, with removeObserver):
local propertyTable = LrBinding.makePropertyTable( functionContext )
local myTable = {}
local function colorSpaceChanged( myTable, propertyTable, key, value )
-- do something with new value
-- note that myTable becomes first parameter in this usage
end
propertyTable:addObserver( 'colorSpace', myTable, colorSpaceChanged )
-- (later ...)
propertyTable:removeObserver( 'colorSpace', myTable )Parameters
- 1. condition
- (string) The key name of the property to observe.
- 2. table
- (optional, table) The table to associate with this observation. This same table can be used in a subsequent call to
removeObserver
to discontinue listening for observations. This parameter may also be omitted, in which case thefunc
parameter should move up to the first position. - 3. func
- (function) The handler function to call when the observed property changes. The handler takes these arguments:
- propertyTable: This property table.
- key: The key whose change triggered the notification.
- newValue: The new value of the key.
key
argument to distinguish which key changed. If you do, you must pass the function to a separate registration call for each key.
- observableTable:pairs()
-
Iterate the contents of this table. Like Lua's built-in
pairs
function, except that it actually works on the observable table.First supported in version 1.3 of the Lightroom SDK.
Return value
(function) an iterator that can be used in afor
loop - observableTable:removeObserver( condition, table )
-
Unregisters an existing observer on a property table. The observer is no longer notified when the specified value in the observed table changes.
Important: This form can only be used if a table was provided to the
addObserver
function. (See second example code underaddObserver
.)First supported in version 1.3 of the Lightroom SDK.
Parameters
- 1. condition
- (string) The key name of the property to stop observing.
- 2. table
- (table) The table that was associated with this observation when
addObserver
was called.