import{_ as n,o as e,c as s,d as a}from"./app-EhCe7g9m.js";const t={},o=a(`

func debounce()

Description: 防抖函数

Source code
def debounce(wait):
    """
    防抖函数
    """

    def decorator(func):

        def wrapper(*args, **kwargs):
            nonlocal last_call_time
            current_time = time.time()
            if current_time - last_call_time > wait:
                last_call_time = current_time
                return func(*args, **kwargs)
        last_call_time = None
        return wrapper
    return decorator

func on_file_system_event(directories: tuple[str] = True, recursive: bool = None) -> Callable[[CALLBACK_FUNC], CALLBACK_FUNC]

Description: 注册文件系统变化监听器

Return: 装饰器,装饰一个函数在接收到数据后执行

Arguments:

Source code
def on_file_system_event(directories: tuple[str], recursive: bool=True, event_filter: FILTER_FUNC=None) -> Callable[[CALLBACK_FUNC], CALLBACK_FUNC]:
    """
    注册文件系统变化监听器
    Args:
        directories: 监听目录们
        recursive: 是否递归监听子目录
        event_filter: 事件过滤器, 返回True则执行回调函数
    Returns:
        装饰器,装饰一个函数在接收到数据后执行
    """

    def decorator(func: CALLBACK_FUNC) -> CALLBACK_FUNC:

        def wrapper(event: FileSystemEvent):
            if event_filter is not None and (not event_filter(event)):
                return
            func(event)
        code_modified_handler = CodeModifiedHandler()
        code_modified_handler.on_modified = wrapper
        for directory in directories:
            observer.schedule(code_modified_handler, directory, recursive=recursive)
        return func
    return decorator

class CodeModifiedHandler(FileSystemEventHandler)

@debounce(1)

method on_modified(self, event)

Source code
@debounce(1)
def on_modified(self, event):
    raise NotImplementedError('on_modified must be implemented')

method on_created(self, event)

Source code
def on_created(self, event):
    self.on_modified(event)

method on_deleted(self, event)

Source code
def on_deleted(self, event):
    self.on_modified(event)

method on_moved(self, event)

Source code
def on_moved(self, event):
    self.on_modified(event)

method on_any_event(self, event)

Source code
def on_any_event(self, event):
    self.on_modified(event)

var CALLBACK_FUNC = Callable[[FileSystemEvent], None]

var FILTER_FUNC = Callable[[FileSystemEvent], bool]

`,25),l=[o];function c(i,p){return e(),s("div",null,l)}const r=n(t,[["render",c],["__file","observer.html.vue"]]),u=JSON.parse('{"path":"/en/api/dev/observer.html","title":"liteyuki.dev.observer","lang":"en-US","frontmatter":{"title":"liteyuki.dev.observer","description":"func debounce() Description: 防抖函数 Source code func on_file_system_event(directories: tuple[str] = True, recursive: bool = None) -> Callable[[CALLBACK_FUNC], CALLBACK_FUNC] Descr...","head":[["link",{"rel":"alternate","hreflang":"zh-cn","href":"https://vuepress-theme-hope-docs-demo.netlify.app/api/dev/observer.html"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/en/api/dev/observer.html"}],["meta",{"property":"og:site_name","content":"LiteyukiBot"}],["meta",{"property":"og:title","content":"liteyuki.dev.observer"}],["meta",{"property":"og:description","content":"func debounce() Description: 防抖函数 Source code func on_file_system_event(directories: tuple[str] = True, recursive: bool = None) -> Callable[[CALLBACK_FUNC], CALLBACK_FUNC] Descr..."}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"en-US"}],["meta",{"property":"og:locale:alternate","content":"zh-CN"}],["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"Article\\",\\"headline\\":\\"liteyuki.dev.observer\\",\\"image\\":[\\"\\"],\\"dateModified\\":null,\\"author\\":[]}"]]},"headers":[{"level":3,"title":"func debounce()","slug":"func-debounce","link":"#func-debounce","children":[]},{"level":3,"title":"func on_file_system_event(directories: tuple[str] = True, recursive: bool = None) -> Callable[[CALLBACK_FUNC], CALLBACK_FUNC]","slug":"func-on-file-system-event-directories-tuple-str-true-recursive-bool-none-callable-callback-func-callback-func","link":"#func-on-file-system-event-directories-tuple-str-true-recursive-bool-none-callable-callback-func-callback-func","children":[]},{"level":3,"title":"class CodeModifiedHandler(FileSystemEventHandler)","slug":"class-codemodifiedhandler-filesystemeventhandler","link":"#class-codemodifiedhandler-filesystemeventhandler","children":[]},{"level":3,"title":"@debounce(1)","slug":"debounce-1","link":"#debounce-1","children":[]},{"level":3,"title":"method on_modified(self, event)","slug":"method-on-modified-self-event","link":"#method-on-modified-self-event","children":[]},{"level":3,"title":"method on_created(self, event)","slug":"method-on-created-self-event","link":"#method-on-created-self-event","children":[]},{"level":3,"title":"method on_deleted(self, event)","slug":"method-on-deleted-self-event","link":"#method-on-deleted-self-event","children":[]},{"level":3,"title":"method on_moved(self, event)","slug":"method-on-moved-self-event","link":"#method-on-moved-self-event","children":[]},{"level":3,"title":"method on_any_event(self, event)","slug":"method-on-any-event-self-event","link":"#method-on-any-event-self-event","children":[]},{"level":3,"title":"var CALLBACK_FUNC = Callable[[FileSystemEvent], None]","slug":"var-callback-func-callable-filesystemevent-none","link":"#var-callback-func-callable-filesystemevent-none","children":[]},{"level":3,"title":"var FILTER_FUNC = Callable[[FileSystemEvent], bool]","slug":"var-filter-func-callable-filesystemevent-bool","link":"#var-filter-func-callable-filesystemevent-bool","children":[]}],"git":{"createdTime":null,"updatedTime":null,"contributors":[]},"readingTime":{"minutes":1.28,"words":384},"filePathRelative":"en/api/dev/observer.md","autoDesc":true}');export{r as comp,u as data};