aboutsummaryrefslogtreecommitdiffstats
path: root/lua/nvim-lsp-installer/ui/state.lua
blob: ff54c657accf102acbb987ec1c9130929daf5ec2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
local M = {}

function M.create_state_container(initial_state, subscriber)
    -- we do deepcopy to make sure instances of state containers doesn't mutate the initial state
    local state = vim.deepcopy(initial_state)
    local has_unsubscribed = false

    return function(mutate_fn)
        mutate_fn(state)
        if not has_unsubscribed then
            subscriber(state)
        end
    end,
        function()
            return state
        end,
        function(val)
            has_unsubscribed = val
        end
end

return M