
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Airwaves is a lightweight pub/sub library that can be used in any JavaScript environment. It has no dependencies.
Airwaves is a lightweight pub/sub library that can be used in any JavaScript environment. It has no dependencies.
To communicate over the airwaves, first create a channel:
bbc = new airwaves.Channel
Channels provide methods for broadcasting transmissions and for managing subscriptions to these broadcasts. Each channel operates on a dedicated frequency, so there's no risk of anyone receiving unwanted transmissions.
bbc.subscribe "news", ({name}) -> alert "now playing: #{name}"
bbc.broadcast "news",
name: "World Business Report"
desc: "The latest business and finance news from around the world."
This adds a subscriber to "news" broadcasts on the bbc
channel. Shortly
thereafter, the subscriber learns of the World Business Report broadcast.
channel.broadcast(name, args...)
Broadcast args
to all those subscribed to name
on this channel.
channel.broadcast "delete"
channel.broadcast "rename", "johnsmith", "JohnSmith"
channel.broadcast "resize", width: 1360, height: 859
channel.subscribe(name, fn)
Subscribe fn
to broadcasts of name
on this channel. fn
receives the
broadcast's values as arguments.
channel.subscribe "hashchange", (hash) -> location.hash = hash
channel.unsubscribe(name[, fn])
Unsubscribe fn
from broadcasts of name
on this channel. If fn
is
omitted, all subscriptions to broadcasts of name
on this channel are
cancelled.
# Unsubscribe save handler from "textchange" broadcasts:
channel.unsubscribe "textchange", save
# Unsubscribe all handlers from "resize" broadcasts:
channel.unsubscribe "resize"
channel.intercept(name, fn)
Subscribe fn
to broadcasts of name
on this channel in such a way that it
may modify and/or cancel such broadcasts.
Subscribers can receive and respond to broadcasts, but cannot affect them in any way. Interceptors, on the other hand:
An interceptor receives the broadcast as its first argument, followed by zero or more arguments representing the broadcast's content:
channel.intercept "print", (broadcast, filename, orientation) ->
# ...
channel.broadcast "print", "~/Downloads/contract.pdf", "portrait"
An interceptor cancels any broadcast it intercepts unless it invokes the function passed to it as its first argument. The values it passes to this function are received by subscribers (and any remaining interceptors). The no-op interceptor is as follows:
channel.intercept name, (broadcast, args...) ->
broadcast args...
An interceptor modifies a broadcast by invoking the broadcast function with values different from those it received. This enables an interceptor to, for example, sanitize broadcasts on the fly:
channel.intercept "comment", (broadcast, user, message) ->
broadcast user, message.replace /wtf/gi, "what on earth"
channel.subscribe "comment", (user, message) ->
console.log "#{user}: #{message}"
channel.broadcast "comment", "Mr. Badger", "I don't know WTF is going on"
channel.broadcast "comment", "Ken Shabby", "WTF are you talking about?"
# Mr. Badger: I don't know what on earth is going on
# Ken Shabby: what on earth are you talking about?
Interceptors can also be used to suppress invalid broadcasts. For example:
channel.intercept "move", (broadcast, move) ->
if player is active_player then broadcast move
else alert "It's not your turn!"
Airwaves supports comma-separated event names, so the following snippets are equivalent:
channel.subscribe 'numerator-change', calculate
channel.subscribe 'denominator-change', calculate
channel.subscribe 'numerator-change, denominator-change', calculate
More accurately, event names are delimited by [,\s]+
(thus cannot contain
commas or whitespace).
make setup
make test
FAQs
Airwaves is a lightweight pub/sub library that can be used in any JavaScript environment. It has no dependencies.
The npm package airwaves receives a total of 3 weekly downloads. As such, airwaves popularity was classified as not popular.
We found that airwaves demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.