npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

veloxjs

v0.3.3

Published

Real-time object synchronisation over SSE

Downloads

5

Readme

velox

GoDoc

Real-time JS object synchronisation over SSE and WebSockets in Go and JavaScript (Node.js and browser)

Features

Quick Usage

Server (Go)

//syncable struct
type Foo struct {
	velox.State
	A, B int
}
foo := &Foo{}
//serve velox.js client library (assets/dist/velox.min.js)
http.Handle("/velox.js", velox.JS)
//serve velox sync endpoint for foo
http.Handle("/sync", velox.SyncHandler(foo))
//make changes
foo.A = 42
foo.B = 21
//push to client
foo.Push()

Server (Node)

//syncable object
let foo = {
  a: 1,
  b: 2
};
//express server
let app = express();
//serve velox.js client library (assets/dist/velox.min.js)
app.get("/velox.js", velox.JS);
//serve velox sync endpoint for foo (adds $push method)
app.get("/sync", velox.handle(foo));
//make changes
foo.a = 42;
foo.b = 21;
//push to client
foo.$push();

Client (Node and Browser)

// load script /velox.js
var foo = {};
var v = velox("/sync", foo);
v.onupdate = function() {
  //foo.A === 42 and foo.B === 21
};

API

Server API (Go)

GoDoc

Server API (Node)

  • velox.handle(object) function returns v - Creates a new route handler for use with express
  • velox.state(object) function returns state - Creates or restores a velox state from a given object
  • state.handle(req, res) function returns Promise - Handle the provided express request/response. Resolves on connection close. Rejects on any error.

Client API (Node and Browser)

  • velox(url, object) function returns v - Creates a new SSE velox connection
  • velox.sse(url, object) function returns v - Creates a new SSE velox connection
  • velox.ws(url, object) function returns v - Creates a new WS velox connection
  • v.onupdate(object) function - Called when a server push is received
  • v.onerror(err) function - Called when a connection error occurs
  • v.onconnect() function - Called when the connection is opened
  • v.ondisconnect() function - Called when the connection is closed
  • v.onchange(bool) function - Called when the connection is opened or closed
  • v.connected bool - Denotes whether the connection is currently open
  • v.ws bool - Denotes whether the connection is in web sockets mode
  • v.sse bool - Denotes whether the connection is in server-sent events mode

Example

See this simple example/ and view it live here: https://velox.jpillora.com

screenshot

Here is a screenshot from this example page, showing the messages arriving as either a full replacement of the object or just a delta. The server will send which ever is smaller.

Notes

  • JS object properties beginning with $ will be ignored to play nice with Angular.

  • JS object with an $apply function will automatically be called on each update to play nice with Angular.

  • velox.SyncHandler is just a small wrapper around velox.Sync:

    	```go
    	func SyncHandler(gostruct interface{}) http.Handler {
    		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
    			if conn, err := Sync(gostruct, w, r); err == nil {
    				conn.Wait()
    			}
    		})
    	}
    	```

Known issues

  • Object synchronization is currently one way (server to client) only.
  • Object diff has not been optimized. It is a simple property-by-property comparison.

TODO

  • WebRTC support
  • Plain http server support in Node
  • WebSockets support in Node

MIT License

Copyright © 2018 Jaime Pillora <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.