expcore.store module

Adds an easy way to store and watch for updates to a value [[

Dependencies

utils.global
utils.event
expcore.common
utils.token

Functions

Store.is_registered(location) Check for if a location is registered
Store.uid_location() Returns a unique name that can be used for a store
Store.register([location][, synced][, callback]) Registers a new location with an update callback which is triggered when the value updates
Store.get(location[, child][, allow_unregistered=false]) Gets the value stored at a location, this location must be registered
Store.set(location[, child], value[, from_sync]) Sets the value at a location, this location must be registered
Store.clear(location[, child][, from_sync]) Sets the value at a location to nil, this location must be registered
Store.get_children(location) Gets all non nil children at a location, children can be added and removed during runtime this is similar to Store.get but will always return a table even if it is empty

Dependencies

# utils.global
# utils.event
# expcore.common
# utils.token

Functions

# Store.is_registered(location)

Check for if a location is registered

Parameters:
  • location : (string) the location to test for
Returns:
# Store.uid_location()

Returns a unique name that can be used for a store

Returns:
# Store.register([location][, synced][, callback])

Registers a new location with an update callback which is triggered when the value updates

Parameters:
  • location : (string) string a unique that points to the data, string used rather than token to allow migration (optional)
  • synced : (boolean) when true will output changes to a file so it can be synced (optional)
  • callback : (function) when given the callback will be automatically registered to the update of the value (optional)
Returns:
  • (string) the location that is being used
# Store.get(location[, child][, allow_unregistered=false])

Gets the value stored at a location, this location must be registered

Parameters:
  • location : (string) the location to get the data from
  • child : (string) the child location if required (optional)
  • allow_unregistered : (boolean) when true no error is returned if the location is not registered (default: false)
Returns:
  • (any) the data which was stored at the location
# Store.set(location[, child], value[, from_sync])

Sets the value at a location, this location must be registered

Parameters:
  • location : (string) the location to set the data to
  • child : (string) the child location if required (optional)
  • value : (any) the new value to set at the location, value may be reverted if there is a watch callback, cant be nil
  • from_sync : (boolean) set this true to avoid an output to the sync file (optional)
Returns:
  • (boolean) true if it was successful
# Store.clear(location[, child][, from_sync])

Sets the value at a location to nil, this location must be registered

Parameters:
  • location : (string) the location to set the data to
  • child : (string) the child location if required (optional)
  • from_sync : (boolean) set this true to avoid an output to the sync file (optional)
Returns:
  • (boolean) true if it was successful
# Store.get_children(location)

Gets all non nil children at a location, children can be added and removed during runtime this is similar to Store.get but will always return a table even if it is empty

Parameters:
  • location : (string) the location to get the children of
Returns:
  • (table) a table containing all the children names