Live Controller Watcher for CLient Side

Usage no npm install needed!

<script type="module">
  import PathWatcher from 'https://cdn.skypack.dev/@__path/watcher';



Path Watcher is a javascript library for interacting with Path's Live Controller, Path Watcher is based on WebSocket and Server-sent-event(SSE).


Using npm

$ npm i --save @__path/watcher

Using Yarn(recommended)

$ yarn add @__path/watcher


Configure Watcher in ./path/project.pconf.json, Set method to how you want Path watcher to work (WS or SSE)

  "WATCHER": {
    "method": "WS",//change this to SSE/WS
    "WEBSOCKET": {
      "host": "yourLocalHost.test",
      "port": 443,
      "scheme": "SSL"

Import for Usage

import Watcher from "@__path/watcher";

Instantiate, Set Live Controller name and proceed to listening to changes

let watcher =  new Watcher('TestChanges')
//here we are referencing the class we created earlier
                   .watch('prop')//we told path-watcher which of the properties to watch, this case we are watching $prop property
                       key1:'a value',
                       anotherKey:'another value'
                   })//we are adding additional infos that can be retrieved from the server side with `getParam()` method of WatcherInterface instance.
watcher.onReady(watcher => {
    // here, we can assign functions to be executed when a particular property changes
    watcher.listenTo("prop", response => {
// we assign an anonymous function to execute when $prop changes on server side
//the `response` parameter will be an object where key "data" will be our property's value

        let is_logged_in = response.data;
// extract the data
        if(is_logged_in !== 'yes'){
            location.href = '/logout'
watcher.start();//tell path to begin watching