From e9fee73b62132d7fd5554da6a8237c0adf04d75a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 28 Sep 2022 19:09:44 +0800 Subject: test delay refresh node cache #1595 --- script/fs-utility.lua | 18 +++++++++++------- script/timer.lua | 6 ++++++ script/vm/node.lua | 15 ++++++++++++++- 3 files changed, 31 insertions(+), 8 deletions(-) (limited to 'script') diff --git a/script/fs-utility.lua b/script/fs-utility.lua index b57c15bb..5ac4139a 100644 --- a/script/fs-utility.lua +++ b/script/fs-utility.lua @@ -96,11 +96,15 @@ local function split(str, sep) return t end +---@class dummyfs +---@operator div(string|fs.path|dummyfs): dummyfs +---@field files table local dfs = {} dfs.__index = dfs dfs.type = 'dummy' dfs.path = '' +---@return dummyfs function m.dummyFS(t) return setmetatable({ files = t or {}, @@ -257,7 +261,7 @@ function dfs:saveFile(path, text) return true end ----@param path string|fs.path +---@param path string|fs.path|dummyfs ---@param option table ---@return fs.path? local function fsAbsolute(path, option) @@ -449,7 +453,7 @@ local function fileRemove(path, option) end end ----@param source fs.path? +---@param source fs.path|dummyfs? ---@param target fs.path? ---@param option table local function fileCopy(source, target, option) @@ -485,7 +489,7 @@ local function fileCopy(source, target, option) end end ----@param source fs.path? +---@param source fs.path|dummyfs? ---@param target fs.path? ---@param option table local function fileSync(source, target, option) @@ -594,8 +598,8 @@ function m.fileRemove(path, option) end --- 复制文件(夹) ----@param source string|fs.path ----@param target string|fs.path +---@param source string|fs.path|dummyfs +---@param target string|fs.path|dummyfs ---@return table function m.fileCopy(source, target, option) option = buildOption(option) @@ -608,8 +612,8 @@ function m.fileCopy(source, target, option) end --- 同步文件(夹) ----@param source string|fs.path ----@param target string|fs.path +---@param source string|fs.path|dummyfs +---@param target string|fs.path|dummyfs ---@return table function m.fileSync(source, target, option) option = buildOption(option) diff --git a/script/timer.lua b/script/timer.lua index a14cdd27..0a905b1c 100644 --- a/script/timer.lua +++ b/script/timer.lua @@ -97,7 +97,13 @@ local function onTick() freeQueue[#freeQueue + 1] = q end +---@class timer.manager local m = {} + +---@class timer +---@field _onTimer? fun(self: timer) +---@field _timeoutFrame integer +---@field _timeout integer local mt = {} mt.__index = mt mt.type = 'timer' diff --git a/script/vm/node.lua b/script/vm/node.lua index 49207b13..9b10fa9d 100644 --- a/script/vm/node.lua +++ b/script/vm/node.lua @@ -3,6 +3,7 @@ local files = require 'files' local vm = require 'vm.vm' local ws = require 'workspace.workspace' local guide = require 'parser.guide' +local timer = require 'timer' ---@type table vm.nodeCache = {} @@ -475,10 +476,22 @@ function vm.createNode(a, b) return node end +---@type timer? +local delayTimer files.watch(function (ev, uri) if ev == 'version' then if ws.isReady(uri) then - vm.clearNodeCache() + if PREVIEW then + if delayTimer then + delayTimer:restart() + end + delayTimer = timer.wait(1, function () + delayTimer = nil + vm.clearNodeCache() + end) + else + vm.clearNodeCache() + end end end end) -- cgit v1.2.3