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

def debounce(wait: Any) -> None

防抖函数

源代码
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

def on_file_system_event(directories: tuple[str], recursive: bool, event_filter: FILTER_FUNC) -> Callable[[CALLBACK_FUNC], CALLBACK_FUNC]

注册文件系统变化监听器

Args:

directories: 监听目录们

recursive: 是否递归监听子目录

event_filter: 事件过滤器, 返回True则执行回调函数

Returns:

装饰器,装饰一个函数在接收到数据后执行
源代码
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

def decorator(func: Any) -> None

源代码
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

def decorator(func: CALLBACK_FUNC) -> CALLBACK_FUNC

源代码
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

def wrapper() -> None

源代码
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)

def wrapper(event: FileSystemEvent) -> None

源代码
def wrapper(event: FileSystemEvent):
    if event_filter is not None and (not event_filter(event)):
        return
    func(event)

class CodeModifiedHandler(FileSystemEventHandler)

Handler for code file changes

def on_modified(self, event: Any) -> None

源代码
@debounce(1)
def on_modified(self, event):
    raise NotImplementedError('on_modified must be implemented')

def on_created(self, event: Any) -> None

源代码
def on_created(self, event):
    self.on_modified(event)

def on_deleted(self, event: Any) -> None

源代码
def on_deleted(self, event):
    self.on_modified(event)

def on_moved(self, event: Any) -> None

源代码
def on_moved(self, event):
    self.on_modified(event)

def on_any_event(self, event: Any) -> None

源代码
def on_any_event(self, event):
    self.on_modified(event)

var liteyuki_bot = get_bot()

var observer = Observer()

var last_call_time = None

var code_modified_handler = CodeModifiedHandler()

var current_time = time.time()

var last_call_time = current_time

`,41),l=[o];function p(i,c){return e(),a("div",null,l)}const d=n(t,[["render",p],["__file","observer.html.vue"]]),u=JSON.parse('{"path":"/dev/api/dev/observer.html","title":"liteyuki.dev.observer","lang":"zh-CN","frontmatter":{"title":"liteyuki.dev.observer","order":1,"icon":"laptop-code","category":"API","description":"def debounce(wait: Any) -> None 防抖函数 源代码 def on_file_system_event(directories: tuple[str], recursive: bool, event_filter: FILTER_FUNC) -> Callable[[CALLBACK_FUNC], CALLBACK_FUNC...","head":[["link",{"rel":"alternate","hreflang":"en-us","href":"https://vuepress-theme-hope-docs-demo.netlify.app/en/dev/api/dev/observer.html"}],["meta",{"property":"og:url","content":"https://vuepress-theme-hope-docs-demo.netlify.app/dev/api/dev/observer.html"}],["meta",{"property":"og:site_name","content":"LiteyukiBot 轻雪机器人"}],["meta",{"property":"og:title","content":"liteyuki.dev.observer"}],["meta",{"property":"og:description","content":"def debounce(wait: Any) -> None 防抖函数 源代码 def on_file_system_event(directories: tuple[str], recursive: bool, event_filter: FILTER_FUNC) -> Callable[[CALLBACK_FUNC], CALLBACK_FUNC..."}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"zh-CN"}],["meta",{"property":"og:locale:alternate","content":"en-US"}],["meta",{"property":"og:updated_time","content":"2024-08-21T09:59:21.000Z"}],["meta",{"property":"article:modified_time","content":"2024-08-21T09:59:21.000Z"}],["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"Article\\",\\"headline\\":\\"liteyuki.dev.observer\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2024-08-21T09:59:21.000Z\\",\\"author\\":[]}"]]},"headers":[{"level":3,"title":"def debounce(wait: Any) -> None","slug":"def-debounce-wait-any-none","link":"#def-debounce-wait-any-none","children":[]},{"level":3,"title":"def on_file_system_event(directories: tuple[str], recursive: bool, event_filter: FILTER_FUNC) -> Callable[[CALLBACK_FUNC], CALLBACK_FUNC]","slug":"def-on-file-system-event-directories-tuple-str-recursive-bool-event-filter-filter-func-callable-callback-func-callback-func","link":"#def-on-file-system-event-directories-tuple-str-recursive-bool-event-filter-filter-func-callable-callback-func-callback-func","children":[]},{"level":3,"title":"def decorator(func: Any) -> None","slug":"def-decorator-func-any-none","link":"#def-decorator-func-any-none","children":[]},{"level":3,"title":"def decorator(func: CALLBACK_FUNC) -> CALLBACK_FUNC","slug":"def-decorator-func-callback-func-callback-func","link":"#def-decorator-func-callback-func-callback-func","children":[]},{"level":3,"title":"def wrapper() -> None","slug":"def-wrapper-none","link":"#def-wrapper-none","children":[]},{"level":3,"title":"def wrapper(event: FileSystemEvent) -> None","slug":"def-wrapper-event-filesystemevent-none","link":"#def-wrapper-event-filesystemevent-none","children":[]},{"level":3,"title":"class CodeModifiedHandler(FileSystemEventHandler)","slug":"class-codemodifiedhandler-filesystemeventhandler","link":"#class-codemodifiedhandler-filesystemeventhandler","children":[]},{"level":3,"title":"def on_modified(self, event: Any) -> None","slug":"def-on-modified-self-event-any-none","link":"#def-on-modified-self-event-any-none","children":[]},{"level":3,"title":"def on_created(self, event: Any) -> None","slug":"def-on-created-self-event-any-none","link":"#def-on-created-self-event-any-none","children":[]},{"level":3,"title":"def on_deleted(self, event: Any) -> None","slug":"def-on-deleted-self-event-any-none","link":"#def-on-deleted-self-event-any-none","children":[]},{"level":3,"title":"def on_moved(self, event: Any) -> None","slug":"def-on-moved-self-event-any-none","link":"#def-on-moved-self-event-any-none","children":[]},{"level":3,"title":"def on_any_event(self, event: Any) -> None","slug":"def-on-any-event-self-event-any-none","link":"#def-on-any-event-self-event-any-none","children":[]},{"level":3,"title":"var liteyuki_bot = get_bot()","slug":"var-liteyuki-bot-get-bot","link":"#var-liteyuki-bot-get-bot","children":[]},{"level":3,"title":"var observer = Observer()","slug":"var-observer-observer","link":"#var-observer-observer","children":[]},{"level":3,"title":"var last_call_time = None","slug":"var-last-call-time-none","link":"#var-last-call-time-none","children":[]},{"level":3,"title":"var code_modified_handler = CodeModifiedHandler()","slug":"var-code-modified-handler-codemodifiedhandler","link":"#var-code-modified-handler-codemodifiedhandler","children":[]},{"level":3,"title":"var current_time = time.time()","slug":"var-current-time-time-time","link":"#var-current-time-time-time","children":[]},{"level":3,"title":"var last_call_time = current_time","slug":"var-last-call-time-current-time","link":"#var-last-call-time-current-time","children":[]}],"git":{"createdTime":1724031826000,"updatedTime":1724234361000,"contributors":[{"name":"snowy","email":"snowykami@outlook.com","commits":5}]},"readingTime":{"minutes":1.82,"words":545},"filePathRelative":"dev/api/dev/observer.md","localizedDate":"2024年8月19日","autoDesc":true}');export{d as comp,u as data};