Skip to content

Commit dfdc77b

Browse files
committed
Add emit API method #19
1 parent 58ca676 commit dfdc77b

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
![Sysend.js Logo](https://github.com/jcubic/sysend.js/blob/master/assets/logo.svg?raw=true)
22

3-
[![npm](https://img.shields.io/badge/npm-1.4.0-blue.svg)](https://www.npmjs.com/package/sysend)
4-
![bower](https://img.shields.io/badge/bower-1.4.0-yellow.svg)
3+
[![npm](https://img.shields.io/badge/npm-1.5.0-blue.svg)](https://www.npmjs.com/package/sysend)
4+
![bower](https://img.shields.io/badge/bower-1.5.0-yellow.svg)
55
![downloads](https://img.shields.io/npm/dt/sysend.svg)
66
[![jsdelivr](https://img.shields.io/jsdelivr/npm/hm/sysend)](https://www.jsdelivr.com/package/npm/sysend)
77

@@ -105,12 +105,13 @@ sysend object:
105105
* `on(name, callback)` - `callback(object, name)` - add event handler for specified name.
106106
* `off(name [, callback])` - remove event handler for given name, if callback is not specified it will remove all callbacks for given name.
107107
* `broadcast(name [, object])` - send any object and fire all events with specified name (in different pages that register callback using on). You can also just send notification without an object.
108-
* `proxy(url)` - create iframe proxy for different domain, the target domain/url should have [proxy.html](https://github.com/jcubic/sysend.js/blob/master/proxy.html) file. If url domain is the same as page domain, it's ignored. So you can put both proxy calls on both domains (new in 1.3.0)
109-
* `serializer(to_string, from_string)` - add serializer and deserializer functions (new in 1.4.0)
108+
* `emit(name, [, object])` - same as broadcast but also invoke the even on same page (new in 1.5.0).
109+
* `proxy(url)` - create iframe proxy for different domain, the target domain/url should have [proxy.html](https://github.com/jcubic/sysend.js/blob/master/proxy.html) file. If url domain is the same as page domain, it's ignored. So you can put both proxy calls on both domains (new in 1.3.0).
110+
* `serializer(to_string, from_string)` - add serializer and deserializer functions (new in 1.4.0).
110111

111112
## License
112113

113-
Copyright (C) 2014-2021 [Jakub T. Jankiewicz](http://jcubic.pl/me)<br/>
114+
Copyright (C) 2014-2021 [Jakub T. Jankiewicz](https://jakub.jankiewicz.org)<br/>
114115
Released under the [MIT license](https://opensource.org/licenses/MIT)
115116

116117
This is free software; you are free to change and redistribute it.<br/>

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sysend",
3-
"version": "1.4.0",
3+
"version": "1.5.0",
44
"description": "Send messages to other tabs/windows in the same browser",
55
"main": "sysend.js",
66
"typings": "sysend.d.ts",
@@ -20,7 +20,7 @@
2020
"notifications",
2121
"browser"
2222
],
23-
"author": "Jakub T. Jankiewicz <jcubic@onet.pl> (http://jcubic.pl/me/)",
23+
"author": "Jakub T. Jankiewicz <jcubic@onet.pl> (https://jakub.jankiewicz.org/)",
2424
"license": "MIT",
2525
"bugs": {
2626
"url": "https://github.com/jcubic/sysend.js/issues"

sysend.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
/**@license
2-
* sysend.js - send messages between browser windows/tabs version 1.4.0
2+
* sysend.js - send messages between browser windows/tabs version 1.5.0
33
*
4-
* Copyright (C) 2014-2021 Jakub T. Jankiewicz <https://jcubic.pl/me>
4+
* Copyright (C) 2014-2021 Jakub T. Jankiewicz <https://jakub.jankiewicz.org>
55
* Released under the MIT license
66
*
77
*/
88
type callback = (message: any, event: string) => void;
99

1010
interface Sysend {
1111
broadcast(event: string, message?: any): void;
12+
emit(event: string, message?: any): void;
1213
on(event: string, callback: callback): void;
1314
off(event: string, callback?: callback): void;
1415
proxy(url: string): void;

sysend.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**@license
2-
* sysend.js - send messages between browser windows/tabs version 1.4.0
2+
* sysend.js - send messages between browser windows/tabs version 1.5.0
33
*
4-
* Copyright (C) 2014-2021 Jakub T. Jankiewicz <https://jcubic.pl/me>
4+
* Copyright (C) 2014-2021 Jakub T. Jankiewicz <https://jakub.jankiewicz.org>
55
* Released under the MIT license
66
*
77
* The idea for localStorage implementation came from this StackOverflow question:
@@ -51,6 +51,10 @@
5151
}
5252
send_to_iframes(event, message);
5353
},
54+
emit: function(event, message) {
55+
sysend.broadcast(event, message);
56+
invoke(event, message);
57+
},
5458
serializer: function(to, from) {
5559
if (typeof to !== 'function' || typeof from !== 'function') {
5660
throw new Error('sysend::serializer: Invalid argument, expecting' +

0 commit comments

Comments
 (0)