@nextcloud/event-bus
Advanced tools
Comparing version 2.1.1 to 3.0.0
@@ -1,29 +0,78 @@ | ||
"use strict"; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.emit = emit; | ||
exports.subscribe = subscribe; | ||
exports.unsubscribe = unsubscribe; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var _ProxyBus = require("./ProxyBus"); | ||
var valid = require('semver/functions/valid'); | ||
var major = require('semver/functions/major'); | ||
var _SimpleBus = require("./SimpleBus"); | ||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
function getBus() { | ||
if (typeof window.OC !== 'undefined' && window.OC._eventBus && typeof window._nc_event_bus === 'undefined') { | ||
console.warn('found old event bus instance at OC._eventBus. Update your version!'); | ||
window._nc_event_bus = window.OC._eventBus; | ||
} // Either use an existing event bus instance or create one | ||
var valid__default = /*#__PURE__*/_interopDefaultLegacy(valid); | ||
var major__default = /*#__PURE__*/_interopDefaultLegacy(major); | ||
var ProxyBus = /** @class */ (function () { | ||
function ProxyBus(bus) { | ||
if (typeof bus.getVersion !== 'function' || !valid__default["default"](bus.getVersion())) { | ||
console.warn('Proxying an event bus with an unknown or invalid version'); | ||
} | ||
else if (major__default["default"](bus.getVersion()) !== major__default["default"](this.getVersion())) { | ||
console.warn('Proxying an event bus of version ' + bus.getVersion() + ' with ' + this.getVersion()); | ||
} | ||
this.bus = bus; | ||
} | ||
ProxyBus.prototype.getVersion = function () { | ||
return "3.0.0"; | ||
}; | ||
ProxyBus.prototype.subscribe = function (name, handler) { | ||
this.bus.subscribe(name, handler); | ||
}; | ||
ProxyBus.prototype.unsubscribe = function (name, handler) { | ||
this.bus.unsubscribe(name, handler); | ||
}; | ||
ProxyBus.prototype.emit = function (name, event) { | ||
this.bus.emit(name, event); | ||
}; | ||
return ProxyBus; | ||
}()); | ||
if (typeof window._nc_event_bus !== 'undefined') { | ||
return new _ProxyBus.ProxyBus(window._nc_event_bus); | ||
} else { | ||
return window._nc_event_bus = new _SimpleBus.SimpleBus(); | ||
} | ||
var SimpleBus = /** @class */ (function () { | ||
function SimpleBus() { | ||
this.handlers = new Map(); | ||
} | ||
SimpleBus.prototype.getVersion = function () { | ||
return "3.0.0"; | ||
}; | ||
SimpleBus.prototype.subscribe = function (name, handler) { | ||
this.handlers.set(name, (this.handlers.get(name) || []).concat(handler)); | ||
}; | ||
SimpleBus.prototype.unsubscribe = function (name, handler) { | ||
this.handlers.set(name, (this.handlers.get(name) || []).filter(function (h) { return h != handler; })); | ||
}; | ||
SimpleBus.prototype.emit = function (name, event) { | ||
(this.handlers.get(name) || []).forEach(function (h) { | ||
try { | ||
h(event); | ||
} | ||
catch (e) { | ||
console.error('could not invoke event listener', e); | ||
} | ||
}); | ||
}; | ||
return SimpleBus; | ||
}()); | ||
function getBus() { | ||
if ((typeof window.OC !== 'undefined') && window.OC._eventBus && typeof window._nc_event_bus === 'undefined') { | ||
console.warn('found old event bus instance at OC._eventBus. Update your version!'); | ||
window._nc_event_bus = window.OC._eventBus; | ||
} | ||
// Either use an existing event bus instance or create one | ||
if (typeof window._nc_event_bus !== 'undefined') { | ||
return new ProxyBus(window._nc_event_bus); | ||
} | ||
else { | ||
return window._nc_event_bus = new SimpleBus(); | ||
} | ||
} | ||
const bus = getBus(); | ||
var bus = getBus(); | ||
/** | ||
@@ -35,5 +84,4 @@ * Register an event listener | ||
*/ | ||
function subscribe(name, handler) { | ||
bus.subscribe(name, handler); | ||
bus.subscribe(name, handler); | ||
} | ||
@@ -48,6 +96,4 @@ /** | ||
*/ | ||
function unsubscribe(name, handler) { | ||
bus.unsubscribe(name, handler); | ||
bus.unsubscribe(name, handler); | ||
} | ||
@@ -60,7 +106,11 @@ /** | ||
*/ | ||
function emit(name, event) { | ||
bus.emit(name, event); | ||
bus.emit(name, event); | ||
} | ||
//# sourceMappingURL=index.js.map | ||
exports.ProxyBus = ProxyBus; | ||
exports.SimpleBus = SimpleBus; | ||
exports.emit = emit; | ||
exports.subscribe = subscribe; | ||
exports.unsubscribe = unsubscribe; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@nextcloud/event-bus", | ||
"version": "2.1.1", | ||
"description": "", | ||
"version": "3.0.0", | ||
"description": "A simple event bus to communicate between Nextcloud components.", | ||
"main": "dist/index.js", | ||
"module": "dist/index.esm.js", | ||
"types": "dist/index.d.ts", | ||
"exports": { | ||
"import": "./dist/index.esm.js", | ||
"require": "./dist/index.js" | ||
}, | ||
"files": [ | ||
"dist/" | ||
], | ||
"scripts": { | ||
"build": "babel ./lib --out-dir dist --extensions '.ts,.tsx' --source-maps && tsc --emitDeclarationOnly", | ||
"build": "rollup --config rollup.config.js", | ||
"build:doc": "typedoc --out dist/doc lib/index.ts && touch dist/doc/.nojekyll", | ||
"check-types": "tsc", | ||
"dev": "babel ./lib --out-dir dist --extensions '.ts,.tsx' --watch", | ||
"check-types": "tsc --noEmit", | ||
"dev": "rollup --config rollup.config.js --watch", | ||
"test": "jest", | ||
@@ -26,28 +34,19 @@ "test:watch": "jest --watchAll" | ||
"dependencies": { | ||
"@types/semver": "^7.1.0", | ||
"core-js": "^3.6.2", | ||
"semver": "^7.3.2" | ||
"semver": "^7.3.7" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.6.0", | ||
"@babel/core": "^7.6.0", | ||
"@babel/plugin-proposal-class-properties": "^7.5.5", | ||
"@babel/preset-env": "^7.6.0", | ||
"@babel/preset-typescript": "^7.6.0", | ||
"@nextcloud/browserslist-config": "^2.1.0", | ||
"@rollup/plugin-babel": "^5.3.0", | ||
"@rollup/plugin-commonjs": "^21.0.1", | ||
"@rollup/plugin-node-resolve": "^13.0.0", | ||
"babel-jest": "^27.2.1", | ||
"babel-plugin-inline-json-import": "^0.3.2", | ||
"jest": "^26.0.1", | ||
"rollup": "^2.47.0", | ||
"rollup-plugin-inject-process-env": "^1.3.1", | ||
"rollup-plugin-typescript2": "^0.30.0", | ||
"typedoc": "^0.22.4", | ||
"typescript": "^4.0.2" | ||
"@rollup/plugin-replace": "^4.0.0", | ||
"@rollup/plugin-typescript": "^8.3.4", | ||
"@types/semver": "^7.3.10", | ||
"jest": "^28.1.3", | ||
"jest-environment-jsdom": "^28.1.3", | ||
"rollup": "^2.77.2", | ||
"tslib": "^2.4.0", | ||
"typedoc": "^0.23.10", | ||
"typescript": "^4.7.4" | ||
}, | ||
"browserslist": [ | ||
"extends @nextcloud/browserslist-config" | ||
] | ||
"engines": { | ||
"node": "^16.0.0", | ||
"npm": "^7.0.0 || ^8.0.0" | ||
} | ||
} |
@@ -11,4 +11,8 @@ # @nextcloud/event-bus | ||
```sh | ||
npm install @nextcloud/event-bus --save | ||
``` | ||
npm i -S @nextcloud/event-bus | ||
```sh | ||
yarn add @nextcloud/event-bus | ||
``` | ||
@@ -35,2 +39,3 @@ | ||
## Naming convention | ||
To stay consistent, we encourage you to use the following syntax when declaring events | ||
@@ -41,7 +46,22 @@ | ||
### Examples: | ||
- nextcloud:unified-search:closed | ||
- files:file:uploading | ||
- files:file:uploaded | ||
- contacts:contact:deleted | ||
- calendar:event:created | ||
- forms:answer:updated | ||
- `nextcloud:unified-search:closed` | ||
- `files:file:uploading` | ||
- `files:file:uploaded` | ||
- `contacts:contact:deleted` | ||
- `calendar:event:created` | ||
- `forms:answer:updated` | ||
## Development | ||
```sh | ||
npm install | ||
npm run build | ||
npm run test | ||
``` | ||
### Requirements | ||
- [Node 16 or higher](https://nodejs.org/en/download/) | ||
- [NPM 8 or higher](https://www.npmjs.com/package/npm) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1
9
65
60299
13
267
1
- Removed@types/semver@^7.1.0
- Removedcore-js@^3.6.2
- Removed@types/semver@7.5.8(transitive)
- Removedcore-js@3.39.0(transitive)
Updatedsemver@^7.3.7