* move last_group_node to DirectoryNode * move add BaseNode:as and more doc * revert parameter name changes * revert parameter name changes * add Class * move group methods into DN * tidy group methods * tidy group methods * tidy group methods * tidy group methods * parent is DirectoryNode * tidy expand all * BaseNode -> Node * move watcher to DirectoryNode * last_group_node is DirectoryNode only * simplify create-file * simplify parent * simplify collapse-all * simplify live-filter * style
This commit is contained in:
committed by
GitHub
parent
fb2070db94
commit
8331a24c77
40
lua/nvim-tree/class.lua
Normal file
40
lua/nvim-tree/class.lua
Normal file
@@ -0,0 +1,40 @@
|
||||
---Generic class, useful for inheritence.
|
||||
---@class (exact) Class
|
||||
---@field private __index? table
|
||||
local Class = {}
|
||||
|
||||
---@param o Class?
|
||||
---@return Class
|
||||
function Class:new(o)
|
||||
o = o or {}
|
||||
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
|
||||
return o
|
||||
end
|
||||
|
||||
---Object is an instance of class
|
||||
---This will start with the lowest class and loop over all the superclasses.
|
||||
---@param class table
|
||||
---@return boolean
|
||||
function Class:is(class)
|
||||
local mt = getmetatable(self)
|
||||
while mt do
|
||||
if mt == class then
|
||||
return true
|
||||
end
|
||||
mt = getmetatable(mt)
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
---Return object if it is an instance of class, otherwise nil
|
||||
---@generic T
|
||||
---@param class T
|
||||
---@return `T`|nil
|
||||
function Class:as(class)
|
||||
return self:is(class) and self or nil
|
||||
end
|
||||
|
||||
return Class
|
||||
Reference in New Issue
Block a user