reactive-hermes
Advanced tools
Comparing version 1.1.4 to 1.1.5
@@ -203,12 +203,51 @@ import _regeneratorRuntime from 'babel-runtime/regenerator'; | ||
data = _this3.setMessageDuration(data); | ||
if (data.onShow) { | ||
data.onShow(data); | ||
} | ||
_this3.triggerEvent(data, 'messageOpen'); | ||
}); | ||
}; | ||
HermesComponent.prototype.triggerEvent = function triggerEvent(message, eventName) { | ||
eventName = 'on' + eventName.charAt(0).toUpperCase() + eventName.slice(1); | ||
var exec = function exec(message, eventName, container) { | ||
if (container[eventName]) { | ||
try { | ||
container[eventName](message); | ||
} catch (e) { | ||
console.error('Failed on callback for ' + eventName + '\nError Message: ' + (e.message || e) + ' for the message: ', message); | ||
} | ||
} | ||
}; | ||
exec(message, eventName, message); | ||
exec(message, eventName, this.props); | ||
if (eventName === 'onMessageUpdate' || eventName === 'onMessageOpen') { | ||
switch (message.type) { | ||
case 'error': | ||
case 'fail': | ||
exec(message, 'onError', message); | ||
exec(message, 'onError', this.props); | ||
break; | ||
case 'warn': | ||
case 'warning': | ||
exec(message, 'onWarning', message); | ||
exec(message, 'onWarning', this.props); | ||
break; | ||
case 'info': | ||
exec(message, 'onInfo', message); | ||
exec(message, 'onInfo', this.props); | ||
break; | ||
case 'success': | ||
case 'ok': | ||
exec(message, 'onSuccess', message); | ||
exec(message, 'onSuccess', this.props); | ||
break; | ||
} | ||
} | ||
}; | ||
HermesComponent.prototype.updateMessage = function updateMessage(id, data) { | ||
var _this4 = this; | ||
var list = this.state.messages; | ||
if (id && list[id]) { | ||
var message = list[id]; | ||
var oldMessage = Object.assign({}, list[id]); | ||
if (data.animate !== false && this.props.animate) { | ||
@@ -229,2 +268,7 @@ data.animate = true; | ||
messages: list | ||
}, function (_) { | ||
_this4.triggerEvent({ | ||
prev: oldMessage, | ||
next: message | ||
}, 'messageUpdate'); | ||
}); | ||
@@ -238,3 +282,3 @@ } else { | ||
HermesComponent.prototype.removeMessageElement = function removeMessageElement(data) { | ||
var _this4 = this; | ||
var _this5 = this; | ||
@@ -247,3 +291,3 @@ var id = data && data.id ? data.id : data; | ||
}, function (_) { | ||
_this4.updateTitleCounter(); | ||
_this5.updateTitleCounter(); | ||
if (data.to) { | ||
@@ -256,3 +300,3 @@ clearTimeout(data.to); | ||
HermesComponent.prototype.removeMessage = function removeMessage(data) { | ||
var _this5 = this; | ||
var _this6 = this; | ||
@@ -267,3 +311,4 @@ var id = data && data.id ? data.id : data; | ||
setTimeout(function (_) { | ||
_this5.removeMessageElement(data); | ||
_this6.triggerEvent(data, 'messageClose'); | ||
_this6.removeMessageElement(data); | ||
}, 1000); | ||
@@ -279,3 +324,3 @@ }); | ||
HermesComponent.prototype.render = function render() { | ||
var _this6 = this; | ||
var _this7 = this; | ||
@@ -287,3 +332,3 @@ var notifs = Object.keys(this.state.messages); | ||
notifs.map(function (messageId, i) { | ||
var message = _this6.state.messages[messageId]; | ||
var message = _this7.state.messages[messageId]; | ||
var order = notifs.length - i; | ||
@@ -305,3 +350,3 @@ return message ? React.createElement( | ||
onClick: function onClick(event) { | ||
return _this6.removeMessage(message); | ||
return _this7.removeMessage(message); | ||
} }, | ||
@@ -308,0 +353,0 @@ 'x' |
@@ -215,12 +215,51 @@ 'use strict'; | ||
data = _this3.setMessageDuration(data); | ||
if (data.onShow) { | ||
data.onShow(data); | ||
} | ||
_this3.triggerEvent(data, 'messageOpen'); | ||
}); | ||
}; | ||
HermesComponent.prototype.triggerEvent = function triggerEvent(message, eventName) { | ||
eventName = 'on' + eventName.charAt(0).toUpperCase() + eventName.slice(1); | ||
var exec = function exec(message, eventName, container) { | ||
if (container[eventName]) { | ||
try { | ||
container[eventName](message); | ||
} catch (e) { | ||
console.error('Failed on callback for ' + eventName + '\nError Message: ' + (e.message || e) + ' for the message: ', message); | ||
} | ||
} | ||
}; | ||
exec(message, eventName, message); | ||
exec(message, eventName, this.props); | ||
if (eventName === 'onMessageUpdate' || eventName === 'onMessageOpen') { | ||
switch (message.type) { | ||
case 'error': | ||
case 'fail': | ||
exec(message, 'onError', message); | ||
exec(message, 'onError', this.props); | ||
break; | ||
case 'warn': | ||
case 'warning': | ||
exec(message, 'onWarning', message); | ||
exec(message, 'onWarning', this.props); | ||
break; | ||
case 'info': | ||
exec(message, 'onInfo', message); | ||
exec(message, 'onInfo', this.props); | ||
break; | ||
case 'success': | ||
case 'ok': | ||
exec(message, 'onSuccess', message); | ||
exec(message, 'onSuccess', this.props); | ||
break; | ||
} | ||
} | ||
}; | ||
HermesComponent.prototype.updateMessage = function updateMessage(id, data) { | ||
var _this4 = this; | ||
var list = this.state.messages; | ||
if (id && list[id]) { | ||
var message = list[id]; | ||
var oldMessage = Object.assign({}, list[id]); | ||
if (data.animate !== false && this.props.animate) { | ||
@@ -241,2 +280,7 @@ data.animate = true; | ||
messages: list | ||
}, function (_) { | ||
_this4.triggerEvent({ | ||
prev: oldMessage, | ||
next: message | ||
}, 'messageUpdate'); | ||
}); | ||
@@ -250,3 +294,3 @@ } else { | ||
HermesComponent.prototype.removeMessageElement = function removeMessageElement(data) { | ||
var _this4 = this; | ||
var _this5 = this; | ||
@@ -259,3 +303,3 @@ var id = data && data.id ? data.id : data; | ||
}, function (_) { | ||
_this4.updateTitleCounter(); | ||
_this5.updateTitleCounter(); | ||
if (data.to) { | ||
@@ -268,3 +312,3 @@ clearTimeout(data.to); | ||
HermesComponent.prototype.removeMessage = function removeMessage(data) { | ||
var _this5 = this; | ||
var _this6 = this; | ||
@@ -279,3 +323,4 @@ var id = data && data.id ? data.id : data; | ||
setTimeout(function (_) { | ||
_this5.removeMessageElement(data); | ||
_this6.triggerEvent(data, 'messageClose'); | ||
_this6.removeMessageElement(data); | ||
}, 1000); | ||
@@ -291,3 +336,3 @@ }); | ||
HermesComponent.prototype.render = function render() { | ||
var _this6 = this; | ||
var _this7 = this; | ||
@@ -299,3 +344,3 @@ var notifs = Object.keys(this.state.messages); | ||
notifs.map(function (messageId, i) { | ||
var message = _this6.state.messages[messageId]; | ||
var message = _this7.state.messages[messageId]; | ||
var order = notifs.length - i; | ||
@@ -317,3 +362,3 @@ return message ? _react2.default.createElement( | ||
onClick: function onClick(event) { | ||
return _this6.removeMessage(message); | ||
return _this7.removeMessage(message); | ||
} }, | ||
@@ -320,0 +365,0 @@ 'x' |
{ | ||
"name": "reactive-hermes", | ||
"version": "1.1.4", | ||
"version": "1.1.5", | ||
"description": "A notification manager for react. Animated, customizable, light and cleaner, allows you to controll duration, sound, and even use other react components inside of messages.", | ||
@@ -21,2 +21,4 @@ "main": "lib/index.js", | ||
}, | ||
"repository": "https://github.com/NascHQ/reactive-hermes", | ||
"bugs": "https://github.com/NascHQ/reactive-hermes/issues", | ||
"dependencies": {}, | ||
@@ -32,9 +34,14 @@ "peerDependencies": { | ||
}, | ||
"author": "", | ||
"author": "https://nasc.io/", | ||
"homepage": "", | ||
"license": "MIT", | ||
"repository": "", | ||
"keywords": [ | ||
"react-component" | ||
"react-component", | ||
"message", | ||
"notification", | ||
"tool", | ||
"animated", | ||
"audio", | ||
"multiple" | ||
] | ||
} |
@@ -82,2 +82,3 @@ # Hermes, the notifier | ||
- _Hermes.updateMessage(Object)_ | ||
@@ -103,2 +104,14 @@ Allows you to update an existing message. If the message is not opened, it will be shown. | ||
### Events | ||
You can use this events in the one tag for the _HermesComponent_, so, the listener will be called everytime any message triggers the given event. Or you can pass the eventListener on each individual message to listen for only its event. | ||
- **onMessageOpen**: Will be trigger after ending the message animation for showing the message. | ||
- **onMessageClose**: Will be trigger after ending the message animation for closing the message. | ||
- **onMessageUpdate**: Will be trigger after updating a message. | ||
- **onInfo**: Triggered when a message of type `info` is shown. | ||
- **onWarn**: Triggered when a message of type `warn` is shown. | ||
- **onError**: Triggered when a message of type `error` is shown. | ||
- **onSuccess**: Triggered when a message of type `success` is shown. | ||
## Compatibility | ||
@@ -133,3 +146,3 @@ | ||
```js | ||
let message = 'Something is out of order'; | ||
let message = 'Something is out of order!'; | ||
Hermes.fail(message); | ||
@@ -136,0 +149,0 @@ Hermes.error(message); |
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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
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
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
1642672
932
2
251