Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

phosphor-signaling

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

phosphor-signaling - npm Package Compare versions

Comparing version 0.9.6 to 0.9.7

scripts/tdoptions.json

14

lib/index.d.ts

@@ -6,3 +6,3 @@ /**

* User code will not create a signal object directly, instead one will
* be returned when accessing the property defined by the `@signal`
* be returned when accessing the property defined by the `defineSignal`
* decorator.

@@ -18,3 +18,3 @@ *

*
* @signal
* @defineSignal
* valueChanged: ISignal<number>;

@@ -25,3 +25,3 @@ *

* // ES5 alternative signal definition
* signal(SomeClass.prototype, 'valueChanged');
* defineSignal(SomeClass.prototype, 'valueChanged');
* ```

@@ -107,3 +107,3 @@ */

/**
* A decorator which defines a signal for an object.
* A decorator which defines a signal on a prototype.
*

@@ -123,3 +123,3 @@ * @param proto - The object prototype on which to define the signal.

*
* @signal
* @defineSignal
* valueChanged: ISignal<number>;

@@ -130,6 +130,6 @@ *

* // ES5 alternative signal definition
* signal(SomeClass.prototype, 'valueChanged');
* defineSignal(SomeClass.prototype, 'valueChanged');
* ```
*/
export declare function signal(proto: any, name: string): void;
export declare function defineSignal(proto: any, name: string): void;
/**

@@ -136,0 +136,0 @@ * Get the object which is emitting the current signal.

@@ -10,3 +10,3 @@ /*-----------------------------------------------------------------------------

/**
* A decorator which defines a signal for an object.
* A decorator which defines a signal on a prototype.
*

@@ -26,3 +26,3 @@ * @param proto - The object prototype on which to define the signal.

*
* @signal
* @defineSignal
* valueChanged: ISignal<number>;

@@ -33,6 +33,6 @@ *

* // ES5 alternative signal definition
* signal(SomeClass.prototype, 'valueChanged');
* defineSignal(SomeClass.prototype, 'valueChanged');
* ```
*/
function signal(proto, name) {
function defineSignal(proto, name) {
var token = {};

@@ -43,3 +43,3 @@ Object.defineProperty(proto, name, {

}
exports.signal = signal;
exports.defineSignal = defineSignal;
/**

@@ -46,0 +46,0 @@ * Get the object which is emitting the current signal.

@@ -7,3 +7,3 @@ declare module 'phosphor-signaling/index' {

* User code will not create a signal object directly, instead one will
* be returned when accessing the property defined by the `@signal`
* be returned when accessing the property defined by the `defineSignal`
* decorator.

@@ -19,3 +19,3 @@ *

*
* @signal
* @defineSignal
* valueChanged: ISignal<number>;

@@ -26,3 +26,3 @@ *

* // ES5 alternative signal definition
* signal(SomeClass.prototype, 'valueChanged');
* defineSignal(SomeClass.prototype, 'valueChanged');
* ```

@@ -108,3 +108,3 @@ */

/**
* A decorator which defines a signal for an object.
* A decorator which defines a signal on a prototype.
*

@@ -124,3 +124,3 @@ * @param proto - The object prototype on which to define the signal.

*
* @signal
* @defineSignal
* valueChanged: ISignal<number>;

@@ -131,6 +131,6 @@ *

* // ES5 alternative signal definition
* signal(SomeClass.prototype, 'valueChanged');
* defineSignal(SomeClass.prototype, 'valueChanged');
* ```
*/
export function signal(proto: any, name: string): void;
export function defineSignal(proto: any, name: string): void;
/**

@@ -137,0 +137,0 @@ * Get the object which is emitting the current signal.

{
"name": "phosphor-signaling",
"version": "0.9.6",
"version": "0.9.7",
"description": "A module for type-safe inter-object communication.",

@@ -24,3 +24,3 @@ "main": "lib/index.js",

"build": "npm run build:src && npm run build:dts && npm run build:test",
"docs": "rimraf docs && typedoc --module commonjs --target ES5 --excludeNotExported --mode file --out docs src/index.ts typings/es6-containers/es6-containers.d.ts",
"docs": "rimraf docs && typedoc --options scripts/tdoptions.json",
"prepublish": "npm run build",

@@ -27,0 +27,0 @@ "test": "mocha"

@@ -77,7 +77,11 @@ phosphor-signaling

**Note:** Except where explicitly noted in the examples, this module is fully
compatible with Node/Babel/ES6/ES5. Simply omit the type declarations when
using a language other than TypeScript.
**Start by defining the model object and its signals:**
*TypeScript*
```typescript
import { ISignal, signal } from 'phosphor-signaling';
// Omit the `ISignal` import on Node/Babel/ES6/ES5
import { ISignal, defineSignal } from 'phosphor-signaling';

@@ -87,3 +91,4 @@

@signal
// See below for Node/Babel/ES6/ES5 equivalent
@defineSignal
itemAdded: ISignal<{ index: number, item: string }>;

@@ -112,43 +117,13 @@

}
```
*ES5*
```javascript
var signal = require('phosphor-signaling').signal;
function Model(name) {
this._name = name;
this._items = [];
}
signal(Model.prototype, 'itemAdded');
Object.defineProperty(Model.prototype, 'name', {
get: function() { return this._name; },
});
Object.defineProperty(Model.prototype, 'items', {
get: function() { return this._items.slice(); },
});
Object.prototype.addItem = function(item) {
var i = this._items.length;
this._items.push(item);
this.itemAdded.emit({ index: i, item: item });
};
// Node/Babel/ES6/ES5 `@defineSignal` decorator alternative
defineSignal(Model.prototype, 'itemAdded');
```
**Next, define the handler(s) which will consume the signals:**
If the same handler is connected to multiple signals, it may want to get a reference
to the object emitting the signal which caused it to be invoked. This
can be done with the `emitter()` function.
If the same handler is connected to multiple signals, it may want to get a
reference to the object emitting the signal which caused it to be invoked.
This can be done with the `emitter()` function.
*TypeScript*
```typescript

@@ -191,41 +166,5 @@ import { emitter } from 'phosphor-signaling';

*ES5*
```javascript
var emitter = require('phosphor-signaling').emitter;
function logger(args) {
var model = emitter();
console.log(model.name, args.index, args.name);
}
function ItemCounter(model, item) {
this._count = 0;
this._model = model;
this._item = item;
model.itemAdded.connect(this._onItemAdded, this);
}
ItemCounter.prototype.dispose = function() {
this._model.itemAdded.disconnect(this._onItemAdded, this);
this._model = null;
};
Object.defineProperty(ItemCounter.prototype, 'count', {
get: function() { return this._count; },
});
ItemCounter.prototype._onItemAdded = function(args) {
if (args.item === this._item) this._count++;
};
```
**Next, connect the handlers to the signals:**
```javascript
```typescript
var m1 = new Model('foo');

@@ -244,6 +183,5 @@ var m2 = new Model('bar');

**Make some changes to the models:**
```javascript
```typescript
m1.addItem('turkey');

@@ -258,7 +196,5 @@ m1.addItem('fowl');

**Disconnect the logger from all models in a single-shot:**
*TypeScript*
```
```typescript
import { disconnectReceiver } from 'phosphor-signaling';

@@ -269,14 +205,5 @@

*ES5*
```
var disconnectReceiver = require('phosphor-signaling').disconnectReceiver;
disconnectReceiver(logger);
```
**Disconnect a particular model from all handlers in a single-shot:**
*TypeScript*
```
```typescript
import { disconnectEmitter } from 'phosphor-signaling';

@@ -286,8 +213,1 @@

```
*ES5*
```
var disconnectEmitter = require('phosphor-signaling').disconnectEmitter;
disconnectEmitter(m1);
```

@@ -16,3 +16,3 @@ /*-----------------------------------------------------------------------------

* User code will not create a signal object directly, instead one will
* be returned when accessing the property defined by the `@signal`
* be returned when accessing the property defined by the `defineSignal`
* decorator.

@@ -28,3 +28,3 @@ *

*
* @signal
* @defineSignal
* valueChanged: ISignal<number>;

@@ -35,3 +35,3 @@ *

* // ES5 alternative signal definition
* signal(SomeClass.prototype, 'valueChanged');
* defineSignal(SomeClass.prototype, 'valueChanged');
* ```

@@ -122,3 +122,3 @@ */

/**
* A decorator which defines a signal for an object.
* A decorator which defines a signal on a prototype.
*

@@ -138,3 +138,3 @@ * @param proto - The object prototype on which to define the signal.

*
* @signal
* @defineSignal
* valueChanged: ISignal<number>;

@@ -145,7 +145,7 @@ *

* // ES5 alternative signal definition
* signal(SomeClass.prototype, 'valueChanged');
* defineSignal(SomeClass.prototype, 'valueChanged');
* ```
*/
export
function signal(proto: any, name: string): void {
function defineSignal(proto: any, name: string): void {
var token = {};

@@ -152,0 +152,0 @@ Object.defineProperty(proto, name, {

@@ -23,9 +23,9 @@ /*-----------------------------------------------------------------------------

__decorate([
index_1.signal
index_1.defineSignal
], TestObject.prototype, "one");
__decorate([
index_1.signal
index_1.defineSignal
], TestObject.prototype, "two");
__decorate([
index_1.signal
index_1.defineSignal
], TestObject.prototype, "three");

@@ -32,0 +32,0 @@ return TestObject;

@@ -13,3 +13,3 @@ /*-----------------------------------------------------------------------------

import {
ISignal, disconnectEmitter, disconnectReceiver, emitter, signal
ISignal, defineSignal, disconnectEmitter, disconnectReceiver, emitter
} from '../lib/index';

@@ -20,9 +20,9 @@

@signal
@defineSignal
one: ISignal<void>;
@signal
@defineSignal
two: ISignal<boolean>;
@signal
@defineSignal
three: ISignal<string[]>;

@@ -29,0 +29,0 @@ }

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc