Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/panates/putil-callable
A callable class implementation
https://github.com/panates/putil-callable
Last synced: about 2 months ago
JSON representation
A callable class implementation
- Host: GitHub
- URL: https://github.com/panates/putil-callable
- Owner: panates
- Created: 2017-07-11T13:18:02.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-09T06:41:32.000Z (almost 2 years ago)
- Last Synced: 2024-10-07T17:10:29.542Z (3 months ago)
- Language: JavaScript
- Size: 183 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# putil-callable
[![NPM Version][npm-image]][npm-url]
[![NPM Downloads][downloads-image]][downloads-url]
[![Build Status][travis-image]][travis-url]
[![Test Coverage][coveralls-image]][coveralls-url]
[![DevDependencies][devdependencies-image]][devdependencies-url]This package contains two very handy callable class implementations.
Callable: Base extensible callable class
CallableEventEmitter: Mixin of Callable and EventEmitter classes.## Installation
- `$ npm install putil-callable --save`
## Usage
Extend Callable in ES6
```javascript
const {Callable} = require('putil-callable');class MyCallable extends Callable {
constructor() {
super('handle');
}handle(msg) {
console.log('MyCallable:', msg);
}
}
const obj1 = new MyCallable();
obj1('This is a callable class');
```
Extend Callable in ES5
```javascript
const Callable = require('putil-callable').Callable;function MyCallable() {
return Callable.call(this, 'handle');
}
MyCallable.prototype = Object.create(Callable.prototype);
MyCallable.prototype.constructor = MyCallable;
MyCallable.prototype.handle = function(msg) {
console.log('MyCallable:', msg);
};const obj1 = new MyCallable();
obj1('This is a callable class');
```Extend CallableEventEmitter in ES6
```js
const {CallableEventEmitter} = require('putil-callable');class MyCallable extends CallableEventEmitter {
constructor() {
super();
}__call__(msg) {
this.emit('msg', msg);
}
}const obj2 = new MyCallable();
obj2.on('msg', function(msg) {
console.log('CallableEventEmitter:', msg);
});```
## Node Compatibility
- node `>= 1`;
### License
[MIT](LICENSE)[npm-image]: https://img.shields.io/npm/v/putil-callable.svg
[npm-url]: https://npmjs.org/package/putil-callable
[travis-image]: https://img.shields.io/travis/panates/putil-callable/master.svg
[travis-url]: https://travis-ci.org/panates/putil-callable
[coveralls-image]: https://img.shields.io/coveralls/panates/putil-callable/master.svg
[coveralls-url]: https://coveralls.io/r/panates/putil-callable
[downloads-image]: https://img.shields.io/npm/dm/putil-callable.svg
[downloads-url]: https://npmjs.org/package/putil-callable
[devdependencies-image]: https://david-dm.org/panates/putil-callable/dev-status.svg
[devdependencies-url]:https://david-dm.org/panates/putil-callable?type=dev