|
1 | 1 | local collect = require('github-theme.lib.collect')
|
| 2 | +local M = {} |
2 | 3 |
|
3 |
| -local store = { |
4 |
| - palettes = {}, |
5 |
| - specs = {}, |
6 |
| - groups = {}, |
7 |
| - has_override = false, |
8 |
| -} |
9 |
| - |
10 |
| -local function reset() |
11 |
| - store.palettes = {} |
12 |
| - store.specs = {} |
13 |
| - store.groups = {} |
14 |
| - store.has_override = false |
| 4 | +function M.reset() |
| 5 | + getmetatable(M).__index = |
| 6 | + { palettes = {}, specs = {}, groups = {}, has_override = false } |
| 7 | + return M |
15 | 8 | end
|
16 | 9 |
|
17 |
| -local function hash() |
18 |
| - local hash = require('github-theme.lib.hash')(store) |
19 |
| - return hash and hash or 0 |
| 10 | +function M.hash() |
| 11 | + return require('github-theme.lib.hash')(getmetatable(M).__index) or 0 |
20 | 12 | end
|
21 | 13 |
|
22 | 14 | local function check_link(tbl)
|
23 |
| - for _, style in pairs(tbl) do |
24 |
| - for _, opts in pairs(style) do |
| 15 | + for _, theme in pairs(tbl) do |
| 16 | + for _, opts in pairs(theme) do |
25 | 17 | opts.link = opts.link or ''
|
26 | 18 | end
|
27 | 19 | end
|
28 | 20 | end
|
29 | 21 |
|
30 |
| -return setmetatable({ reset = reset, hash = hash }, { |
31 |
| - __index = function(_, value) |
32 |
| - if store[value] then |
33 |
| - return store[value] |
34 |
| - end |
35 |
| - end, |
36 |
| - |
37 |
| - __newindex = function(_, key, value) |
38 |
| - if store[key] then |
39 |
| - if key == 'groups' then |
40 |
| - check_link(value or {}) |
| 22 | +setmetatable(M, { |
| 23 | + __newindex = function(self, k, v) |
| 24 | + local store = getmetatable(self).__index |
| 25 | + if type(store[k]) == 'table' then |
| 26 | + if not v then |
| 27 | + store[k] = {} |
| 28 | + return |
| 29 | + end |
| 30 | + if k == 'groups' then |
| 31 | + check_link(v) |
41 | 32 | end
|
42 |
| - store[key] = collect.deep_extend(store[key], value or {}) |
| 33 | + store[k] = collect.deep_extend(store[k], v) |
43 | 34 | store.has_override = true
|
44 | 35 | end
|
45 | 36 | end,
|
46 | 37 | })
|
| 38 | + |
| 39 | +return M.reset() |
0 commit comments