ste-browser

3.0.11 • Public • Published

Strongly Typed Events for your browser

Why not use Strongly Typed Events in your browser? We got a special package for you that already contains all the files you need. You can even serve them from a CDN for extra speed (or easy prototyping). The packae is UMD compatible.

Build Status npm version code style: prettier License: MIT

Code

Include the script from this NPM package or from a CDN:

<script src="https://cdn.jsdelivr.net/npm/ste-browser@latest/dist/strongly-typed-events.min.js"></script>

Subscription is easy

Let's assume you have a clock, subscribing to events on it is easy:

var clock = new Clock("Smu", 1000);

//log the ticks to the console - this is a signal event
clock.onTick.subscribe(function () {
    console.log("Tick!");
});

//log the sequence parameter to the console - this is a simple event
clock.onSequenceTick.subscribe(function (s) {
    console.log(`Sequence: ${s}`);
});

//log the name of the clock and the tick argument to the console - this is an event
clock.onClockTick.subscribe(function (c, n) {
    console.log(c.name + " ticked " + n + " times.");
});

Creating events is also easy

We've created a dispatcher to help you propagate your events:

function Clock(name, timeout) {

    var _this = this;
    var _ticks = 0;
    var _onTick = new SignalDispatcher();
    var _onSequenceTick = new SimpleEventDispatcher();
    var _onClockTick = new EventDispatcher();

    setInterval(function () {
        _ticks += 1;
        _onTick.dispatch();
        _onSequenceTick.dispatch(_ticks);
        _onClockTick.dispatch(_this, _ticks);
    }, timeout);

    Object.defineProperty(this, "name", {
        get: function () { return name; }
    });

    Object.defineProperty(this, "ticks", {
        get: function () { return _ticks; }
    });

    Object.defineProperty(this, "onTick", {
        get: function () { return _onTick.asEvent(); }
    });

    Object.defineProperty(this, "onSequenceTick", {
        get: function () { return _onSequenceTick.asEvent(); }
    });

    Object.defineProperty(this, "onClockTick", {
        get: function () { return _onClockTick.asEvent(); }
    });
}

Usage

The package contains the following scripts:

  • Events that are modeled after .Net with a sender and argument.
    • dist/ste-events.js
    • dist/ste-events.min.js
    • dist/ste-promise-events.js
    • dist/ste-promise-events.min.js

  • A simpler version of the ste-event-event. No sender, just an argument.
    • dist/ste-simple-events.js
    • dist/ste-simple-events.min.js
    • dist/ste-promise-simple-events.js
    • dist/ste-promise-simple-events.min.js

  • A signal is even simpler, it is just a callback for when you need to be alerted without any scope.
    • dist/ste-signals.js
    • dist/ste-signals.min.js
    • dist/ste-promise-signals.js
    • dist/ste-promise-signals.min.js

  • All objects to build and use events:
    • dist/strongly-typed-events.js
    • dist/strongly-typed-events.min.js

  • Want to build your own style of events? You can use the dispatcher and other base classes for our core project:
    • dist/ste-core.js
    • dist/ste-core.min.js

CDN

You want to use a CDN? Great!

What Link
All event types https://cdn.jsdelivr.net/npm/ste-browser@latest/dist/strongly-typed-events.min.js
Events https://cdn.jsdelivr.net/npm/ste-browser@latest/dist/ste-events.min.js
Events with Promise https://cdn.jsdelivr.net/npm/ste-browser@latest/dist/ste-promise-events.min.js
Simple Events https://cdn.jsdelivr.net/npm/ste-browser@latest/dist/ste-simple-events.min.js
Simple Events with Promise https://cdn.jsdelivr.net/npm/ste-browser@latest/dist/ste-promise-simple-events.min.js
Signals https://cdn.jsdelivr.net/npm/ste-browser@latest/dist/ste-signals.min.js
Signals with Promise https://cdn.jsdelivr.net/npm/ste-browser@latest/dist/ste-promise-signals.min.js
Core https://cdn.jsdelivr.net/npm/ste-browser/dist/strongly-typed-events.min.js

Every link comes with a .map. If you need a specific version, just include after ste-browser (like ste-browser@1.3 will serve you version 1.3 with the latest patches). Like a non-minified version, just remove .min from the link.

Packages

The project is separated into multiple packages, so you only need to include what you need. We have the following packages:

Package Description
ste-core Package that contains all the building blocks for the creation of events. The dispatcher implementation is its main hero.
ste-events or ste-promise-events Events that are modeled after .Net with a sender and argument. If you use typescript, you can leverage the support for generics and get strongly typed code.
ste-simple-events or ste-promise-simple-events A simpler version of the ste-event-event. No sender, just an argument.
ste-signals or ste-promise-signals A signal is even simpler, it is just a callback for when you need to be alerted without any scope.
strongly-typed-events This package includes everything.
ste-browser Helps to host events in the browser.

Maintenance

This project is maintained by Kees C. Bakker.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
3.0.112latest

Version History

VersionDownloads (Last 7 Days)Published
3.0.112
3.0.91
3.0.81
3.0.71
3.0.61
3.0.51
3.0.41
3.0.31
3.0.21
3.0.11
2.1.161
2.1.141
2.1.131
2.1.121
2.1.111
2.1.101
2.1.91
2.1.81
2.1.71
2.1.62
2.1.51
2.1.41
2.1.31
2.1.21
2.0.91
2.0.61
2.0.51
2.0.21
2.0.11
1.7.21
1.7.12
1.7.01
1.6.211
1.6.201
1.6.191
1.6.181
1.6.161
1.6.151
1.6.141
1.6.131
1.6.121
1.6.111
1.6.101
1.6.91
1.6.81
1.6.71
1.6.61
1.6.51
1.6.41
1.6.31
1.6.21
1.6.11
1.6.01
1.5.21
1.5.11
1.4.101
1.4.91
1.4.71
1.4.61
1.4.51
1.4.41
1.4.21
1.4.11
1.4.01
1.3.121
1.3.111
1.3.101
1.3.91
1.3.81
1.3.71
1.3.61
1.3.51
1.3.41

Package Sidebar

Install

npm i ste-browser

Weekly Downloads

76

Version

3.0.11

License

MIT

Unpacked Size

315 kB

Total Files

21

Last publish

Collaborators

  • keestalkstech