Mercurial > prosody-hg
comparison util/pubsub.lua @ 8500:9bf00d0734c8
util.pubsub: For clarity, split config tables from their metatables
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Thu, 01 Feb 2018 15:09:04 +0000 |
| parents | f1923a79c93d |
| children | 8d9e2c2095dd |
comparison
equal
deleted
inserted
replaced
| 8499:549361c68f5a | 8500:9bf00d0734c8 |
|---|---|
| 2 local cache = require "util.cache"; | 2 local cache = require "util.cache"; |
| 3 | 3 |
| 4 local service = {}; | 4 local service = {}; |
| 5 local service_mt = { __index = service }; | 5 local service_mt = { __index = service }; |
| 6 | 6 |
| 7 local default_config = { __index = { | 7 local default_config = { |
| 8 itemstore = function (config, _) return cache.new(config["max_items"]) end; | 8 itemstore = function (config, _) return cache.new(config["max_items"]) end; |
| 9 broadcaster = function () end; | 9 broadcaster = function () end; |
| 10 get_affiliation = function () end; | 10 get_affiliation = function () end; |
| 11 capabilities = {}; | 11 capabilities = {}; |
| 12 } }; | 12 }; |
| 13 local default_node_config = { __index = { | 13 local default_config_mt = { __index = default_config }; |
| 14 | |
| 15 local default_node_config = { | |
| 14 ["persist_items"] = false; | 16 ["persist_items"] = false; |
| 15 ["max_items"] = 20; | 17 ["max_items"] = 20; |
| 16 } }; | 18 }; |
| 19 local default_node_config_mt = { __index = default_node_config }; | |
| 17 | 20 |
| 18 local function new(config) | 21 local function new(config) |
| 19 config = config or {}; | 22 config = config or {}; |
| 20 return setmetatable({ | 23 return setmetatable({ |
| 21 config = setmetatable(config, default_config); | 24 config = setmetatable(config, default_config_mt); |
| 22 node_defaults = setmetatable(config.node_defaults or {}, default_node_config); | 25 node_defaults = setmetatable(config.node_defaults or {}, default_node_config_mt); |
| 23 affiliations = {}; | 26 affiliations = {}; |
| 24 subscriptions = {}; | 27 subscriptions = {}; |
| 25 nodes = {}; | 28 nodes = {}; |
| 26 data = {}; | 29 data = {}; |
| 27 events = events.new(); | 30 events = events.new(); |
