New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@travetto/watch

Package Overview
Dependencies
Maintainers
1
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@travetto/watch

Support for making files watchable during runtime

  • 2.0.0-alpha.3
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Watch

Support for making files watchable during runtime

Install: @travetto/watch

npm install @travetto/watch

This module is intended to be used during development, and is not during production. This constraint is tied to the performance hit the functionality could have at run-time. To that end, this is primarily an utilitiy for other modules, but it's functionality could prove useful to others during development.

File Watching

This module is the base file system watching support for Travetto applications. In addition to file system scanning, the framework offers a simple file watching library. The goal is to provide a substantially smaller footprint than gaze or chokidar. Utilizing the patterns from the file scanning, you create a Watcher that either has files added manually, or has patterns added that will recursively look for files.

Code: Example of watching for specific files

import { Watcher } from '@travetto/watch';

export function main() {
  const watcher = new Watcher('base/path/to/...')
    .on('all', ({ event, entry }) => {
      if (entry.file.endsWith('.config') || entry.file.endsWith('.config.json')) {
        console.log('File Event', { event, file: entry.file });
      }
    });

  setTimeout(() => watcher.close(), 1000);
}

Retargetting Proxy

In addition to file watching, the module also provides a core utiltity for hot reloading at runtime. The framework makes use of ES2015 Proxys. Specifically the the module provides RetargettingProxy, as a means to provide a reference that can have it's underlying target changed at runtime.

Code: Example of using the RetargettingProxy

import { RetargettingProxy } from '@travetto/watch';

class User { }

export class CoolService {
  async tricky() {
    const target = new User();
    const proxy = new RetargettingProxy(target);

    // Update target a second later
    setTimeout(() => {
      proxy.setTarget(new User());
    }, 1000);

    return proxy;
  }
}

Keywords

FAQs

Package last updated on 20 Apr 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc