watch

package
v0.1.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2026 License: MIT, MIT Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

@golet-plugins/watch

Changes to files for Golet apps' pages, in the directories and files the app lets them watch, such as a project open in an editor.

Use the plugin in Go with the directories pages may watch, each under a name:

import "github.com/HyperparameterSI/golet/backend/plugins/watch"

golet.Use(watch.New(watch.Options{
	Roots: map[string]watch.Root{
		"project": {Path: projectDir, Recursive: true},
	},
}))

and watch one by its name in the frontend:

import { watch } from "@golet-plugins/watch";

const watcher = await watch("project", { recursive: true });
for await (const events of watcher) {
  for (const event of events) console.log(event.op, event.path); // "write", "src/main.ts"
}

Each batch has the events of create, write, remove and rename (with oldPath) found once changes stopped for 50 ms (debounceMs), with paths relative to what is watched, path in the root or the root itself. They say what is different, not every step: treat them as hints to read the files again. watcher.close(), breaking out of the loop, an AbortSignal (signal) or the page navigating stop the watch.

The documentation covers the options of the Go side, errors and how each platform watches.

Documentation

Overview

Package watch is the watch plugin of Golet: it lets pages watch for changes to the files and directories the app names (see @golet-plugins/watch). Go code and native UI call golet.WatchFiles directly.

Index

Constants

This section is empty.

Variables

View Source
var Plugin = New(Options{})

Plugin is the plugin without roots, which lets pages watch nothing.

Functions

func New

func New(opts Options) golet.Plugin

New returns the plugin with opts. golet.Use panics when a root is not an absolute path to a directory or a file, after resolving its symlinks.

Types

type Options

type Options struct {
	// Roots are the directories and files pages may watch, by the names
	// they use: lowercase letters, digits and dashes, starting with a
	// letter.
	Roots map[string]Root
	// Resolve, when set, is asked for the root of a name that is not in
	// Roots, with the call's context, so that the app can grant roots
	// while it runs, such as a folder the user chose in a dialog. It
	// returns false for names it doesn't know.
	Resolve func(ctx context.Context, name string) (Root, bool)
	// Allow, when set, is asked before each watch with the call's context
	// and the request, and can refuse it.
	Allow func(ctx context.Context, r Request) bool
	// MaxWatchesPerPage is how many watches a page may have at a time: 8
	// when zero.
	MaxWatchesPerPage int
	// MaxWatches is how many watches all pages may have at a time: 128
	// when zero.
	MaxWatches int
}

Options configures the plugin.

type Request

type Request struct {
	// Root is the name of the root.
	Root string
	// Path is what to watch in the root, relative to it and separated by
	// slashes: "." for the root itself.
	Path string
	// Recursive asks to watch the directories in it too.
	Recursive bool
}

Request is a watch a page asks for.

type Root

type Root struct {
	// Path is the absolute path of the directory or file.
	Path string
	// Recursive lets pages watch the directories in it too, and what is
	// in them.
	Recursive bool
	// Ignore, when set, is asked about every file and directory a watch
	// of the root finds, by its path relative to the root, separated by
	// slashes, as golet.FileWatchOptions.Ignore is.
	Ignore func(path string, isDir bool) bool
}

Root is a directory, or a file, pages may watch.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL