Started adding frontend notifications, fixing firefox file upload bug

This commit is contained in:
2018-01-22 19:03:06 -05:00
parent f14e96c490
commit 5856052f82
1536 changed files with 109746 additions and 2658 deletions

View File

@@ -0,0 +1,33 @@
const eventManager = {
eventList: new Map(),
on(event, callback) {
this.eventList.has(event) || this.eventList.set(event, []);
this.eventList.get(event).push(callback);
return this;
},
off(event = null) {
return this.eventList.delete(event);
},
emit(event, ...args) {
if (!this.eventList.has(event)) {
/* eslint no-console: 0 */
console.warn(
`<${event}> Event is not registered. Did you forgot to bind the event ?`
);
return false;
}
this.eventList
.get(event)
.forEach(callback => setTimeout(() => callback.call(this, ...args), 0));
return true;
}
};
export default eventManager;

View File

@@ -0,0 +1,45 @@
import { isValidElement } from 'react';
export function isValidDelay(val) {
return typeof val === 'number' && !isNaN(val) && val > 0;
}
export function objectValues(obj) {
return Object.keys(obj).map(key => obj[key]);
}
function withRequired(fn) {
fn.isRequired = function(props, propName, componentName) {
const prop = props[propName];
if (typeof prop === 'undefined') {
return new Error(`The prop ${propName} is marked as required in
${componentName}, but its value is undefined.`);
}
fn(props, propName, componentName);
};
return fn;
}
export const falseOrDelay = withRequired((props, propName, componentName) => {
const prop = props[propName];
if (prop !== false && !isValidDelay(prop)) {
return new Error(`${componentName} expect ${propName}
to be a valid Number > 0 or equal to false. ${prop} given.`);
}
return null;
});
export const falseOrElement = withRequired((props, propName, componentName) => {
const prop = props[propName];
if (prop !== false && !isValidElement(prop)) {
return new Error(`${componentName} expect ${propName}
to be a valid react element or equal to false. ${prop} given.`);
}
return null;
});