A minimalistic Key-Value-Observer framework for Lua.
This module allows you to generate a table with a defined label or path that can be used to share data with other modules or code. Other modules can register as watchers to a specific key-value pair within the watchable object table and will be automatically notified when the key-value pair changes.
The goal is to provide a mechanism for sharing state information between separate and (mostly) unrelated code easily and in an independent fashion.
Signature | hs.watchable.new(path, [externalChanges]) -> table |
---|---|
Type | Constructor |
Description | Creates a table that can be watched by other modules for key changes |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/watchable/watchable.lua line 222 |
Signature | hs.watchable.watch(path, [key], callback) -> watchableObject |
---|---|
Type | Constructor |
Description | Creates a watcher that will be invoked when the specified key in the specified path is modified. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/watchable/watchable.lua line 254 |
Signature | hs.watchable:alwaysNotify([notify]) -> watchableObject | currentValue |
---|---|
Type | Method |
Description | Get or set whether this watcher should be notified even when the new value is identical to the current value |
Parameters |
|
Returns |
|
Source | extensions/watchable/watchable.lua line 158 |
Signature | hs.watchable:callback([fn]) -> watchableObject | currentValue |
---|---|
Type | Method |
Description | Change or remove the callback function for the watchableObject. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/watchable/watchable.lua line 112 |
Signature | hs.watchable:change([key], value) -> watchableObject |
---|---|
Type | Method |
Description | Externally change the value of the key-value pair being watched by the watchableObject |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/watchable/watchable.lua line 179 |
Signature | hs.watchable:pause() -> watchableObject |
---|---|
Type | Method |
Description | Temporarily stop notifications about the key-value pair(s) watched by this watchableObject. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/watchable/watchable.lua line 64 |
Signature | hs.watchable:release() -> nil |
---|---|
Type | Method |
Description | Removes the watchableObject so that key-value pairs watched by this object no longer generate notifications. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/watchable/watchable.lua line 90 |
Signature | hs.watchable:resume() -> watchableObject |
---|---|
Type | Method |
Description | Resume notifications about the key-value pair(s) watched by this watchableObject which were previously paused. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/watchable/watchable.lua line 77 |
Signature | hs.watchable:value([key]) -> currentValue |
---|---|
Type | Method |
Description | Get the current value for the key-value pair being watched by the watchableObject |
Parameters |
|
Returns |
|
Source | extensions/watchable/watchable.lua line 139 |