@enact/core
Advanced tools
Comparing version 1.13.3 to 1.13.4
@@ -5,2 +5,6 @@ # Change Log | ||
## [1.13.4] - 2018-07-30 | ||
No significant changes. | ||
## [1.13.3] - 2017-01-16 | ||
@@ -7,0 +11,0 @@ |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,15 +6,17 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
exports.once = exports.on = exports.off = undefined; | ||
exports.once = exports.on = exports.off = void 0; | ||
var _curry = require('ramda/src/curry'); | ||
var _curry = _interopRequireDefault(require("ramda/src/curry")); | ||
var _curry2 = _interopRequireDefault(_curry); | ||
var _listeners = _interopRequireDefault(require("./listeners")); | ||
var _listeners = require('./listeners'); | ||
var _listeners2 = _interopRequireDefault(_listeners); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/** | ||
* Provides methods to add and remove global event listeners | ||
* | ||
* @module core/dispatcher | ||
*/ | ||
/** | ||
* Checks if the default target of `document` exists before returning it, otherwise returns `false`. | ||
@@ -26,12 +28,5 @@ * | ||
*/ | ||
/** | ||
* Provides methods to add and remove global event listeners | ||
* | ||
* @module core/dispatcher | ||
*/ | ||
var getDefaultTarget = function getDefaultTarget() { | ||
return typeof document !== 'undefined' && document; | ||
}; | ||
/** | ||
@@ -48,3 +43,5 @@ * Wraps event callbacks with a try-catch block to prevent unrelated code from blocking | ||
*/ | ||
var invoker = (0, _curry2.default)(function (ev, fn) { | ||
var invoker = (0, _curry.default)(function (ev, fn) { | ||
try { | ||
@@ -54,6 +51,5 @@ fn(ev); | ||
// eslint-disable-next-line no-console | ||
console.error('A ' + e.name + ' occurred during event handling with the message \'' + e.message + '\''); | ||
console.error("A ".concat(e.name, " occurred during event handling with the message '").concat(e.message, "'")); | ||
} | ||
}); | ||
/** | ||
@@ -69,5 +65,6 @@ * Dispatches an event to the registered handlers | ||
*/ | ||
var dispatcher = function dispatcher(ev) { | ||
var name = ev.type; | ||
var listeners = (0, _listeners2.default)(ev.currentTarget, name); | ||
var listeners = (0, _listeners.default)(ev.currentTarget, name); | ||
@@ -79,3 +76,2 @@ if (listeners) { | ||
}; | ||
/** | ||
@@ -92,2 +88,4 @@ * Adds a new global event listener | ||
*/ | ||
var on = function on(name, fn) { | ||
@@ -97,5 +95,5 @@ var target = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : getDefaultTarget(); | ||
if (target) { | ||
var listeners = (0, _listeners2.default)(target, name); | ||
var listeners = (0, _listeners.default)(target, name); | ||
var length = listeners.push(fn); | ||
var length = listeners.push(fn); | ||
if (length === 1) { | ||
@@ -106,3 +104,2 @@ target.addEventListener(name, dispatcher); | ||
}; | ||
/** | ||
@@ -119,2 +116,6 @@ * Removes a global event listener | ||
*/ | ||
exports.on = on; | ||
var off = function off(name, fn) { | ||
@@ -124,3 +125,3 @@ var target = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : getDefaultTarget(); | ||
if (target) { | ||
var listeners = (0, _listeners2.default)(target, name); | ||
var listeners = (0, _listeners.default)(target, name); | ||
var index = listeners.indexOf(fn); | ||
@@ -130,2 +131,3 @@ | ||
listeners.splice(index, 1); | ||
if (listeners.length === 0) { | ||
@@ -137,3 +139,2 @@ target.removeEventListener(name, dispatcher); | ||
}; | ||
/** | ||
@@ -151,2 +152,6 @@ * Adds a new global event listener that removes itself after handling one event | ||
*/ | ||
exports.off = off; | ||
var once = function once(name, fn, target) { | ||
@@ -159,8 +164,5 @@ var onceFn = function onceFn(ev) { | ||
on(name, onceFn, target); | ||
return onceFn; | ||
}; | ||
exports.off = off; | ||
exports.on = on; | ||
exports.once = once; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
value: true | ||
}); | ||
exports.getListeners = exports.default = void 0; | ||
// Simple Map polyfill mapping targets to a hash of names->handler[] | ||
@@ -11,11 +12,14 @@ var targets = []; | ||
var getListeners = function getListeners(target, name) { | ||
var targetIndex = targets.indexOf(target); | ||
if (targetIndex === -1) { | ||
targetIndex = targets.push(target) - 1; | ||
} | ||
var listeners = events[targetIndex] = events[targetIndex] || {}; | ||
return listeners[name] = listeners[name] || []; | ||
var targetIndex = targets.indexOf(target); | ||
if (targetIndex === -1) { | ||
targetIndex = targets.push(target) - 1; | ||
} | ||
var listeners = events[targetIndex] = events[targetIndex] || {}; | ||
return listeners[name] = listeners[name] || []; | ||
}; | ||
exports.default = getListeners; | ||
exports.getListeners = getListeners; | ||
exports.getListeners = getListeners; | ||
var _default = getListeners; | ||
exports.default = _default; |
@@ -1,97 +0,81 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _sinon = require('sinon'); | ||
var _sinon = _interopRequireDefault(require("sinon")); | ||
var _sinon2 = _interopRequireDefault(_sinon); | ||
var _consoleSnoop = require("console-snoop"); | ||
var _consoleSnoop = require('console-snoop'); | ||
var _dispatcher = require("../dispatcher"); | ||
var _dispatcher = require('../dispatcher'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/* global CustomEvent */ | ||
describe('dispatcher', function () { | ||
it('should register handlers on target', function () { | ||
var handler = _sinon.default.spy(); | ||
it('should register handlers on target', function () { | ||
var handler = _sinon2.default.spy(); | ||
(0, _dispatcher.on)('localechange', handler, window); | ||
(0, _dispatcher.on)('localechange', handler, window); | ||
var ev = new CustomEvent('localechange', {}); | ||
window.dispatchEvent(ev); | ||
var expected = true; | ||
var actual = handler.calledOnce; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should unregister handlers on target', function () { | ||
var handler = _sinon.default.spy(); | ||
var ev = new CustomEvent('localechange', {}); | ||
window.dispatchEvent(ev); | ||
(0, _dispatcher.on)('localechange', handler, window); | ||
var ev = new CustomEvent('localechange', {}); | ||
window.dispatchEvent(ev); | ||
(0, _dispatcher.off)('localechange', handler, window); | ||
window.dispatchEvent(ev); | ||
var expected = false; | ||
var actual = handler.calledTwice; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should only call a "once" handler once', function () { | ||
var handler = _sinon.default.spy(); | ||
var expected = true; | ||
var actual = handler.calledOnce; | ||
(0, _dispatcher.once)('localechange', handler, window); | ||
var ev = new CustomEvent('localechange', {}); | ||
window.dispatchEvent(ev); | ||
window.dispatchEvent(ev); | ||
var expected = true; | ||
var actual = handler.calledOnce; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should allow unregistering a "once" before it is called', function () { | ||
var handler = _sinon.default.spy(); | ||
expect(actual).to.equal(expected); | ||
}); | ||
var onceHandler = (0, _dispatcher.once)('localechange', handler, window); | ||
(0, _dispatcher.off)('localechange', onceHandler, window); | ||
var ev = new CustomEvent('localechange', {}); | ||
window.dispatchEvent(ev); | ||
var expected = false; | ||
var actual = handler.calledOnce; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should not block subsequent handlers when a handler throws', function () { | ||
// clear enyo-console-spy so we can stub it to suppress the console.error | ||
(0, _consoleSnoop.restoreErrorAndWarnings)(); | ||
it('should unregister handlers on target', function () { | ||
var handler = _sinon2.default.spy(); | ||
(0, _dispatcher.on)('localechange', handler, window); | ||
_sinon.default.stub(console, 'error'); | ||
var ev = new CustomEvent('localechange', {}); | ||
window.dispatchEvent(ev); | ||
var throws = function throws() { | ||
throw new Error('Thrown from handler'); | ||
}; | ||
(0, _dispatcher.off)('localechange', handler, window); | ||
window.dispatchEvent(ev); | ||
var handler = _sinon.default.spy(); | ||
var expected = false; | ||
var actual = handler.calledTwice; | ||
(0, _dispatcher.on)('localechange', throws, window); | ||
(0, _dispatcher.on)('localechange', handler, window); | ||
var ev = new CustomEvent('localechange', {}); | ||
window.dispatchEvent(ev); // restore console.error and set up enyo-console-spy again so it can complete successfully | ||
// eslint-disable-next-line no-console | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should only call a "once" handler once', function () { | ||
var handler = _sinon2.default.spy(); | ||
(0, _dispatcher.once)('localechange', handler, window); | ||
var ev = new CustomEvent('localechange', {}); | ||
window.dispatchEvent(ev); | ||
window.dispatchEvent(ev); | ||
var expected = true; | ||
var actual = handler.calledOnce; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should allow unregistering a "once" before it is called', function () { | ||
var handler = _sinon2.default.spy(); | ||
var onceHandler = (0, _dispatcher.once)('localechange', handler, window); | ||
(0, _dispatcher.off)('localechange', onceHandler, window); | ||
var ev = new CustomEvent('localechange', {}); | ||
window.dispatchEvent(ev); | ||
var expected = false; | ||
var actual = handler.calledOnce; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should not block subsequent handlers when a handler throws', function () { | ||
// clear enyo-console-spy so we can stub it to suppress the console.error | ||
(0, _consoleSnoop.restoreErrorAndWarnings)(); | ||
_sinon2.default.stub(console, 'error'); | ||
var throws = function throws() { | ||
throw new Error('Thrown from handler'); | ||
}; | ||
var handler = _sinon2.default.spy(); | ||
(0, _dispatcher.on)('localechange', throws, window); | ||
(0, _dispatcher.on)('localechange', handler, window); | ||
var ev = new CustomEvent('localechange', {}); | ||
window.dispatchEvent(ev); | ||
// restore console.error and set up enyo-console-spy again so it can complete successfully | ||
// eslint-disable-next-line no-console | ||
console.error.restore(); | ||
(0, _consoleSnoop.watchErrorAndWarnings)(); | ||
var expected = true; | ||
var actual = handler.calledOnce; | ||
expect(actual).to.equal(expected); | ||
}); | ||
}); /* global CustomEvent */ | ||
console.error.restore(); | ||
(0, _consoleSnoop.watchErrorAndWarnings)(); | ||
var expected = true; | ||
var actual = handler.calledOnce; | ||
expect(actual).to.equal(expected); | ||
}); | ||
}); |
@@ -1,6 +0,8 @@ | ||
'use strict'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
value: true | ||
}); | ||
exports.feature = exports.default = void 0; | ||
/** | ||
@@ -16,21 +18,21 @@ * Merges the local CSS object and a CSS object from the props. When both exist, the class names are | ||
var feature = function feature(componentCss, authorCss) { | ||
if (authorCss && componentCss) { | ||
var css = Object.assign({}, componentCss); | ||
Object.keys(authorCss).forEach(function (className) { | ||
if (componentCss[className]) { | ||
css[className] = componentCss[className] + ' ' + authorCss[className]; | ||
} else { | ||
css[className] = authorCss[className]; | ||
} | ||
}); | ||
if (authorCss && componentCss) { | ||
var css = Object.assign({}, componentCss); | ||
Object.keys(authorCss).forEach(function (className) { | ||
if (componentCss[className]) { | ||
css[className] = componentCss[className] + ' ' + authorCss[className]; | ||
} else { | ||
css[className] = authorCss[className]; | ||
} | ||
}); | ||
return css; | ||
} else if (authorCss) { | ||
return Object.assign({}, authorCss); | ||
} | ||
return css; | ||
} else if (authorCss) { | ||
return Object.assign({}, authorCss); | ||
} | ||
return componentCss; | ||
return componentCss; | ||
}; | ||
exports.default = feature; | ||
exports.feature = feature; | ||
exports.feature = feature; | ||
var _default = feature; | ||
exports.default = _default; |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,11 +6,15 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
exports.factory = undefined; | ||
exports.factory = exports.default = void 0; | ||
var _css = require('./css'); | ||
var _css = _interopRequireDefault(require("./css")); | ||
var _css2 = _interopRequireDefault(_css); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/** | ||
* Exports the {@link core/factory.factory} function for creating customizeable components. | ||
* | ||
* @module core/factory | ||
*/ | ||
/** | ||
* Invokes a factory feature | ||
@@ -31,3 +35,2 @@ * | ||
}; | ||
/** | ||
@@ -88,8 +91,4 @@ * Creates a factory function which reconciles a default configuration object (`defaultConfig`) and | ||
*/ | ||
/** | ||
* Exports the {@link core/factory.factory} function for creating customizeable components. | ||
* | ||
* @module core/factory | ||
*/ | ||
var factory = function factory(defaultConfig, fn) { | ||
@@ -99,5 +98,4 @@ return function (config) { | ||
var authorConfig = config; | ||
var factoryFn = fn; | ||
var factoryFn = fn; // support omitting defaultConfig | ||
// support omitting defaultConfig | ||
if (typeof defaultConfig === 'function') { | ||
@@ -109,3 +107,3 @@ factoryFn = defaultConfig; | ||
return factoryFn({ | ||
css: feature('css', _css2.default, componentConfig, authorConfig) | ||
css: feature('css', _css.default, componentConfig, authorConfig) | ||
}); | ||
@@ -115,3 +113,4 @@ }; | ||
exports.default = factory; | ||
exports.factory = factory; | ||
exports.factory = factory; | ||
var _default = factory; | ||
exports.default = _default; |
@@ -1,38 +0,30 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _css = require('../css'); | ||
var _css = _interopRequireDefault(require("../css")); | ||
var _css2 = _interopRequireDefault(_css); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
describe('css feature', function () { | ||
var componentCss = { | ||
button: 'component-button', | ||
inner: 'component-inner' | ||
}; | ||
it('should merge component and author css objects', function () { | ||
var authorCss = { | ||
other: 'author-other' | ||
}; | ||
var updated = (0, _css2.default)(componentCss, authorCss); | ||
var expected = ['button', 'inner', 'other']; | ||
var actual = Object.keys(updated); | ||
expect(actual).to.deep.equal(expected); | ||
}); | ||
it('should join class names that exist in both component and author css objects', function () { | ||
var authorCss = { | ||
button: 'author-button' | ||
}; | ||
var updated = (0, _css2.default)(componentCss, authorCss); | ||
var expected = componentCss.button + ' author-button'; | ||
var actual = updated.button; | ||
expect(actual).to.equal(expected); | ||
}); | ||
var componentCss = { | ||
button: 'component-button', | ||
inner: 'component-inner' | ||
}; | ||
it('should merge component and author css objects', function () { | ||
var authorCss = { | ||
other: 'author-other' | ||
}; | ||
var updated = (0, _css.default)(componentCss, authorCss); | ||
var expected = ['button', 'inner', 'other']; | ||
var actual = Object.keys(updated); | ||
expect(actual).to.deep.equal(expected); | ||
}); | ||
it('should join class names that exist in both component and author css objects', function () { | ||
var authorCss = { | ||
button: 'author-button' | ||
}; | ||
var updated = (0, _css.default)(componentCss, authorCss); | ||
var expected = componentCss.button + ' author-button'; | ||
var actual = updated.button; | ||
expect(actual).to.equal(expected); | ||
}); | ||
}); |
@@ -1,56 +0,46 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _sinon = require('sinon'); | ||
var _sinon = _interopRequireDefault(require("sinon")); | ||
var _sinon2 = _interopRequireDefault(_sinon); | ||
var _factory = _interopRequireDefault(require("../factory")); | ||
var _factory = require('../factory'); | ||
var _factory2 = _interopRequireDefault(_factory); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
describe('factory', function () { | ||
it('should allow omitting the component config', function () { | ||
var fn = _sinon.default.spy(); | ||
it('should allow omitting the component config', function () { | ||
var fn = _sinon2.default.spy(); | ||
var fnFactory = (0, _factory2.default)(fn); | ||
fnFactory(); | ||
var fnFactory = (0, _factory.default)(fn); | ||
fnFactory(); | ||
var expected = true; | ||
var actual = fn.calledOnce; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should pass through author config when omitting the component config', function () { | ||
var fn = _sinon.default.spy(); | ||
var expected = true; | ||
var actual = fn.calledOnce; | ||
var config = { | ||
css: { | ||
button: 'author-button', | ||
inner: 'author-inner' | ||
} | ||
}; | ||
var fnFactory = (0, _factory.default)(fn); | ||
fnFactory(config); | ||
var expected = config; | ||
var actual = fn.firstCall.args[0]; | ||
expect(actual).to.deep.equal(expected); | ||
}); | ||
it('should only pass supported keys to function', function () { | ||
var fn = _sinon.default.spy(); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should pass through author config when omitting the component config', function () { | ||
var fn = _sinon2.default.spy(); | ||
var config = { | ||
css: { | ||
button: 'author-button', | ||
inner: 'author-inner' | ||
} | ||
}; | ||
var fnFactory = (0, _factory2.default)(fn); | ||
fnFactory(config); | ||
var expected = config; | ||
var actual = fn.firstCall.args[0]; | ||
expect(actual).to.deep.equal(expected); | ||
}); | ||
it('should only pass supported keys to function', function () { | ||
var fn = _sinon2.default.spy(); | ||
var config = { | ||
unsupportedKey: true | ||
}; | ||
var fnFactory = (0, _factory2.default)(fn); | ||
fnFactory(config); | ||
var expected = 'unsupportedKey'; | ||
var actual = Object.keys(fn.firstCall.args[0]); | ||
expect(actual).to.not.contain(expected); | ||
}); | ||
var config = { | ||
unsupportedKey: true | ||
}; | ||
var fnFactory = (0, _factory.default)(fn); | ||
fnFactory(config); | ||
var expected = 'unsupportedKey'; | ||
var actual = Object.keys(fn.firstCall.args[0]); | ||
expect(actual).to.not.contain(expected); | ||
}); | ||
}); |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,53 +6,28 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
exports.stopImmediate = exports.stop = exports.preventDefault = exports.oneOf = exports.log = exports.handle = exports.forProp = exports.forKeyCode = exports.forKey = exports.forEventProp = exports.forwardWithPrevent = exports.forward = exports.callOnEvent = undefined; | ||
exports.stopImmediate = exports.stop = exports.preventDefault = exports.oneOf = exports.log = exports.handle = exports.forProp = exports.forKeyCode = exports.forKey = exports.forEventProp = exports.forwardWithPrevent = exports.forward = exports.callOnEvent = exports.default = void 0; | ||
var _allPass = require('ramda/src/allPass'); | ||
var _allPass = _interopRequireDefault(require("ramda/src/allPass")); | ||
var _allPass2 = _interopRequireDefault(_allPass); | ||
var _always = _interopRequireDefault(require("ramda/src/always")); | ||
var _always = require('ramda/src/always'); | ||
var _compose = _interopRequireDefault(require("ramda/src/compose")); | ||
var _always2 = _interopRequireDefault(_always); | ||
var _cond = _interopRequireDefault(require("ramda/src/cond")); | ||
var _compose = require('ramda/src/compose'); | ||
var _curry = _interopRequireDefault(require("ramda/src/curry")); | ||
var _compose2 = _interopRequireDefault(_compose); | ||
var _identity = _interopRequireDefault(require("ramda/src/identity")); | ||
var _cond = require('ramda/src/cond'); | ||
var _ifElse = _interopRequireDefault(require("ramda/src/ifElse")); | ||
var _cond2 = _interopRequireDefault(_cond); | ||
var _is = _interopRequireDefault(require("ramda/src/is")); | ||
var _curry = require('ramda/src/curry'); | ||
var _map = _interopRequireDefault(require("ramda/src/map")); | ||
var _curry2 = _interopRequireDefault(_curry); | ||
var _T = _interopRequireDefault(require("ramda/src/T")); | ||
var _identity = require('ramda/src/identity'); | ||
var _keymap = require("../keymap"); | ||
var _identity2 = _interopRequireDefault(_identity); | ||
var _ifElse = require('ramda/src/ifElse'); | ||
var _ifElse2 = _interopRequireDefault(_ifElse); | ||
var _is = require('ramda/src/is'); | ||
var _is2 = _interopRequireDefault(_is); | ||
var _map = require('ramda/src/map'); | ||
var _map2 = _interopRequireDefault(_map); | ||
var _T = require('ramda/src/T'); | ||
var _T2 = _interopRequireDefault(_T); | ||
var _keymap = require('../keymap'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
// Ensures that everything passed to `allPass` is a function so that if null values are passed they | ||
// do not impede the event flow | ||
var makeSafeHandler = (0, _ifElse2.default)((0, _is2.default)(Function), _identity2.default, (0, _always2.default)(_T2.default)); | ||
// Accepts an array of handlers, sanitizes them, and returns a handler function | ||
/** | ||
@@ -113,5 +88,7 @@ * `core/handle` provides a set of utilities to support handling events for `kind()`s and | ||
*/ | ||
// Ensures that everything passed to `allPass` is a function so that if null values are passed they | ||
// do not impede the event flow | ||
var makeSafeHandler = (0, _ifElse.default)((0, _is.default)(Function), _identity.default, (0, _always.default)(_T.default)); // Accepts an array of handlers, sanitizes them, and returns a handler function | ||
var makeHandler = (0, _compose2.default)(_allPass2.default, (0, _map2.default)(makeSafeHandler)); | ||
var makeHandler = (0, _compose.default)(_allPass.default, (0, _map.default)(makeSafeHandler)); | ||
/** | ||
@@ -127,6 +104,7 @@ * Allows generating event handlers by chaining input functions to filter or short-circuit the | ||
*/ | ||
var handle = function handle() { | ||
var _this = this; | ||
for (var _len = arguments.length, handlers = Array(_len), _key = 0; _key < _len; _key++) { | ||
for (var _len = arguments.length, handlers = new Array(_len), _key = 0; _key < _len; _key++) { | ||
handlers[_key] = arguments[_key]; | ||
@@ -137,3 +115,2 @@ } | ||
h.displayName = 'handle'; | ||
return function (ev, props, context) { | ||
@@ -150,3 +127,2 @@ // if handle() was bound to a class, use its props and context. otherwise, we accept | ||
}; | ||
/** | ||
@@ -171,10 +147,13 @@ * Calls the first handler whose condition passes. Each branch must be passed as an array with the | ||
*/ | ||
exports.handle = handle; | ||
var oneOf = handle.oneOf = function () { | ||
for (var _len2 = arguments.length, handlers = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
for (var _len2 = arguments.length, handlers = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
handlers[_key2] = arguments[_key2]; | ||
} | ||
return (0, _cond2.default)(handlers); | ||
return (0, _cond.default)(handlers); | ||
}; | ||
/** | ||
@@ -199,3 +178,6 @@ * Calls a named function on the event and returns `true` | ||
*/ | ||
var callOnEvent = handle.callOnEvent = (0, _curry2.default)(function (methodName, ev) { | ||
exports.oneOf = oneOf; | ||
var callOnEvent = handle.callOnEvent = (0, _curry.default)(function (methodName, ev) { | ||
if (ev[methodName]) { | ||
@@ -208,5 +190,5 @@ ev[methodName](); | ||
} | ||
return true; | ||
}); | ||
/** | ||
@@ -231,6 +213,7 @@ * Allows handling to continue if the value of `prop` on the event strictly equals `value` | ||
*/ | ||
var forEventProp = handle.forEventProp = (0, _curry2.default)(function (prop, value, ev) { | ||
exports.callOnEvent = callOnEvent; | ||
var forEventProp = handle.forEventProp = (0, _curry.default)(function (prop, value, ev) { | ||
return ev[prop] === value; | ||
}); | ||
/** | ||
@@ -257,4 +240,7 @@ * Forwards the event to a function at `name` on `props`. If the specified prop is `undefined` or | ||
*/ | ||
var forward = handle.forward = (0, _curry2.default)(function (name, ev, props) { | ||
exports.forEventProp = forEventProp; | ||
var forward = handle.forward = (0, _curry.default)(function (name, ev, props) { | ||
var fn = props && props[name]; | ||
if (typeof fn === 'function') { | ||
@@ -266,3 +252,2 @@ fn(ev); | ||
}); | ||
/** | ||
@@ -285,4 +270,6 @@ * Calls `event.preventDefault()` and returns `true`. | ||
*/ | ||
exports.forward = forward; | ||
var _preventDefault = handle.preventDefault = callOnEvent('preventDefault'); | ||
/** | ||
@@ -310,3 +297,6 @@ * Forwards the event to a function at `name` on `props` with capability to prevent default | ||
*/ | ||
var forwardWithPrevent = handle.forwardWithPrevent = (0, _curry2.default)(function (name, ev, props) { | ||
exports.preventDefault = _preventDefault; | ||
var forwardWithPrevent = handle.forwardWithPrevent = (0, _curry.default)(function (name, ev, props) { | ||
var prevented = false; | ||
@@ -316,2 +306,3 @@ var wrappedEvent = Object.assign({}, ev, { | ||
prevented = true; | ||
_preventDefault(ev); | ||
@@ -321,6 +312,4 @@ } | ||
forward(name, wrappedEvent, props); | ||
return !prevented; | ||
}); | ||
/** | ||
@@ -343,4 +332,5 @@ * Calls `event.stopPropagation()` and returns `true` | ||
*/ | ||
exports.forwardWithPrevent = forwardWithPrevent; | ||
var stop = handle.stop = callOnEvent('stopPropagation'); | ||
/** | ||
@@ -363,4 +353,5 @@ * Calls `event.stopImmediatePropagation()` and returns `true` | ||
*/ | ||
exports.stop = stop; | ||
var stopImmediate = handle.stopImmediate = callOnEvent('stopImmediatePropagation'); | ||
/** | ||
@@ -384,4 +375,5 @@ * Allows event handling to continue if `event.keyCode === value`. | ||
*/ | ||
exports.stopImmediate = stopImmediate; | ||
var forKeyCode = handle.forKeyCode = forEventProp('keyCode'); | ||
/** | ||
@@ -407,6 +399,7 @@ * Allows handling to continue if the event's keyCode is mapped to `name` within | ||
*/ | ||
var forKey = handle.forKey = (0, _curry2.default)(function (name, ev) { | ||
exports.forKeyCode = forKeyCode; | ||
var forKey = handle.forKey = (0, _curry.default)(function (name, ev) { | ||
return (0, _keymap.is)(name, ev.keyCode); | ||
}); | ||
/** | ||
@@ -432,6 +425,7 @@ * Allows handling to continue if the value of `prop` on the props strictly equals `value`. | ||
*/ | ||
var forProp = handle.forProp = (0, _curry2.default)(function (prop, value, ev, props) { | ||
exports.forKey = forKey; | ||
var forProp = handle.forProp = (0, _curry.default)(function (prop, value, ev, props) { | ||
return props[prop] === value; | ||
}); | ||
/** | ||
@@ -458,10 +452,12 @@ * Logs the event, props, and context optionally preceded by a custom message. Will only log in | ||
*/ | ||
var log = handle.log = (0, _curry2.default)(function (message, ev) { | ||
for (var _len3 = arguments.length, args = Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) { | ||
args[_key3 - 2] = arguments[_key3]; | ||
} | ||
if (process.env.NODE_ENV !== 'production') { | ||
exports.forProp = forProp; | ||
var log = handle.log = (0, _curry.default)(function (message, ev) { | ||
if (process.env.NODE_ENV !== "production") { | ||
var _console; | ||
for (var _len3 = arguments.length, args = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) { | ||
args[_key3 - 2] = arguments[_key3]; | ||
} | ||
// eslint-disable-next-line no-console | ||
@@ -473,16 +469,4 @@ (_console = console).log.apply(_console, [message, ev].concat(args)); | ||
}); | ||
exports.default = handle; | ||
exports.callOnEvent = callOnEvent; | ||
exports.forward = forward; | ||
exports.forwardWithPrevent = forwardWithPrevent; | ||
exports.forEventProp = forEventProp; | ||
exports.forKey = forKey; | ||
exports.forKeyCode = forKeyCode; | ||
exports.forProp = forProp; | ||
exports.handle = handle; | ||
exports.log = log; | ||
exports.oneOf = oneOf; | ||
exports.preventDefault = _preventDefault; | ||
exports.stop = stop; | ||
exports.stopImmediate = stopImmediate; | ||
var _default = handle; | ||
exports.default = _default; |
@@ -1,320 +0,289 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var _sinon = _interopRequireDefault(require("sinon")); | ||
var _sinon = require('sinon'); | ||
var _handle = require("../handle"); | ||
var _sinon2 = _interopRequireDefault(_sinon); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _handle = require('../handle'); | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
describe('handle', function () { | ||
var makeEvent = function makeEvent(payload) { | ||
return _objectSpread({ | ||
preventDefault: _sinon.default.spy(), | ||
stopPropagation: _sinon.default.spy() | ||
}, payload); | ||
}; | ||
var makeEvent = function makeEvent(payload) { | ||
return _extends({ | ||
preventDefault: _sinon2.default.spy(), | ||
stopPropagation: _sinon2.default.spy() | ||
}, payload); | ||
}; | ||
var returnsTrue = function returnsTrue() { | ||
return true; | ||
}; | ||
var returnsTrue = function returnsTrue() { | ||
return true; | ||
}; | ||
var returnsFalse = function returnsFalse() { | ||
return false; | ||
}; | ||
var returnsFalse = function returnsFalse() { | ||
return false; | ||
}; | ||
it('should call only handler', function () { | ||
var handler = _sinon2.default.spy(returnsTrue); | ||
var callback = (0, _handle.handle)(handler); | ||
it('should call only handler', function () { | ||
var handler = _sinon.default.spy(returnsTrue); | ||
callback(makeEvent()); | ||
var callback = (0, _handle.handle)(handler); | ||
callback(makeEvent()); | ||
var expected = true; | ||
var actual = handler.calledOnce; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should call multiple handlers', function () { | ||
var handler1 = _sinon.default.spy(returnsTrue); | ||
var expected = true; | ||
var actual = handler.calledOnce; | ||
var handler2 = _sinon.default.spy(returnsTrue); | ||
expect(actual).to.equal(expected); | ||
}); | ||
var callback = (0, _handle.handle)(handler1, handler2); | ||
callback(makeEvent()); | ||
var expected = true; | ||
var actual = handler1.calledOnce && handler2.calledOnce; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should skip non-function handlers', function () { | ||
var handler = _sinon.default.spy(returnsTrue); | ||
it('should call multiple handlers', function () { | ||
var handler1 = _sinon2.default.spy(returnsTrue); | ||
var handler2 = _sinon2.default.spy(returnsTrue); | ||
var callback = (0, _handle.handle)(null, void 0, 0, 'purple', handler); | ||
callback(makeEvent()); | ||
var expected = true; | ||
var actual = handler.calledOnce; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should not call handlers after one that returns false', function () { | ||
var handler1 = _sinon.default.spy(returnsTrue); | ||
var callback = (0, _handle.handle)(handler1, handler2); | ||
var handler2 = _sinon.default.spy(returnsTrue); | ||
callback(makeEvent()); | ||
var callback = (0, _handle.handle)(handler1, returnsFalse, handler2); | ||
callback(makeEvent()); | ||
var expected = false; | ||
var actual = handler2.calledOnce; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should call stopPropagation on event', function () { | ||
var callback = (0, _handle.handle)(_handle.stop); | ||
var ev = makeEvent(); | ||
callback(ev); | ||
var expected = true; | ||
var actual = ev.stopPropagation.calledOnce; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should call preventDefault on event', function () { | ||
var callback = (0, _handle.handle)(_handle.preventDefault); | ||
var ev = makeEvent(); | ||
callback(ev); | ||
var expected = true; | ||
var actual = ev.preventDefault.calledOnce; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should call any method on event', function () { | ||
var callback = (0, _handle.handle)((0, _handle.callOnEvent)('customMethod')); | ||
var ev = makeEvent({ | ||
customMethod: _sinon.default.spy() | ||
}); | ||
callback(ev); | ||
var expected = true; | ||
var actual = ev.customMethod.calledOnce; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should only call handler for specified keyCode', function () { | ||
var keyCode = 13; | ||
var expected = true; | ||
var actual = handler1.calledOnce && handler2.calledOnce; | ||
var handler = _sinon.default.spy(); | ||
expect(actual).to.equal(expected); | ||
}); | ||
var callback = (0, _handle.handle)((0, _handle.forKeyCode)(keyCode), handler); | ||
callback(makeEvent()); | ||
expect(handler.calledOnce).to.equal(false); | ||
callback(makeEvent({ | ||
keyCode: keyCode | ||
})); | ||
expect(handler.calledOnce).to.equal(true); | ||
}); | ||
it('should only call handler for specified event prop', function () { | ||
var prop = 'index'; | ||
var value = 0; | ||
it('should skip non-function handlers', function () { | ||
var handler = _sinon2.default.spy(returnsTrue); | ||
var callback = (0, _handle.handle)(null, void 0, 0, 'purple', handler); | ||
var handler = _sinon.default.spy(); | ||
callback(makeEvent()); | ||
var callback = (0, _handle.handle)((0, _handle.forEventProp)(prop, value), handler); // undefined shouldn't pass | ||
var expected = true; | ||
var actual = handler.calledOnce; | ||
callback(makeEvent()); | ||
expect(handler.calledOnce).to.equal(false); // == check shouldn't pass | ||
expect(actual).to.equal(expected); | ||
}); | ||
callback(makeEvent(_defineProperty({}, prop, false))); | ||
expect(handler.calledOnce).to.equal(false); // === should pass | ||
it('should not call handlers after one that returns false', function () { | ||
var handler1 = _sinon2.default.spy(returnsTrue); | ||
var handler2 = _sinon2.default.spy(returnsTrue); | ||
callback(makeEvent(_defineProperty({}, prop, value))); | ||
expect(handler.calledOnce).to.equal(true); | ||
}); | ||
it('should only call handler for specified prop', function () { | ||
var handler = _sinon.default.spy(); | ||
var callback = (0, _handle.handle)(handler1, returnsFalse, handler2); | ||
var callback = (0, _handle.handle)((0, _handle.forProp)('checked', true), handler); // undefined shouldn't pass | ||
callback(makeEvent()); | ||
callback({}, {}); | ||
expect(handler.calledOnce).to.equal(false); // == check shouldn't pass | ||
var expected = false; | ||
var actual = handler2.calledOnce; | ||
callback({}, { | ||
checked: 1 | ||
}); | ||
expect(handler.calledOnce).to.equal(false); // === should pass | ||
expect(actual).to.equal(expected); | ||
}); | ||
callback({}, { | ||
checked: true | ||
}); | ||
expect(handler.calledOnce).to.equal(true); | ||
}); | ||
it('should forward events to function specified in provided props', function () { | ||
var event = 'onMyClick'; | ||
var prop = 'index'; | ||
var propValue = 0; | ||
it('should call stopPropagation on event', function () { | ||
var callback = (0, _handle.handle)(_handle.stop); | ||
var ev = makeEvent(); | ||
callback(ev); | ||
var spy = _sinon.default.spy(); | ||
var expected = true; | ||
var actual = ev.stopPropagation.calledOnce; | ||
var props = _defineProperty({}, event, spy); | ||
expect(actual).to.equal(expected); | ||
}); | ||
var payload = _defineProperty({}, prop, propValue); | ||
it('should call preventDefault on event', function () { | ||
var callback = (0, _handle.handle)(_handle.preventDefault); | ||
var ev = makeEvent(); | ||
callback(ev); | ||
(0, _handle.handle)((0, _handle.forward)(event))(payload, props); | ||
var expected = true; | ||
var actual = spy.args[0][0][prop] === propValue; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should forwardWithPrevent events to function specified in provided props when preventDefault() hasn\'t been called', function () { | ||
var event = 'onMyClick'; | ||
var expected = true; | ||
var actual = ev.preventDefault.calledOnce; | ||
var handler = _sinon.default.spy(); | ||
expect(actual).to.equal(expected); | ||
}); | ||
var callback = (0, _handle.handle)((0, _handle.forwardWithPrevent)(event), handler); | ||
callback(); | ||
expect(handler.calledOnce).to.equal(true); | ||
}); | ||
it('should not forwardWithPrevent events to function specified in provided props when preventDefault() has been called', function () { | ||
var event = 'onMyClick'; | ||
it('should call any method on event', function () { | ||
var callback = (0, _handle.handle)((0, _handle.callOnEvent)('customMethod')); | ||
var ev = makeEvent({ | ||
customMethod: _sinon2.default.spy() | ||
}); | ||
callback(ev); | ||
var handler = _sinon.default.spy(); | ||
var expected = true; | ||
var actual = ev.customMethod.calledOnce; | ||
var callback = (0, _handle.handle)((0, _handle.forwardWithPrevent)(event), handler); // should stop chain when `preventDefault()` has been called | ||
expect(actual).to.equal(expected); | ||
}); | ||
callback({}, { | ||
'onMyClick': function onMyClick(ev) { | ||
return ev.preventDefault(); | ||
} | ||
}); | ||
expect(handler.calledOnce).to.equal(false); | ||
}); | ||
it('should include object props as second arg when bound', function () { | ||
var componentInstance = { | ||
props: { | ||
value: 1 | ||
} | ||
}; | ||
it('should only call handler for specified keyCode', function () { | ||
var keyCode = 13; | ||
var handler = _sinon2.default.spy(); | ||
var callback = (0, _handle.handle)((0, _handle.forKeyCode)(keyCode), handler); | ||
var handler = _sinon.default.spy(); | ||
callback(makeEvent()); | ||
expect(handler.calledOnce).to.equal(false); | ||
var h = _handle.handle.bind(componentInstance); | ||
callback(makeEvent({ keyCode: keyCode })); | ||
expect(handler.calledOnce).to.equal(true); | ||
}); | ||
var callback = h(handler); | ||
callback(); | ||
var expected = 1; | ||
var actual = handler.firstCall.args[1].value; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should include object context as third arg when bound', function () { | ||
var componentInstance = { | ||
context: { | ||
value: 1 | ||
} | ||
}; | ||
it('should only call handler for specified event prop', function () { | ||
var prop = 'index'; | ||
var value = 0; | ||
var handler = _sinon2.default.spy(); | ||
var callback = (0, _handle.handle)((0, _handle.forEventProp)(prop, value), handler); | ||
var handler = _sinon.default.spy(); | ||
// undefined shouldn't pass | ||
callback(makeEvent()); | ||
expect(handler.calledOnce).to.equal(false); | ||
var h = _handle.handle.bind(componentInstance); | ||
// == check shouldn't pass | ||
callback(makeEvent(_defineProperty({}, prop, false))); | ||
expect(handler.calledOnce).to.equal(false); | ||
var callback = h(handler); | ||
callback(); | ||
var expected = 1; | ||
var actual = handler.firstCall.args[2].value; | ||
expect(actual).to.equal(expected); | ||
}); | ||
describe('#oneOf', function () { | ||
it('should call each handler until one passes', function () { | ||
var handler = _sinon.default.spy(returnsTrue); | ||
// === should pass | ||
callback(makeEvent(_defineProperty({}, prop, value))); | ||
expect(handler.calledOnce).to.equal(true); | ||
}); | ||
var h1 = [returnsFalse, handler]; | ||
var h2 = [returnsTrue, handler]; | ||
var callback = (0, _handle.oneOf)(h1, h1, h2); | ||
callback(); | ||
var expected = 1; | ||
var actual = handler.callCount; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should stop if the first handler passes', function () { | ||
var handler = _sinon.default.spy(returnsTrue); | ||
it('should only call handler for specified prop', function () { | ||
var handler = _sinon2.default.spy(); | ||
var callback = (0, _handle.handle)((0, _handle.forProp)('checked', true), handler); | ||
var callback = (0, _handle.oneOf)([returnsTrue, handler], [returnsTrue, handler], [returnsTrue, handler]); | ||
callback(); | ||
var expected = 1; | ||
var actual = handler.callCount; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should pass args to condition', function () { | ||
var handler = _sinon.default.spy(returnsTrue); | ||
// undefined shouldn't pass | ||
callback({}, {}); | ||
expect(handler.calledOnce).to.equal(false); | ||
var callback = (0, _handle.oneOf)([handler, returnsTrue]); | ||
var ev = { | ||
value: 1 | ||
}; | ||
callback(ev); | ||
var expected = ev; | ||
var actual = handler.firstCall.args[0]; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should pass args to handlers', function () { | ||
var handler = _sinon.default.spy(returnsTrue); | ||
// == check shouldn't pass | ||
callback({}, { checked: 1 }); | ||
expect(handler.calledOnce).to.equal(false); | ||
var callback = (0, _handle.oneOf)([returnsTrue, handler]); | ||
var ev = { | ||
value: 1 | ||
}; | ||
callback(ev); | ||
var expected = ev; | ||
var actual = handler.firstCall.args[0]; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should return the value from the passed condition branch', function () { | ||
var handler = _sinon.default.spy(function () { | ||
return 'ok'; | ||
}); | ||
// === should pass | ||
callback({}, { checked: true }); | ||
expect(handler.calledOnce).to.equal(true); | ||
}); | ||
var callback = (0, _handle.oneOf)([returnsTrue, handler]); | ||
var expected = callback(); | ||
var actual = 'ok'; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should support bound handlers', function () { | ||
var componentInstance = { | ||
context: { | ||
value: 1 | ||
} | ||
}; | ||
it('should forward events to function specified in provided props', function () { | ||
var event = 'onMyClick'; | ||
var prop = 'index'; | ||
var propValue = 0; | ||
var spy = _sinon2.default.spy(); | ||
var handler = _sinon.default.spy(); | ||
var props = _defineProperty({}, event, spy); | ||
var payload = _defineProperty({}, prop, propValue); | ||
var h = _handle.handle.bind(componentInstance); | ||
(0, _handle.handle)((0, _handle.forward)(event))(payload, props); | ||
var expected = true; | ||
var actual = spy.args[0][0][prop] === propValue; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should forwardWithPrevent events to function specified in provided props when preventDefault() hasn\'t been called', function () { | ||
var event = 'onMyClick'; | ||
var handler = _sinon2.default.spy(); | ||
var callback = (0, _handle.handle)((0, _handle.forwardWithPrevent)(event), handler); | ||
callback(); | ||
expect(handler.calledOnce).to.equal(true); | ||
}); | ||
it('should not forwardWithPrevent events to function specified in provided props when preventDefault() has been called', function () { | ||
var event = 'onMyClick'; | ||
var handler = _sinon2.default.spy(); | ||
var callback = (0, _handle.handle)((0, _handle.forwardWithPrevent)(event), handler); | ||
// should stop chain when `preventDefault()` has been called | ||
callback({}, { | ||
'onMyClick': function onMyClick(ev) { | ||
return ev.preventDefault(); | ||
} | ||
}); | ||
expect(handler.calledOnce).to.equal(false); | ||
}); | ||
it('should include object props as second arg when bound', function () { | ||
var componentInstance = { | ||
props: { | ||
value: 1 | ||
} | ||
}; | ||
var handler = _sinon2.default.spy(); | ||
var h = _handle.handle.bind(componentInstance); | ||
var callback = h(handler); | ||
callback(); | ||
var expected = 1; | ||
var actual = handler.firstCall.args[1].value; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should include object context as third arg when bound', function () { | ||
var componentInstance = { | ||
context: { | ||
value: 1 | ||
} | ||
}; | ||
var handler = _sinon2.default.spy(); | ||
var h = _handle.handle.bind(componentInstance); | ||
var callback = h(handler); | ||
callback(); | ||
var expected = 1; | ||
var actual = handler.firstCall.args[2].value; | ||
expect(actual).to.equal(expected); | ||
}); | ||
describe('#oneOf', function () { | ||
it('should call each handler until one passes', function () { | ||
var handler = _sinon2.default.spy(returnsTrue); | ||
var h1 = [returnsFalse, handler]; | ||
var h2 = [returnsTrue, handler]; | ||
var callback = (0, _handle.oneOf)(h1, h1, h2); | ||
callback(); | ||
var expected = 1; | ||
var actual = handler.callCount; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should stop if the first handler passes', function () { | ||
var handler = _sinon2.default.spy(returnsTrue); | ||
var callback = (0, _handle.oneOf)([returnsTrue, handler], [returnsTrue, handler], [returnsTrue, handler]); | ||
callback(); | ||
var expected = 1; | ||
var actual = handler.callCount; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should pass args to condition', function () { | ||
var handler = _sinon2.default.spy(returnsTrue); | ||
var callback = (0, _handle.oneOf)([handler, returnsTrue]); | ||
var ev = { value: 1 }; | ||
callback(ev); | ||
var expected = ev; | ||
var actual = handler.firstCall.args[0]; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should pass args to handlers', function () { | ||
var handler = _sinon2.default.spy(returnsTrue); | ||
var callback = (0, _handle.oneOf)([returnsTrue, handler]); | ||
var ev = { value: 1 }; | ||
callback(ev); | ||
var expected = ev; | ||
var actual = handler.firstCall.args[0]; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should return the value from the passed condition branch', function () { | ||
var handler = _sinon2.default.spy(function () { | ||
return 'ok'; | ||
}); | ||
var callback = (0, _handle.oneOf)([returnsTrue, handler]); | ||
var expected = callback(); | ||
var actual = 'ok'; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should support bound handlers', function () { | ||
var componentInstance = { | ||
context: { | ||
value: 1 | ||
} | ||
}; | ||
var handler = _sinon2.default.spy(); | ||
var h = _handle.handle.bind(componentInstance); | ||
var callback = (0, _handle.oneOf)([returnsTrue, h(handler)]); | ||
callback(); | ||
var expected = 1; | ||
var actual = handler.firstCall.args[2].value; | ||
expect(actual).to.equal(expected); | ||
}); | ||
}); | ||
var callback = (0, _handle.oneOf)([returnsTrue, h(handler)]); | ||
callback(); | ||
var expected = 1; | ||
var actual = handler.firstCall.args[2].value; | ||
expect(actual).to.equal(expected); | ||
}); | ||
}); | ||
}); |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,10 +6,8 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
exports.hoc = undefined; | ||
exports.hoc = exports.default = void 0; | ||
var _util = require('../util'); | ||
var _util = require("../util"); | ||
var _mergeDeepWithKey = require('ramda/src/mergeDeepWithKey'); | ||
var _mergeDeepWithKey = _interopRequireDefault(require("ramda/src/mergeDeepWithKey")); | ||
var _mergeDeepWithKey2 = _interopRequireDefault(_mergeDeepWithKey); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -22,3 +20,2 @@ | ||
*/ | ||
var mergeFn = function mergeFn(key, defaultValue, userValue) { | ||
@@ -32,3 +29,2 @@ // eslint-disable-next-line no-undefined | ||
}; | ||
/** | ||
@@ -77,7 +73,9 @@ * Constructs a Higher-order Component using an optional set of default configuration parameters and | ||
*/ | ||
var hoc = function hoc(defaultConfig, hawk) { | ||
// normalize arguments to allow defaultConfig to be omitted | ||
var factory = hawk; | ||
var defaults = defaultConfig; | ||
if (!factory && typeof defaultConfig === 'function') { | ||
@@ -92,3 +90,4 @@ factory = defaultConfig; | ||
} else { | ||
var cfg = (0, _mergeDeepWithKey2.default)(mergeFn, defaults, config); | ||
var cfg = (0, _mergeDeepWithKey.default)(mergeFn, defaults, config); | ||
if ((0, _util.isRenderable)(maybeWrapped)) { | ||
@@ -105,3 +104,4 @@ return factory(cfg, maybeWrapped); | ||
exports.default = hoc; | ||
exports.hoc = hoc; | ||
exports.hoc = hoc; | ||
var _default = hoc; | ||
exports.default = _default; |
@@ -1,125 +0,91 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; /* eslint-disable enact/display-name */ | ||
var _react = _interopRequireDefault(require("react")); | ||
var _react = require('react'); | ||
var _enzyme = require("enzyme"); | ||
var _react2 = _interopRequireDefault(_react); | ||
var _hoc = _interopRequireDefault(require("../hoc")); | ||
var _enzyme = require('enzyme'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _hoc = require('../hoc'); | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
var _hoc2 = _interopRequireDefault(_hoc); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
describe('hoc', function () { | ||
var defaultConfig = { | ||
color: 'blue' | ||
}; | ||
var HoC = (0, _hoc.default)(defaultConfig, function (config, Wrapped) { | ||
return function (props) { | ||
return _react.default.createElement(Wrapped, _extends({}, props, config)); | ||
}; | ||
}); | ||
var NullHoC = (0, _hoc.default)(null, function (config, Wrapped) { | ||
return function () { | ||
return _react.default.createElement(Wrapped, config); | ||
}; | ||
}); | ||
it('should support HoC factory function as first argument to hoc()', function () { | ||
var ImplicitNullHoC = (0, _hoc.default)(function (config, Wrapped) { | ||
return function () { | ||
return _react.default.createElement(Wrapped, config); | ||
}; | ||
}); | ||
var Component = ImplicitNullHoC('span'); | ||
var subject = (0, _enzyme.shallow)(_react.default.createElement(Component, null)); | ||
var expected = 'span'; | ||
var actual = subject.name(); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should support DOM node name as first argument to HoC', function () { | ||
var Component = HoC('span'); | ||
var subject = (0, _enzyme.shallow)(_react.default.createElement(Component, null)); | ||
var expected = 'span'; | ||
var actual = subject.name(); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should support React component as first argument to HoC', function () { | ||
function Thing() { | ||
return _react.default.createElement("div", null); | ||
} | ||
var defaultConfig = { | ||
color: 'blue' | ||
}; | ||
var HoC = (0, _hoc2.default)(defaultConfig, function (config, Wrapped) { | ||
return function (props) { | ||
return _react2.default.createElement(Wrapped, _extends({}, props, config)); | ||
}; | ||
}); | ||
var NullHoC = (0, _hoc2.default)(null, function (config, Wrapped) { | ||
return function () { | ||
return _react2.default.createElement(Wrapped, config); | ||
}; | ||
}); | ||
it('should support HoC factory function as first argument to hoc()', function () { | ||
var ImplicitNullHoC = (0, _hoc2.default)(function (config, Wrapped) { | ||
return function () { | ||
return _react2.default.createElement(Wrapped, config); | ||
}; | ||
}); | ||
var Component = ImplicitNullHoC('span'); | ||
var subject = (0, _enzyme.shallow)(_react2.default.createElement(Component, null)); | ||
var expected = 'span'; | ||
var actual = subject.name(); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should support DOM node name as first argument to HoC', function () { | ||
var Component = HoC('span'); | ||
var subject = (0, _enzyme.shallow)(_react2.default.createElement(Component, null)); | ||
var expected = 'span'; | ||
var actual = subject.name(); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should support React component as first argument to HoC', function () { | ||
function Thing() { | ||
return _react2.default.createElement('div', null); | ||
} | ||
var Component = HoC(Thing); | ||
var subject = (0, _enzyme.shallow)(_react2.default.createElement(Component, null)); | ||
var expected = 'Thing'; | ||
var actual = subject.name(); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should use default config when instance config is omitted', function () { | ||
var Component = HoC('span'); | ||
var subject = (0, _enzyme.mount)(_react2.default.createElement(Component, null)); | ||
var expected = defaultConfig.color; | ||
var actual = subject.find('span').prop('color'); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should overwrite default config with instance config', function () { | ||
var instanceConfig = { | ||
color: 'green' | ||
}; | ||
var Component = HoC(instanceConfig, 'div'); | ||
var subject = (0, _enzyme.mount)(_react2.default.createElement(Component, null)); | ||
var expected = instanceConfig.color; | ||
var actual = subject.find('div').prop('color'); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should allow construction without default or instance configs', function () { | ||
var Component = NullHoC('div'); | ||
var subject = (0, _enzyme.mount)(_react2.default.createElement(Component, null)); | ||
var expected = 1; | ||
var actual = subject.find('div').length; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should allow construction without default config', function () { | ||
var instanceConfig = { | ||
color: 'green' | ||
}; | ||
var Component = NullHoC(instanceConfig, 'div'); | ||
var subject = (0, _enzyme.mount)(_react2.default.createElement(Component, null)); | ||
var expected = instanceConfig.color; | ||
var actual = subject.find('div').prop('color'); | ||
expect(actual).to.equal(expected); | ||
}); | ||
var Component = HoC(Thing); | ||
var subject = (0, _enzyme.shallow)(_react.default.createElement(Component, null)); | ||
var expected = 'Thing'; | ||
var actual = subject.name(); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should use default config when instance config is omitted', function () { | ||
var Component = HoC('span'); | ||
var subject = (0, _enzyme.mount)(_react.default.createElement(Component, null)); | ||
var expected = defaultConfig.color; | ||
var actual = subject.find('span').prop('color'); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should overwrite default config with instance config', function () { | ||
var instanceConfig = { | ||
color: 'green' | ||
}; | ||
var Component = HoC(instanceConfig, 'div'); | ||
var subject = (0, _enzyme.mount)(_react.default.createElement(Component, null)); | ||
var expected = instanceConfig.color; | ||
var actual = subject.find('div').prop('color'); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should allow construction without default or instance configs', function () { | ||
var Component = NullHoC('div'); | ||
var subject = (0, _enzyme.mount)(_react.default.createElement(Component, null)); | ||
var expected = 1; | ||
var actual = subject.find('div').length; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should allow construction without default config', function () { | ||
var instanceConfig = { | ||
color: 'green' | ||
}; | ||
var Component = NullHoC(instanceConfig, 'div'); | ||
var subject = (0, _enzyme.mount)(_react.default.createElement(Component, null)); | ||
var expected = instanceConfig.color; | ||
var actual = subject.find('div').prop('color'); | ||
expect(actual).to.equal(expected); | ||
}); | ||
}); |
@@ -1,63 +0,64 @@ | ||
'use strict'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
value: true | ||
}); | ||
exports.ApiDecorator = undefined; | ||
exports.ApiDecorator = exports.default = void 0; | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var _invariant = _interopRequireDefault(require("invariant")); | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _react = _interopRequireDefault(require("react")); | ||
var _invariant = require('invariant'); | ||
var _hoc = _interopRequireDefault(require("../../hoc")); | ||
var _invariant2 = _interopRequireDefault(_invariant); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _react = require('react'); | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
var _react2 = _interopRequireDefault(_react); | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
var _hoc = require('../../hoc'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var _hoc2 = _interopRequireDefault(_hoc); | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } /** | ||
* Provides the `ApiDecorator` Higher-order Component | ||
* | ||
* @module core/internal/ApiDecorator | ||
* @private | ||
*/ | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); } | ||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); } | ||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); } | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } } | ||
// Invokes `name` on `provider` with `args` | ||
var invoke = function invoke(provider, name, args) { | ||
if (provider) { | ||
var fn = provider[name]; | ||
if (typeof fn === 'function') { | ||
return provider[name].apply(provider, _toConsumableArray(args)); | ||
} | ||
} | ||
}; | ||
if (provider) { | ||
var fn = provider[name]; | ||
// Gets a property from `provider` | ||
var _get = function _get(provider, name) { | ||
if (provider) { | ||
return provider[name]; | ||
} | ||
}; | ||
if (typeof fn === 'function') { | ||
return provider[name].apply(provider, _toConsumableArray(args)); | ||
} | ||
} | ||
}; // Gets a property from `provider` | ||
// Sets a property on `provider` | ||
var _set = function _set(provider, name, value) { | ||
if (provider) { | ||
return provider[name] = value; | ||
} | ||
var _get = function get(provider, name) { | ||
if (provider) { | ||
return provider[name]; | ||
} | ||
}; // Sets a property on `provider` | ||
var _set = function set(provider, name, value) { | ||
if (provider) { | ||
return provider[name] = value; | ||
} | ||
}; | ||
/** | ||
@@ -69,13 +70,14 @@ * Default config for {@link core/internal/ApiDecorator.ApiDecorator}. | ||
*/ | ||
var defaultConfig = { | ||
/** | ||
* Configures the API endpoints to be exposed | ||
* | ||
* @type {String[]} | ||
* @required | ||
* @memberof core/internal/ApiDecorator.ApiDecorator.defaultConfig | ||
*/ | ||
api: null | ||
/** | ||
* Configures the API endpoints to be exposed | ||
* | ||
* @type {String[]} | ||
* @required | ||
* @memberof core/internal/ApiDecorator.ApiDecorator.defaultConfig | ||
*/ | ||
api: null | ||
}; | ||
/** | ||
@@ -103,69 +105,81 @@ * {@link core/internal/ApiDecorator.ApiDecorator} is a Higher-order Component that exposes an | ||
*/ | ||
var ApiDecorator = (0, _hoc2.default)(defaultConfig, function (config, Wrapped) { | ||
var _class, _temp2, _initialiseProps; | ||
var api = config.api; | ||
var ApiDecorator = (0, _hoc.default)(defaultConfig, function (config, Wrapped) { | ||
var _class, _temp2, _initialiseProps; | ||
var api = config.api; | ||
!(api != null) ? process.env.NODE_ENV !== "production" ? (0, _invariant.default)(false, 'ApiDecorator: api is a required config property') : invariant(false) : void 0; | ||
return _temp2 = _class = | ||
/*#__PURE__*/ | ||
function (_React$Component) { | ||
_inherits(_class, _React$Component); | ||
!(api != null) ? process.env.NODE_ENV !== 'production' ? (0, _invariant2.default)(false, 'ApiDecorator: api is a required config property') : (0, _invariant2.default)(false) : void 0; | ||
function _class() { | ||
var _ref; | ||
return _temp2 = _class = function (_React$Component) { | ||
_inherits(_class, _React$Component); | ||
var _temp, _this; | ||
function _class() { | ||
var _ref; | ||
_classCallCheck(this, _class); | ||
var _temp, _this, _ret; | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_classCallCheck(this, _class); | ||
return _possibleConstructorReturn(_this, (_temp = _this = _possibleConstructorReturn(this, (_ref = _class.__proto__ || Object.getPrototypeOf(_class)).call.apply(_ref, [this].concat(args))), _initialiseProps.call(_assertThisInitialized(_this)), _temp)); | ||
} | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_createClass(_class, [{ | ||
key: "render", | ||
value: function render() { | ||
return _react.default.createElement(Wrapped, _extends({ | ||
setApiProvider: this.setProvider | ||
}, this.props)); | ||
} | ||
}]); | ||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = _class.__proto__ || Object.getPrototypeOf(_class)).call.apply(_ref, [this].concat(args))), _this), _initialiseProps.call(_this), _temp), _possibleConstructorReturn(_this, _ret); | ||
} | ||
return _class; | ||
}(_react.default.Component), Object.defineProperty(_class, "displayName", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: 'ApiDecorator' | ||
}), _initialiseProps = function _initialiseProps() { | ||
var _this2 = this; | ||
_createClass(_class, [{ | ||
key: 'render', | ||
value: function render() { | ||
return _react2.default.createElement(Wrapped, _extends({ setApiProvider: this.setProvider }, this.props)); | ||
} | ||
}]); | ||
Object.defineProperty(this, "setProvider", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: function value(provider) { | ||
api.forEach(function (key) { | ||
if (_this2[key]) { | ||
throw new Error("API endpoint, ".concat(key, ", already exists")); | ||
} | ||
return _class; | ||
}(_react2.default.Component), _class.displayName = 'ApiDecorator', _initialiseProps = function _initialiseProps() { | ||
var _this2 = this; | ||
if (typeof provider[key] === 'function') { | ||
_this2[key] = function () { | ||
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
this.setProvider = function (provider) { | ||
api.forEach(function (key) { | ||
if (_this2[key]) { | ||
throw new Error('API endpoint, ' + key + ', already exists'); | ||
} | ||
if (typeof provider[key] === 'function') { | ||
_this2[key] = function () { | ||
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
return invoke(provider, key, args); | ||
}; | ||
} else { | ||
Object.defineProperty(_this2, key, { | ||
get: function get() { | ||
return _get(provider, key); | ||
}, | ||
set: function set(v) { | ||
return _set(provider, key, v); | ||
}, | ||
enumerable: true | ||
}); | ||
} | ||
}); | ||
}; | ||
}, _temp2; | ||
return invoke(provider, key, args); | ||
}; | ||
} else { | ||
Object.defineProperty(_this2, key, { | ||
get: function get() { | ||
return _get(provider, key); | ||
}, | ||
set: function set(v) { | ||
return _set(provider, key, v); | ||
}, | ||
enumerable: true | ||
}); | ||
} | ||
}); | ||
} | ||
}); | ||
}, _temp2; | ||
}); | ||
exports.default = ApiDecorator; | ||
exports.ApiDecorator = ApiDecorator; | ||
exports.ApiDecorator = ApiDecorator; | ||
var _default = ApiDecorator; | ||
exports.default = _default; |
@@ -1,104 +0,114 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _react = _interopRequireDefault(require("react")); | ||
var _react = require('react'); | ||
var _enzyme = require("enzyme"); | ||
var _react2 = _interopRequireDefault(_react); | ||
var _ApiDecorator = _interopRequireDefault(require("../ApiDecorator")); | ||
var _enzyme = require('enzyme'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _ApiDecorator = require('../ApiDecorator'); | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
var _ApiDecorator2 = _interopRequireDefault(_ApiDecorator); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
describe('ApiDecorator', function () { | ||
var _class, _temp; | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
var ApiProvider = (_temp = _class = function (_React$Component) { | ||
_inherits(ApiProvider, _React$Component); | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function ApiProvider(props) { | ||
_classCallCheck(this, ApiProvider); | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
// eslint-disable-next-line | ||
var _this = _possibleConstructorReturn(this, (ApiProvider.__proto__ || Object.getPrototypeOf(ApiProvider)).call(this)); | ||
describe('ApiDecorator', function () { | ||
var _class, _temp; | ||
_this.arrowFunction = function () { | ||
return 'arrow'; | ||
}; | ||
var ApiProvider = (_temp = _class = | ||
/*#__PURE__*/ | ||
function (_React$Component) { | ||
_inherits(ApiProvider, _React$Component); | ||
_this.instanceProperty = 'property'; | ||
props.setApiProvider(_this); | ||
return _this; | ||
} | ||
function ApiProvider(props) { | ||
var _this; | ||
_createClass(ApiProvider, [{ | ||
key: 'instanceFunction', | ||
value: function instanceFunction() { | ||
return 'instance'; | ||
} | ||
}, { | ||
key: 'render', | ||
value: function render() { | ||
return _react2.default.createElement('div', null); | ||
} | ||
}]); | ||
_classCallCheck(this, ApiProvider); | ||
return ApiProvider; | ||
}(_react2.default.Component), _class.displayName = 'ApiProvider', _temp); | ||
_this = _possibleConstructorReturn(this, (ApiProvider.__proto__ || Object.getPrototypeOf(ApiProvider)).call(this)); // eslint-disable-next-line | ||
it('should invoke arrow function on wrapped component', function () { | ||
var Component = (0, _ApiDecorator2.default)({ api: ['arrowFunction'] }, ApiProvider); | ||
Object.defineProperty(_assertThisInitialized(_this), "arrowFunction", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: function value() { | ||
return 'arrow'; | ||
} | ||
}); | ||
Object.defineProperty(_assertThisInitialized(_this), "instanceProperty", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: 'property' | ||
}); | ||
props.setApiProvider(_assertThisInitialized(_this)); | ||
return _this; | ||
} | ||
var subject = (0, _enzyme.mount)(_react2.default.createElement(Component, null)); | ||
_createClass(ApiProvider, [{ | ||
key: "instanceFunction", | ||
value: function instanceFunction() { | ||
return 'instance'; | ||
} | ||
}, { | ||
key: "render", | ||
value: function render() { | ||
return _react.default.createElement("div", null); | ||
} | ||
}]); | ||
var expected = 'arrow'; | ||
var actual = subject.instance().arrowFunction(); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should invoke instance function on wrapped component', function () { | ||
var Component = (0, _ApiDecorator2.default)({ api: ['instanceFunction'] }, ApiProvider); | ||
var subject = (0, _enzyme.mount)(_react2.default.createElement(Component, null)); | ||
var expected = 'instance'; | ||
var actual = subject.instance().instanceFunction(); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should get an instance property on wrapped component', function () { | ||
var Component = (0, _ApiDecorator2.default)({ api: ['instanceProperty'] }, ApiProvider); | ||
var subject = (0, _enzyme.mount)(_react2.default.createElement(Component, null)); | ||
var expected = 'property'; | ||
var actual = subject.instance().instanceProperty; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should set an instance property on wrapped component', function () { | ||
var Component = (0, _ApiDecorator2.default)({ api: ['instanceProperty'] }, ApiProvider); | ||
var subject = (0, _enzyme.mount)(_react2.default.createElement(Component, null)); | ||
subject.instance().instanceProperty = 'updated'; | ||
var expected = 'updated'; | ||
var actual = subject.instance().instanceProperty; | ||
expect(actual).to.equal(expected); | ||
}); | ||
return ApiProvider; | ||
}(_react.default.Component), Object.defineProperty(_class, "displayName", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: 'ApiProvider' | ||
}), _temp); | ||
it('should invoke arrow function on wrapped component', function () { | ||
var Component = (0, _ApiDecorator.default)({ | ||
api: ['arrowFunction'] | ||
}, ApiProvider); | ||
var subject = (0, _enzyme.mount)(_react.default.createElement(Component, null)); | ||
var expected = 'arrow'; | ||
var actual = subject.instance().arrowFunction(); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should invoke instance function on wrapped component', function () { | ||
var Component = (0, _ApiDecorator.default)({ | ||
api: ['instanceFunction'] | ||
}, ApiProvider); | ||
var subject = (0, _enzyme.mount)(_react.default.createElement(Component, null)); | ||
var expected = 'instance'; | ||
var actual = subject.instance().instanceFunction(); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should get an instance property on wrapped component', function () { | ||
var Component = (0, _ApiDecorator.default)({ | ||
api: ['instanceProperty'] | ||
}, ApiProvider); | ||
var subject = (0, _enzyme.mount)(_react.default.createElement(Component, null)); | ||
var expected = 'property'; | ||
var actual = subject.instance().instanceProperty; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should set an instance property on wrapped component', function () { | ||
var Component = (0, _ApiDecorator.default)({ | ||
api: ['instanceProperty'] | ||
}, ApiProvider); | ||
var subject = (0, _enzyme.mount)(_react.default.createElement(Component, null)); | ||
subject.instance().instanceProperty = 'updated'; | ||
var expected = 'updated'; | ||
var actual = subject.instance().instanceProperty; | ||
expect(actual).to.equal(expected); | ||
}); | ||
}); |
@@ -1,6 +0,8 @@ | ||
'use strict'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
value: true | ||
}); | ||
exports.deprecate = exports.default = void 0; | ||
/** | ||
@@ -12,47 +14,52 @@ * Provides the `deprecate` method | ||
*/ | ||
// Utility method to format deprecate message | ||
var formatMsg = function formatMsg(_ref) { | ||
var message = _ref.message, | ||
name = _ref.name, | ||
until = _ref.until, | ||
replacedBy = _ref.replacedBy, | ||
since = _ref.since; | ||
var message = _ref.message, | ||
name = _ref.name, | ||
until = _ref.until, | ||
replacedBy = _ref.replacedBy, | ||
since = _ref.since; | ||
var msg = 'DEPRECATED:'; | ||
var msg = 'DEPRECATED:'; | ||
if (name) { | ||
msg += " ".concat(name); | ||
} | ||
if (name) { | ||
msg += ' ' + name; | ||
} | ||
if (since) { | ||
msg += ' since ' + since; | ||
} | ||
if (until) { | ||
if (name || since) { | ||
msg += '.'; | ||
} | ||
msg += ' Will be removed in ' + until; | ||
} | ||
if (replacedBy) { | ||
if (name || since || until) { | ||
msg += '.'; | ||
} | ||
msg += ' Replaced by ' + replacedBy; | ||
} | ||
if (name || since || until || replacedBy) { | ||
msg += '.'; | ||
} | ||
if (message) { | ||
msg += ' ' + message + '.'; | ||
} | ||
return msg; | ||
}; | ||
if (since) { | ||
msg += " since ".concat(since); | ||
} | ||
// Utility method for console warning | ||
if (until) { | ||
if (name || since) { | ||
msg += '.'; | ||
} | ||
msg += " Will be removed in ".concat(until); | ||
} | ||
if (replacedBy) { | ||
if (name || since || until) { | ||
msg += '.'; | ||
} | ||
msg += " Replaced by ".concat(replacedBy); | ||
} | ||
if (name || since || until || replacedBy) { | ||
msg += '.'; | ||
} | ||
if (message) { | ||
msg += " ".concat(message, "."); | ||
} | ||
return msg; | ||
}; // Utility method for console warning | ||
var warn = function warn(msg) { | ||
if (typeof console !== 'undefined') { | ||
console.warn(msg); // eslint-disable-line no-console | ||
} | ||
if (typeof console !== 'undefined') { | ||
console.warn(msg); // eslint-disable-line no-console | ||
} | ||
}; | ||
/** | ||
@@ -78,29 +85,34 @@ * Marks a function, component or property (via `propTypes`) as deprecated. Deprecated items will | ||
*/ | ||
var deprecate = function deprecate(thing, config) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
if (!config) { | ||
// If no config, config only invocation, just log message | ||
var msg = formatMsg(thing); | ||
warn(msg); | ||
return thing; | ||
} else { | ||
var displayed = void 0, | ||
_msg = void 0; | ||
return function () { | ||
if (!displayed || config.alwaysWarn) { | ||
if (!_msg) { | ||
_msg = formatMsg(config); | ||
} | ||
warn(_msg); | ||
displayed = true; | ||
} | ||
return thing.apply(undefined, arguments); | ||
}; | ||
} | ||
} else { | ||
return thing; | ||
} | ||
if (process.env.NODE_ENV !== "production") { | ||
if (!config) { | ||
// If no config, config only invocation, just log message | ||
var msg = formatMsg(thing); | ||
warn(msg); | ||
return thing; | ||
} else { | ||
var displayed, _msg; | ||
return function () { | ||
if (!displayed || config.alwaysWarn) { | ||
if (!_msg) { | ||
_msg = formatMsg(config); | ||
} | ||
warn(_msg); | ||
displayed = true; | ||
} | ||
return thing.apply(void 0, arguments); | ||
}; | ||
} | ||
} else { | ||
return thing; | ||
} | ||
}; | ||
exports.default = deprecate; | ||
exports.deprecate = deprecate; | ||
exports.deprecate = deprecate; | ||
var _default = deprecate; | ||
exports.default = _default; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
value: true | ||
}); | ||
exports.Publisher = exports.default = void 0; | ||
@@ -34,154 +35,149 @@ /** | ||
var Publisher = { | ||
/** | ||
* Creates a new {@link core/internal/PubSub.Publisher} for the given `channel`. If `parent` is | ||
* provided, subscriptions for other channels will be forwarded to the parent allowing multiple | ||
* channels from different publishers in the chain. | ||
* | ||
* @param {String} channel Channel name | ||
* @param {core/internal/PubSub.Subscriber} parent Subscriber instance from an upstream | ||
* publisher | ||
* | ||
* @returns {core/internal/PubSub/Publisher} New Publisher instance | ||
* @private | ||
* @static | ||
* @memberof core/internal/PubSub/Publisher | ||
*/ | ||
create: function create(channel, parent) { | ||
// cache the last message sent so it can be rebroadcast to new subscribers | ||
var lastMessage = null; | ||
// @TODO Replace with Set when unit testing supports it | ||
// All known subscribers to this channel | ||
var listeners = []; | ||
/** | ||
* Adds a listener (if it isn't already added) and republishes the last message (if one | ||
* exists) to the new subscriber. | ||
/** | ||
* Creates a new {@link core/internal/PubSub.Publisher} for the given `channel`. If `parent` is | ||
* provided, subscriptions for other channels will be forwarded to the parent allowing multiple | ||
* channels from different publishers in the chain. | ||
* | ||
* @param {Function} callback New listener | ||
* @param {String} channel Channel name | ||
* @param {core/internal/PubSub.Subscriber} parent Subscriber instance from an upstream | ||
* publisher | ||
* | ||
* @returns {core/internal/PubSub/Publisher} New Publisher instance | ||
* @private | ||
* @memberof core/internal/PubSub.Publisher | ||
* @static | ||
* @memberof core/internal/PubSub/Publisher | ||
*/ | ||
function addListener(callback) { | ||
if (listeners.indexOf(callback) >= 0) return; | ||
create: function create(channel, parent) { | ||
// cache the last message sent so it can be rebroadcast to new subscribers | ||
var lastMessage = null; // @TODO Replace with Set when unit testing supports it | ||
// All known subscribers to this channel | ||
listeners.unshift(callback); | ||
var listeners = []; | ||
/** | ||
* Adds a listener (if it isn't already added) and republishes the last message (if one | ||
* exists) to the new subscriber. | ||
* | ||
* @param {Function} callback New listener | ||
* @private | ||
* @memberof core/internal/PubSub.Publisher | ||
*/ | ||
if (lastMessage) { | ||
callback({ | ||
channel: channel, | ||
message: lastMessage | ||
}); | ||
} | ||
} | ||
function addListener(callback) { | ||
if (listeners.indexOf(callback) >= 0) return; | ||
listeners.unshift(callback); | ||
/** | ||
* Removes a listener from this publisher | ||
* | ||
* @param {Function} callback Listener | ||
* @private | ||
* @memberof core/internal/PubSub.Publisher | ||
*/ | ||
function removeListener(callback) { | ||
var index = listeners.indexOf(callback); | ||
if (index >= 0) { | ||
listeners.splice(index, 1); | ||
} | ||
} | ||
if (lastMessage) { | ||
callback({ | ||
channel: channel, | ||
message: lastMessage | ||
}); | ||
} | ||
} | ||
/** | ||
* Removes a listener from this publisher | ||
* | ||
* @param {Function} callback Listener | ||
* @private | ||
* @memberof core/internal/PubSub.Publisher | ||
*/ | ||
/** | ||
* Subscribers can `subscribe` to a channel to be notified of messages or events as | ||
* determined by the publisher. They must `unsubscribe` with the same `channel` and | ||
* `callback` to avoid invocations after the subscriber has been destroyed. | ||
* | ||
* @class Subscriber | ||
* @private | ||
* @memberof core/internal/PubSub | ||
*/ | ||
var subscriber = { | ||
/** | ||
* Subscribes to a `channel` | ||
* | ||
* @param {String} channel Channel name | ||
* @param {Function} callback Handler for channel messages | ||
* | ||
* @returns {Boolean} `true` if a publisher exists for the `channel` and the | ||
* subscription was successful | ||
* @private | ||
* @memberof core/internal/PubSub.Subscriber.protoptype | ||
*/ | ||
subscribe: function subscribe(channelName, callback) { | ||
if (channelName === channel) { | ||
addListener(callback); | ||
return true; | ||
} else if (parent) { | ||
return parent.subscribe(channelName, callback); | ||
} | ||
function removeListener(callback) { | ||
var index = listeners.indexOf(callback); | ||
return false; | ||
}, | ||
if (index >= 0) { | ||
listeners.splice(index, 1); | ||
} | ||
} | ||
/** | ||
* Subscribers can `subscribe` to a channel to be notified of messages or events as | ||
* determined by the publisher. They must `unsubscribe` with the same `channel` and | ||
* `callback` to avoid invocations after the subscriber has been destroyed. | ||
* | ||
* @class Subscriber | ||
* @private | ||
* @memberof core/internal/PubSub | ||
*/ | ||
/** | ||
* Unsubscribes from a `channel` | ||
* | ||
* @param {String} channel Channel name | ||
* @param {Function} callback Handler for channel messages | ||
* | ||
* @returns {Boolean} `true` if a publisher exists for the `channel` and the | ||
* unsubscription was successful | ||
* @private | ||
* @memberof core/internal/PubSub.Subscriber.protoptype | ||
*/ | ||
unsubscribe: function unsubscribe(channelName, callback) { | ||
if (channelName === channel) { | ||
removeListener(callback); | ||
var subscriber = { | ||
/** | ||
* Subscribes to a `channel` | ||
* | ||
* @param {String} channel Channel name | ||
* @param {Function} callback Handler for channel messages | ||
* | ||
* @returns {Boolean} `true` if a publisher exists for the `channel` and the | ||
* subscription was successful | ||
* @private | ||
* @memberof core/internal/PubSub.Subscriber.protoptype | ||
*/ | ||
subscribe: function subscribe(channelName, callback) { | ||
if (channelName === channel) { | ||
addListener(callback); | ||
return true; | ||
} else if (parent) { | ||
return parent.subscribe(channelName, callback); | ||
} | ||
return true; | ||
} else if (parent) { | ||
return parent.unsubscribe(channelName, callback); | ||
} | ||
return false; | ||
}, | ||
return false; | ||
} | ||
}; | ||
/** | ||
* Unsubscribes from a `channel` | ||
* | ||
* @param {String} channel Channel name | ||
* @param {Function} callback Handler for channel messages | ||
* | ||
* @returns {Boolean} `true` if a publisher exists for the `channel` and the | ||
* unsubscription was successful | ||
* @private | ||
* @memberof core/internal/PubSub.Subscriber.protoptype | ||
*/ | ||
unsubscribe: function unsubscribe(channelName, callback) { | ||
if (channelName === channel) { | ||
removeListener(callback); | ||
return true; | ||
} else if (parent) { | ||
return parent.unsubscribe(channelName, callback); | ||
} | ||
return { | ||
/** | ||
* Publishes `message` to the `Publisher`'s Subscribers | ||
* | ||
* @param {Object} message An arbitrary message body which cannot be mutated by | ||
* subscribers | ||
* | ||
* @private | ||
* @memberof core/internal/PubSub.Publisher.prototype | ||
*/ | ||
publish: function publish(message) { | ||
lastMessage = Object.freeze(message); | ||
listeners.forEach(function (listener) { | ||
listener({ | ||
channel: channel, | ||
message: lastMessage | ||
}); | ||
}); | ||
}, | ||
return false; | ||
} | ||
}; | ||
return { | ||
/** | ||
* Publishes `message` to the `Publisher`'s Subscribers | ||
* | ||
* @param {Object} message An arbitrary message body which cannot be mutated by | ||
* subscribers | ||
* | ||
* @private | ||
* @memberof core/internal/PubSub.Publisher.prototype | ||
*/ | ||
publish: function publish(message) { | ||
lastMessage = Object.freeze(message); | ||
listeners.forEach(function (listener) { | ||
listener({ | ||
channel: channel, | ||
message: lastMessage | ||
}); | ||
}); | ||
}, | ||
/** | ||
* Returns a @{link core/internal/PubSub.Subscriber} that can be used to add subscribers | ||
* to this publisher. | ||
* | ||
* @private | ||
* @memberof core/internal/PubSub.Publisher.prototype | ||
*/ | ||
getSubscriber: function getSubscriber() { | ||
return subscriber; | ||
} | ||
}; | ||
} | ||
/** | ||
* Returns a @{link core/internal/PubSub.Subscriber} that can be used to add subscribers | ||
* to this publisher. | ||
* | ||
* @private | ||
* @memberof core/internal/PubSub.Publisher.prototype | ||
*/ | ||
getSubscriber: function getSubscriber() { | ||
return subscriber; | ||
} | ||
}; | ||
} | ||
}; | ||
exports.default = Publisher; | ||
exports.Publisher = Publisher; | ||
exports.Publisher = Publisher; | ||
var _default = Publisher; | ||
exports.default = _default; |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,13 +6,15 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
exports.contextTypes = exports.Subscription = exports.Publisher = undefined; | ||
var _Subscription = require('./Subscription'); | ||
Object.defineProperty(exports, 'Subscription', { | ||
Object.defineProperty(exports, "Publisher", { | ||
enumerable: true, | ||
get: function get() { | ||
return _Publisher2.default; | ||
} | ||
}); | ||
Object.defineProperty(exports, "Subscription", { | ||
enumerable: true, | ||
get: function get() { | ||
return _Subscription.Subscription; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'contextTypes', { | ||
Object.defineProperty(exports, "contextTypes", { | ||
enumerable: true, | ||
@@ -24,14 +26,6 @@ get: function get() { | ||
var _Publisher2 = require('./Publisher'); | ||
var _Publisher2 = _interopRequireDefault(require("./Publisher")); | ||
var _Publisher3 = _interopRequireDefault(_Publisher2); | ||
var _Subscription = require("./Subscription"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
exports.Publisher = _Publisher3.default; /** | ||
* Exports the {@link core/internal/PubSub.Publisher} class and | ||
* {@link core/internal/PubSub.Subscription} HOC. | ||
* | ||
* @module core/internal/PubSub | ||
* @private | ||
*/ | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } |
@@ -1,25 +0,25 @@ | ||
'use strict'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
value: true | ||
}); | ||
exports.Subscription = exports.contextTypes = undefined; | ||
exports.Subscription = exports.contextTypes = exports.default = void 0; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
var _propTypes = _interopRequireDefault(require("prop-types")); | ||
var _propTypes = require('prop-types'); | ||
var _react = _interopRequireDefault(require("react")); | ||
var _propTypes2 = _interopRequireDefault(_propTypes); | ||
var _hoc = _interopRequireDefault(require("../../hoc")); | ||
var _react = require('react'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _react2 = _interopRequireDefault(_react); | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
var _hoc = require('../../hoc'); | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); } | ||
var _hoc2 = _interopRequireDefault(_hoc); | ||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); } | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } } | ||
@@ -30,6 +30,12 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
/** | ||
@@ -42,29 +48,27 @@ * Default config for {@link core/internal/PubSub.Subscription}. | ||
var defaultConfig = { | ||
/** | ||
* Array of channels to which the component should subscribe | ||
* | ||
* @type {String[]} | ||
* @default null | ||
* @required | ||
* @memberof core/internal/PubSub.Subscription.defaultConfig | ||
*/ | ||
channels: null, | ||
/** | ||
* Array of channels to which the component should subscribe | ||
* | ||
* @type {String[]} | ||
* @default null | ||
* @required | ||
* @memberof core/internal/PubSub.Subscription.defaultConfig | ||
*/ | ||
channels: null, | ||
/** | ||
* Function that maps a channel's message to props | ||
* | ||
* @type {Function} | ||
* @default null | ||
* @memberof core/internal/PubSub.Subscription.defaultConfig | ||
*/ | ||
mapMessageToProps: null | ||
/** | ||
* Function that maps a channel's message to props | ||
* | ||
* @type {Function} | ||
* @default null | ||
* @memberof core/internal/PubSub.Subscription.defaultConfig | ||
*/ | ||
mapMessageToProps: null | ||
}; | ||
var contextTypes = { | ||
Subscriber: _propTypes2.default.shape({ | ||
subscribe: _propTypes2.default.func, | ||
unsubscribe: _propTypes2.default.func | ||
}) | ||
Subscriber: _propTypes.default.shape({ | ||
subscribe: _propTypes.default.func, | ||
unsubscribe: _propTypes.default.func | ||
}) | ||
}; | ||
/** | ||
@@ -103,82 +107,106 @@ * Subscribes to the configured `channels` and passes the received messages to the Wrapped component | ||
*/ | ||
var Subscription = (0, _hoc2.default)(defaultConfig, function (config, Wrapped) { | ||
var _class, _temp; | ||
var channels = config.channels, | ||
mapMessageToProps = config.mapMessageToProps; | ||
exports.contextTypes = contextTypes; | ||
var Subscription = (0, _hoc.default)(defaultConfig, function (config, Wrapped) { | ||
var _class, _temp; | ||
var channels = config.channels, | ||
mapMessageToProps = config.mapMessageToProps; | ||
return _temp = _class = | ||
/*#__PURE__*/ | ||
function (_React$Component) { | ||
_inherits(_class, _React$Component); | ||
return _temp = _class = function (_React$Component) { | ||
_inherits(_class, _React$Component); | ||
function _class() { | ||
var _this; | ||
function _class() { | ||
_classCallCheck(this, _class); | ||
_classCallCheck(this, _class); | ||
var _this = _possibleConstructorReturn(this, (_class.__proto__ || Object.getPrototypeOf(_class)).call(this)); | ||
_this = _possibleConstructorReturn(this, (_class.__proto__ || Object.getPrototypeOf(_class)).call(this)); | ||
Object.defineProperty(_assertThisInitialized(_this), "handleSubscription", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: function value(_ref) { | ||
var channel = _ref.channel, | ||
message = _ref.message; | ||
_this.handleSubscription = function (_ref) { | ||
var channel = _ref.channel, | ||
message = _ref.message; | ||
_this.setState(_defineProperty({}, channel, message)); | ||
} | ||
}); | ||
_this.state = {}; | ||
return _this; | ||
} | ||
_this.setState(_defineProperty({}, channel, message)); | ||
}; | ||
_createClass(_class, [{ | ||
key: "componentWillMount", | ||
value: function componentWillMount() { | ||
var _this2 = this; | ||
_this.state = {}; | ||
return _this; | ||
} | ||
if (channels && channels.length && this.context.Subscriber) { | ||
channels.forEach(function (channel) { | ||
_this2.context.Subscriber.subscribe(channel, _this2.handleSubscription); | ||
}); | ||
} | ||
} | ||
}, { | ||
key: "componentWillUnmount", | ||
value: function componentWillUnmount() { | ||
var _this3 = this; | ||
_createClass(_class, [{ | ||
key: 'componentWillMount', | ||
value: function componentWillMount() { | ||
var _this2 = this; | ||
if (channels && channels.length && this.context.Subscriber) { | ||
channels.forEach(function (channel) { | ||
_this3.context.Subscriber.unsubscribe(channel, _this3.handleSubscription); | ||
}); | ||
} | ||
} | ||
}, { | ||
key: "combinePropsAndState", | ||
value: function combinePropsAndState() { | ||
var _this4 = this; | ||
if (channels && channels.length && this.context.Subscriber) { | ||
channels.forEach(function (channel) { | ||
_this2.context.Subscriber.subscribe(channel, _this2.handleSubscription); | ||
}); | ||
} | ||
} | ||
}, { | ||
key: 'componentWillUnmount', | ||
value: function componentWillUnmount() { | ||
var _this3 = this; | ||
// Choosing to overwrite state with props to provide a simple way to allow localized | ||
// overrides. This can be prevented by a Subscription instance by implementing | ||
// mapMessageToProps in such a way that the state is redirected into different props. | ||
if (typeof mapMessageToProps === 'function') { | ||
return Object.assign.apply(Object, [{}].concat(_toConsumableArray(Object.keys(this.state).map(function (key) { | ||
return mapMessageToProps(key, _this4.state[key]); | ||
})), [this.props])); | ||
} | ||
if (channels && channels.length && this.context.Subscriber) { | ||
channels.forEach(function (channel) { | ||
_this3.context.Subscriber.unsubscribe(channel, _this3.handleSubscription); | ||
}); | ||
} | ||
} | ||
}, { | ||
key: 'combinePropsAndState', | ||
value: function combinePropsAndState() { | ||
var _this4 = this; | ||
return Object.assign({}, this.state, this.props); | ||
} | ||
}, { | ||
key: "render", | ||
value: function render() { | ||
var props = this.combinePropsAndState(); | ||
return _react.default.createElement(Wrapped, props); | ||
} | ||
}]); | ||
// Choosing to overwrite state with props to provide a simple way to allow localized | ||
// overrides. This can be prevented by a Subscription instance by implementing | ||
// mapMessageToProps in such a way that the state is redirected into different props. | ||
if (typeof mapMessageToProps === 'function') { | ||
return Object.assign.apply(Object, [{}].concat(_toConsumableArray(Object.keys(this.state).map(function (key) { | ||
return mapMessageToProps(key, _this4.state[key]); | ||
})), [this.props])); | ||
} | ||
return Object.assign({}, this.state, this.props); | ||
} | ||
}, { | ||
key: 'render', | ||
value: function render() { | ||
var props = this.combinePropsAndState(); | ||
return _react2.default.createElement(Wrapped, props); | ||
} | ||
}]); | ||
return _class; | ||
}(_react2.default.Component), _class.displayName = 'Subscription', _class.contextTypes = contextTypes, _class.propTypes = {}, _class.defaultProps = {}, _temp; | ||
return _class; | ||
}(_react.default.Component), Object.defineProperty(_class, "displayName", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: 'Subscription' | ||
}), Object.defineProperty(_class, "contextTypes", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: contextTypes | ||
}), Object.defineProperty(_class, "propTypes", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: {} | ||
}), Object.defineProperty(_class, "defaultProps", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: {} | ||
}), _temp; | ||
}); | ||
exports.default = Subscription; | ||
exports.contextTypes = contextTypes; | ||
exports.Subscription = Subscription; | ||
exports.Subscription = Subscription; | ||
var _default = Subscription; | ||
exports.default = _default; |
@@ -1,31 +0,30 @@ | ||
'use strict'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
value: true | ||
}); | ||
var _keymap = require('./keymap'); | ||
var _keymap = require("./keymap"); | ||
Object.keys(_keymap).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _keymap[key]; | ||
} | ||
}); | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _keymap[key]; | ||
} | ||
}); | ||
}); | ||
// keymap uses a singleton object, map, to manage the keymap. since webpack may make multiple copies | ||
// of the module available if the import path is different, we ensure a consistent import path for | ||
// the singleton instance by facading it with this module. | ||
// Add the default 5-way navigation key codes | ||
(0, _keymap.addAll)({ | ||
enter: [13, 16777221], | ||
left: 37, | ||
up: 38, | ||
right: 39, | ||
down: 40, | ||
pageUp: 33, | ||
pageDown: 34 | ||
}); // keymap uses a singleton object, map, to manage the keymap. since webpack may make multiple copies | ||
// of the module available if the import path is different, we ensure a consistent import path for | ||
// the singleton instance by facading it with this module. | ||
enter: [13, 16777221], | ||
left: 37, | ||
up: 38, | ||
right: 39, | ||
down: 40, | ||
pageUp: 33, | ||
pageDown: 34 | ||
}); |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,11 +6,27 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
exports.removeAll = exports.remove = exports.is = exports.addAll = exports.add = undefined; | ||
exports.removeAll = exports.remove = exports.is = exports.addAll = exports.add = void 0; | ||
var _curry = require('ramda/src/curry'); | ||
var _curry = _interopRequireDefault(require("ramda/src/curry")); | ||
var _curry2 = _interopRequireDefault(_curry); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/** | ||
* Manages a map of names to key codes to simplify event handlers | ||
* | ||
* ``` | ||
* import {add, is} from '@enact/core/keymap'; | ||
* | ||
* add('enter', 13); | ||
* const isEnter = is('enter'); | ||
* | ||
* // within event handler | ||
* if (isEnter(ev.keyCode)) { | ||
* // handle enter | ||
* } | ||
* ``` | ||
* | ||
* @module core/keymap | ||
*/ | ||
/** | ||
* The singleton map of names to keyCodes. If a name doesn't have any keyCodes mapped to it, it will | ||
@@ -23,3 +39,2 @@ * not exist in this map. If it does, its value will be an array of its keyCodes. | ||
var map = {}; | ||
/** | ||
@@ -35,19 +50,2 @@ * Utility to safely convert keymap name to lower case | ||
*/ | ||
/** | ||
* Manages a map of names to key codes to simplify event handlers | ||
* | ||
* ``` | ||
* import {add, is} from '@enact/core/keymap'; | ||
* | ||
* add('enter', 13); | ||
* const isEnter = is('enter'); | ||
* | ||
* // within event handler | ||
* if (isEnter(ev.keyCode)) { | ||
* // handle enter | ||
* } | ||
* ``` | ||
* | ||
* @module core/keymap | ||
*/ | ||
@@ -57,3 +55,2 @@ var toLowerCase = function toLowerCase(name) { | ||
}; | ||
/** | ||
@@ -70,3 +67,5 @@ * Iterates over `set` and invokes `fn` with the key and value of each item | ||
*/ | ||
var forEachObj = (0, _curry2.default)(function (fn, set) { | ||
var forEachObj = (0, _curry.default)(function (fn, set) { | ||
Object.keys(set).forEach(function (name) { | ||
@@ -76,3 +75,2 @@ return fn(name, set[name]); | ||
}); | ||
/** | ||
@@ -90,3 +88,4 @@ * Invokes `fn` with `name` and `keyCode` for each key code provided | ||
*/ | ||
var oneOrArray = (0, _curry2.default)(function (fn, name, keyCode) { | ||
var oneOrArray = (0, _curry.default)(function (fn, name, keyCode) { | ||
if (Array.isArray(keyCode)) { | ||
@@ -98,3 +97,2 @@ keyCode.forEach(fn(name)); | ||
}); | ||
/** | ||
@@ -111,6 +109,9 @@ * Adds `keyCode` to `name` | ||
*/ | ||
var addOne = (0, _curry2.default)(function (name, keyCode) { | ||
var addOne = (0, _curry.default)(function (name, keyCode) { | ||
name = toLowerCase(name); | ||
if (name in map) { | ||
var index = map[name].indexOf(keyCode); | ||
if (index === -1) { | ||
@@ -123,3 +124,2 @@ map[name].push(keyCode); | ||
}); | ||
/** | ||
@@ -136,7 +136,10 @@ * Removes `keyCode` from `name`. | ||
*/ | ||
var removeOne = (0, _curry2.default)(function (name, keyCode) { | ||
var removeOne = (0, _curry.default)(function (name, keyCode) { | ||
name = toLowerCase(name); | ||
if (name in map) { | ||
var keys = map[name]; | ||
var index = keys.indexOf(keyCode); | ||
if (index === -1) { | ||
@@ -149,3 +152,2 @@ delete map[name]; | ||
}); | ||
/** | ||
@@ -162,4 +164,4 @@ * Registers `keyCode` for `name` | ||
*/ | ||
var add = oneOrArray(addOne); | ||
/** | ||
@@ -175,4 +177,5 @@ * Registers a set of key codes. | ||
*/ | ||
exports.add = add; | ||
var addAll = forEachObj(add); | ||
/** | ||
@@ -189,4 +192,5 @@ * Deregisters `keyCode` from `name`. | ||
*/ | ||
exports.addAll = addAll; | ||
var remove = oneOrArray(removeOne); | ||
/** | ||
@@ -202,4 +206,5 @@ * Deregisters a set of key codes. | ||
*/ | ||
exports.remove = remove; | ||
var removeAll = forEachObj(remove); | ||
/** | ||
@@ -216,11 +221,8 @@ * Determines if `keyCode` is mapped to `name`. | ||
*/ | ||
var is = (0, _curry2.default)(function (name, keyCode) { | ||
exports.removeAll = removeAll; | ||
var is = (0, _curry.default)(function (name, keyCode) { | ||
name = toLowerCase(name); | ||
return name in map && map[name].indexOf(keyCode) >= 0; | ||
}); | ||
exports.add = add; | ||
exports.addAll = addAll; | ||
exports.is = is; | ||
exports.remove = remove; | ||
exports.removeAll = removeAll; | ||
exports.is = is; |
@@ -1,103 +0,73 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _ = require('../'); | ||
var keymap = _interopRequireWildcard(require("../")); | ||
var keymap = _interopRequireWildcard(_); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | ||
describe('keymap', function () { | ||
it('should support adding single keyCodes for a name', function () { | ||
keymap.add('testEnter', 13); | ||
var expected = true; | ||
var actual = keymap.is('testEnter', 13); | ||
keymap.remove('testEnter', 13); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should support removing a single keyCode for a name', function () { | ||
keymap.add('testEnter', 13); | ||
keymap.remove('testEnter', 13); | ||
var expected = false; | ||
var actual = keymap.is('testEnter', 13); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should support adding an array of keyCodes for a name', function () { | ||
keymap.add('testEnter', [13, 16777221]); | ||
var expected = true; | ||
var actual = keymap.is('testEnter', 13) && keymap.is('testEnter', 16777221); | ||
keymap.remove('testEnter', [13, 16777221]); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should support removing an array of keyCodes for a name', function () { | ||
keymap.add('testEnter', [13, 16777221]); | ||
keymap.remove('testEnter', [13, 16777221]); | ||
var expected = false; | ||
var actual = keymap.is('testEnter', 13) || keymap.is('testEnter', 16777221); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should support adding an map of keyCodes', function () { | ||
var map = { | ||
testEnter: [13, 16777221], | ||
testUp: 38, | ||
testDown: 40 | ||
}; | ||
keymap.addAll(map); | ||
var expected = true; | ||
var actual = keymap.is('testEnter', 13) && keymap.is('testEnter', 16777221) && keymap.is('testUp', 38) && keymap.is('testDown', 40); | ||
keymap.removeAll(map); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should removing an map of keyCodes', function () { | ||
var map = { | ||
testEnter: [13, 16777221], | ||
testUp: 38, | ||
testDown: 40 | ||
}; | ||
keymap.addAll(map); | ||
keymap.removeAll(map); | ||
var expected = false; | ||
var actual = keymap.is('testEnter', 13) || keymap.is('testEnter', 16777221) || keymap.is('testUp', 38) || keymap.is('testDown', 40); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should use case-insensitive names', function () { | ||
keymap.add('testEnter', 13); | ||
var expected = true; | ||
var actual = keymap.is('TeStEnTeR', 13); | ||
keymap.remove('testEnter', 13); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should not add entry with a falsey name', function () { | ||
keymap.add('', 13); | ||
var expected = false; | ||
var actual = keymap.is('', 13); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should support adding single keyCodes for a name', function () { | ||
keymap.add('testEnter', 13); | ||
var expected = true; | ||
var actual = keymap.is('testEnter', 13); | ||
keymap.remove('testEnter', 13); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should support removing a single keyCode for a name', function () { | ||
keymap.add('testEnter', 13); | ||
keymap.remove('testEnter', 13); | ||
var expected = false; | ||
var actual = keymap.is('testEnter', 13); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should support adding an array of keyCodes for a name', function () { | ||
keymap.add('testEnter', [13, 16777221]); | ||
var expected = true; | ||
var actual = keymap.is('testEnter', 13) && keymap.is('testEnter', 16777221); | ||
keymap.remove('testEnter', [13, 16777221]); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should support removing an array of keyCodes for a name', function () { | ||
keymap.add('testEnter', [13, 16777221]); | ||
keymap.remove('testEnter', [13, 16777221]); | ||
var expected = false; | ||
var actual = keymap.is('testEnter', 13) || keymap.is('testEnter', 16777221); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should support adding an map of keyCodes', function () { | ||
var map = { | ||
testEnter: [13, 16777221], | ||
testUp: 38, | ||
testDown: 40 | ||
}; | ||
keymap.addAll(map); | ||
var expected = true; | ||
var actual = keymap.is('testEnter', 13) && keymap.is('testEnter', 16777221) && keymap.is('testUp', 38) && keymap.is('testDown', 40); | ||
keymap.removeAll(map); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should removing an map of keyCodes', function () { | ||
var map = { | ||
testEnter: [13, 16777221], | ||
testUp: 38, | ||
testDown: 40 | ||
}; | ||
keymap.addAll(map); | ||
keymap.removeAll(map); | ||
var expected = false; | ||
var actual = keymap.is('testEnter', 13) || keymap.is('testEnter', 16777221) || keymap.is('testUp', 38) || keymap.is('testDown', 40); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should use case-insensitive names', function () { | ||
keymap.add('testEnter', 13); | ||
var expected = true; | ||
var actual = keymap.is('TeStEnTeR', 13); | ||
keymap.remove('testEnter', 13); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should not add entry with a falsey name', function () { | ||
keymap.add('', 13); | ||
var expected = false; | ||
var actual = keymap.is('', 13); | ||
expect(actual).to.equal(expected); | ||
}); | ||
}); |
@@ -6,2 +6,4 @@ "use strict"; | ||
}); | ||
exports.computed = exports.default = void 0; | ||
/** | ||
@@ -32,8 +34,9 @@ * Accepts an object of computed property configurations and a property object, passes the property | ||
var computed = function computed(cfg, props) { | ||
for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { | ||
var keys = Object.keys(cfg); | ||
var updated = {}; | ||
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { | ||
args[_key - 2] = arguments[_key]; | ||
} | ||
var keys = Object.keys(cfg); | ||
var updated = {}; | ||
for (var i = keys.length - 1; i >= 0; i--) { | ||
@@ -46,3 +49,4 @@ updated[keys[i]] = cfg[keys[i]].apply(cfg, [props].concat(args)); | ||
exports.default = computed; | ||
exports.computed = computed; | ||
exports.computed = computed; | ||
var _default = computed; | ||
exports.default = _default; |
@@ -6,2 +6,4 @@ "use strict"; | ||
}); | ||
exports.contextTypes = exports.default = void 0; | ||
/** | ||
@@ -20,3 +22,4 @@ * Adds contextTypes to a render | ||
exports.default = contextTypes; | ||
exports.contextTypes = contextTypes; | ||
exports.contextTypes = contextTypes; | ||
var _default = contextTypes; | ||
exports.default = _default; |
@@ -6,2 +6,4 @@ "use strict"; | ||
}); | ||
exports.defaultProps = exports.default = void 0; | ||
/** | ||
@@ -20,3 +22,4 @@ * Adds default props to a render | ||
exports.default = defaultProps; | ||
exports.defaultProps = defaultProps; | ||
exports.defaultProps = defaultProps; | ||
var _default = defaultProps; | ||
exports.default = _default; |
@@ -1,24 +0,28 @@ | ||
'use strict'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
value: true | ||
}); | ||
exports.handlers = undefined; | ||
exports.handlers = exports.default = void 0; | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var _react = _interopRequireDefault(require("react")); | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _react = require('react'); | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
var _react2 = _interopRequireDefault(_react); | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
/** | ||
@@ -43,49 +47,60 @@ * Accepts an object of event handlers and a Component and returns a React Component that creates | ||
var handlers = function handlers(cfg, Component) { | ||
var _class, _temp; | ||
var _class, _temp; | ||
return _temp = _class = function (_React$Component) { | ||
_inherits(_class, _React$Component); | ||
return _temp = _class = | ||
/*#__PURE__*/ | ||
function (_React$Component) { | ||
_inherits(_class, _React$Component); | ||
function _class() { | ||
_classCallCheck(this, _class); | ||
function _class() { | ||
var _this; | ||
var _this = _possibleConstructorReturn(this, (_class.__proto__ || Object.getPrototypeOf(_class)).call(this)); | ||
_classCallCheck(this, _class); | ||
_this.prepareHandler = function (name, handler) { | ||
_this.handlers[name] = function (ev) { | ||
handler(ev, _this.props, _this.context); | ||
}; | ||
}; | ||
_this = _possibleConstructorReturn(this, (_class.__proto__ || Object.getPrototypeOf(_class)).call(this)); | ||
Object.defineProperty(_assertThisInitialized(_this), "prepareHandler", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: function value(name, handler) { | ||
_this.handlers[name] = function (ev) { | ||
handler(ev, _this.props, _this.context); | ||
}; | ||
} | ||
}); | ||
_this.handlers = {}; // cache bound function for each handler | ||
_this.handlers = {}; | ||
Object.keys(cfg).forEach(function (name) { | ||
return _this.prepareHandler(name, cfg[name]); | ||
}); | ||
return _this; | ||
} | ||
/** | ||
* Caches an event handler on the local `handlers` member | ||
* | ||
* @param {String} name Event name | ||
* @param {Function} handler Event handler | ||
* | ||
* @returns {undefined} | ||
*/ | ||
// cache bound function for each handler | ||
Object.keys(cfg).forEach(function (name) { | ||
return _this.prepareHandler(name, cfg[name]); | ||
}); | ||
return _this; | ||
} | ||
/** | ||
* Caches an event handler on the local `handlers` member | ||
* | ||
* @param {String} name Event name | ||
* @param {Function} handler Event handler | ||
* | ||
* @returns {undefined} | ||
*/ | ||
_createClass(_class, [{ | ||
key: "render", | ||
value: function render() { | ||
return _react.default.createElement(Component, _extends({}, this.props, this.handlers)); | ||
} | ||
}]); | ||
_createClass(_class, [{ | ||
key: 'render', | ||
value: function render() { | ||
return _react2.default.createElement(Component, _extends({}, this.props, this.handlers)); | ||
} | ||
}]); | ||
return _class; | ||
}(_react2.default.Component), _class.displayName = 'Handlers(' + (Component.displayName || Component.name || 'Component') + ')', _temp; | ||
return _class; | ||
}(_react.default.Component), Object.defineProperty(_class, "displayName", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: "Handlers(".concat(Component.displayName || Component.name || 'Component', ")") | ||
}), _temp; | ||
}; | ||
exports.default = handlers; | ||
exports.handlers = handlers; | ||
exports.handlers = handlers; | ||
var _default = handlers; | ||
exports.default = _default; |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,35 +6,27 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
exports.kind = undefined; | ||
exports.kind = exports.default = void 0; | ||
var _computed = require('./computed'); | ||
var _computed = _interopRequireDefault(require("./computed")); | ||
var _computed2 = _interopRequireDefault(_computed); | ||
var _contextTypes = _interopRequireDefault(require("./contextTypes")); | ||
var _contextTypes = require('./contextTypes'); | ||
var _defaultProps = _interopRequireDefault(require("./defaultProps")); | ||
var _contextTypes2 = _interopRequireDefault(_contextTypes); | ||
var _handlers = _interopRequireDefault(require("./handlers")); | ||
var _defaultProps = require('./defaultProps'); | ||
var _name = _interopRequireDefault(require("./name")); | ||
var _defaultProps2 = _interopRequireDefault(_defaultProps); | ||
var _propTypes = _interopRequireDefault(require("./propTypes")); | ||
var _handlers = require('./handlers'); | ||
var _styles = _interopRequireDefault(require("./styles")); | ||
var _handlers2 = _interopRequireDefault(_handlers); | ||
var _name = require('./name'); | ||
var _name2 = _interopRequireDefault(_name); | ||
var _propTypes = require('./propTypes'); | ||
var _propTypes2 = _interopRequireDefault(_propTypes); | ||
var _styles = require('./styles'); | ||
var _styles2 = _interopRequireDefault(_styles); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/** | ||
* Provides the {@link core/kind.kind} method to create components | ||
* | ||
* @module core/kind | ||
*/ | ||
/** | ||
* Creates a new component with some helpful declarative syntactic sugar. | ||
@@ -94,30 +86,25 @@ * | ||
var p = Object.assign({}, props); | ||
if (config.styles) p = (0, _styles2.default)(config.styles, p, context, updater); | ||
if (config.computed) p = (0, _computed2.default)(config.computed, p, context, updater); | ||
if (config.styles) p = (0, _styles.default)(config.styles, p, context, updater); | ||
if (config.computed) p = (0, _computed.default)(config.computed, p, context, updater); | ||
return config.render(p, context, updater); | ||
}; | ||
}; // render() decorations | ||
// render() decorations | ||
if (config.handlers) { | ||
// need to set name and contextTypes on pre-wrapped Component | ||
if (config.contextTypes) (0, _contextTypes2.default)(config.contextTypes, render); | ||
render = (0, _handlers2.default)(config.handlers, render, config.contextTypes); | ||
if (config.contextTypes) (0, _contextTypes.default)(config.contextTypes, render); | ||
render = (0, _handlers.default)(config.handlers, render, config.contextTypes); | ||
} | ||
if (config.name) (0, _name2.default)(config.name, render); | ||
if (config.propTypes) (0, _propTypes2.default)(config.propTypes, render); | ||
if (config.defaultProps) (0, _defaultProps2.default)(config.defaultProps, render); | ||
if (config.contextTypes) (0, _contextTypes2.default)(config.contextTypes, render); | ||
if (config.name) (0, _name.default)(config.name, render); | ||
if (config.propTypes) (0, _propTypes.default)(config.propTypes, render); | ||
if (config.defaultProps) (0, _defaultProps.default)(config.defaultProps, render); | ||
if (config.contextTypes) (0, _contextTypes.default)(config.contextTypes, render); // Decorate the SFC with the computed property object in DEV for easier testability | ||
// Decorate the SFC with the computed property object in DEV for easier testability | ||
if (process.env.NODE_ENV !== 'production' && config.computed) render.computed = config.computed; | ||
if (process.env.NODE_ENV !== "production" && config.computed) render.computed = config.computed; | ||
return render; | ||
}; /** | ||
* Provides the {@link core/kind.kind} method to create components | ||
* | ||
* @module core/kind | ||
*/ | ||
}; | ||
exports.default = kind; | ||
exports.kind = kind; | ||
exports.kind = kind; | ||
var _default = kind; | ||
exports.default = _default; |
@@ -6,2 +6,4 @@ "use strict"; | ||
}); | ||
exports.name = exports.default = void 0; | ||
/** | ||
@@ -21,3 +23,4 @@ * Adds displayName to a render | ||
exports.default = name; | ||
exports.name = name; | ||
exports.name = name; | ||
var _default = name; | ||
exports.default = _default; |
@@ -6,2 +6,4 @@ "use strict"; | ||
}); | ||
exports.propTypes = exports.default = void 0; | ||
/** | ||
@@ -20,3 +22,4 @@ * Adds propTypes to a render | ||
exports.default = propTypes; | ||
exports.propTypes = propTypes; | ||
exports.propTypes = propTypes; | ||
var _default = propTypes; | ||
exports.default = _default; |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,32 +6,23 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
exports.styles = undefined; | ||
exports.styles = exports.default = void 0; | ||
var _curry = require('ramda/src/curry'); | ||
var _curry = _interopRequireDefault(require("ramda/src/curry")); | ||
var _curry2 = _interopRequireDefault(_curry); | ||
var _compose = _interopRequireDefault(require("ramda/src/compose")); | ||
var _compose = require('ramda/src/compose'); | ||
var _merge = _interopRequireDefault(require("ramda/src/merge")); | ||
var _compose2 = _interopRequireDefault(_compose); | ||
var _classnames = _interopRequireDefault(require("classnames")); | ||
var _merge = require('ramda/src/merge'); | ||
var _util = require("./util"); | ||
var _merge2 = _interopRequireDefault(_merge); | ||
var _classnames = require('classnames'); | ||
var _classnames2 = _interopRequireDefault(_classnames); | ||
var _util = require('./util'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
// Joins two strings in a className-friendly way | ||
var joinClasses = (0, _curry2.default)(function (a, b) { | ||
var joinClasses = (0, _curry.default)(function (a, b) { | ||
return a + ' ' + b; | ||
}); | ||
}); // Creates a function accepting two arguments. When both are truthy, calls fn with both. If either | ||
// is falsey, returns the truthy one or the first if both are falsey. | ||
// Creates a function accepting two arguments. When both are truthy, calls fn with both. If either | ||
// is falsey, returns the truthy one or the first if both are falsey. | ||
var bothOrEither = (0, _curry2.default)(function (fn, a, b) { | ||
var bothOrEither = (0, _curry.default)(function (fn, a, b) { | ||
if (a && b) { | ||
@@ -42,12 +33,10 @@ return fn(a, b); | ||
} | ||
}); | ||
}); // Returns either the value for the property or the property name itself | ||
// Returns either the value for the property or the property name itself | ||
var propOrSelf = (0, _curry2.default)(function (obj, prop) { | ||
var propOrSelf = (0, _curry.default)(function (obj, prop) { | ||
return obj && obj[prop] || prop; | ||
}); | ||
}); // Takes a string (multiple classes can be space-delimited) and a css-modules object and resolves | ||
// the class names to their css-modules name | ||
// Takes a string (multiple classes can be space-delimited) and a css-modules object and resolves | ||
// the class names to their css-modules name | ||
var resolveClassNames = (0, _curry2.default)(function (css, className) { | ||
var resolveClassNames = (0, _curry.default)(function (css, className) { | ||
if (css && className) { | ||
@@ -58,5 +47,4 @@ return className.split(' ').map(propOrSelf(css)).join(' '); | ||
return className; | ||
}); | ||
}); // Takes a styles config object and either resolves `className` with `css` or `className` iself | ||
// Takes a styles config object and either resolves `className` with `css` or `className` iself | ||
var localClassName = function localClassName(_ref) { | ||
@@ -66,19 +54,16 @@ var css = _ref.css, | ||
return resolveClassNames(css, className) || ''; | ||
}; | ||
}; // Merges the locally-resolved className and the className from the props | ||
// Merges the locally-resolved className and the className from the props | ||
var mergeClassName = function mergeClassName(config, _ref2) { | ||
var className = _ref2.className; | ||
return bothOrEither(joinClasses, localClassName(config), className); | ||
}; | ||
}; // Merges the local style object and the style object from the props | ||
// Merges the local style object and the style object from the props | ||
var mergeStyle = function mergeStyle(_ref3, _ref4) { | ||
var componentStyle = _ref3.style; | ||
var authorStyle = _ref4.style; | ||
return bothOrEither(_merge2.default, componentStyle, authorStyle); | ||
return bothOrEither(_merge.default, componentStyle, authorStyle); | ||
}; | ||
/** | ||
@@ -93,10 +78,11 @@ * Creates the `join()` method of the styler | ||
*/ | ||
var join = function join(cfg) { | ||
if (cfg.css) { | ||
return (0, _compose2.default)(resolveClassNames(cfg.css), _classnames2.default); | ||
return (0, _compose.default)(resolveClassNames(cfg.css), _classnames.default); | ||
} | ||
return _classnames2.default; | ||
return _classnames.default; | ||
}; | ||
/** | ||
@@ -110,7 +96,8 @@ * Creates the `append()` method of the styler | ||
*/ | ||
var append = function append(props) { | ||
var j = props.styler.join; | ||
return props.className ? (0, _compose2.default)(joinClasses(props.className), j) : j; | ||
return props.className ? (0, _compose.default)(joinClasses(props.className), j) : j; | ||
}; | ||
/** | ||
@@ -150,6 +137,8 @@ * Merges external and internal CSS classes and style objects. Internal CSS classes can be | ||
*/ | ||
var styles = function styles(cfg, props) { | ||
var prop = cfg.prop || 'className'; | ||
var style = mergeStyle(cfg, props); | ||
var style = mergeStyle(cfg, props); | ||
if (style) { | ||
@@ -160,13 +149,13 @@ props.style = style; | ||
var className = mergeClassName(cfg, props); | ||
if (className) { | ||
props[prop] = className; | ||
} | ||
} // styler should not be automatically spread onto children | ||
// styler should not be automatically spread onto children | ||
(0, _util.addInternalProp)(props, 'styler', { | ||
join: join(cfg) | ||
}); | ||
}); // append requires the computed className property so it is built off the updated props rather | ||
// than the provided props | ||
// append requires the computed className property so it is built off the updated props rather | ||
// than the provided props | ||
props.styler.append = append(props); | ||
@@ -176,3 +165,4 @@ return props; | ||
exports.default = styles; | ||
exports.styles = styles; | ||
exports.styles = styles; | ||
var _default = styles; | ||
exports.default = _default; |
@@ -1,108 +0,88 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _computed = require('../computed'); | ||
var _computed = _interopRequireDefault(require("../computed")); | ||
var _computed2 = _interopRequireDefault(_computed); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/* globals describe, it, expect */ | ||
describe('computed', function () { | ||
var exampleCfg = { | ||
sum: function sum(_ref) { | ||
var x = _ref.x, | ||
y = _ref.y, | ||
z = _ref.z; | ||
return x + y + z; | ||
}, | ||
product: function product(_ref2) { | ||
var x = _ref2.x, | ||
y = _ref2.y, | ||
z = _ref2.z; | ||
return x * y * z; | ||
} | ||
}; | ||
var exampleProps = { | ||
x: 2, | ||
y: 3, | ||
z: 4 | ||
}; | ||
it('should add new props to updated object', function () { | ||
var props = { | ||
value: true | ||
}; | ||
var cfg = { | ||
count: function count() { | ||
return 1; | ||
} | ||
}; | ||
var updated = (0, _computed2.default)(cfg, props); | ||
var expected = 1; | ||
var actual = updated.count; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should overwrite properties with computed values', function () { | ||
var props = { | ||
value: true, | ||
count: 2 | ||
}; | ||
var cfg = { | ||
count: function count() { | ||
return 1; | ||
} | ||
}; | ||
var updated = (0, _computed2.default)(cfg, props); | ||
var expected = 1; | ||
var actual = updated.count; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should not leak updated prop values into other computed props', function () { | ||
var props = { | ||
count: 1 | ||
}; | ||
var cfg = { | ||
value: function value(_ref3) { | ||
var count = _ref3.count; | ||
return count + 5; | ||
}, | ||
count: function count(_ref4) { | ||
var _count = _ref4.count; | ||
return _count + 1; | ||
} | ||
}; | ||
var updated = (0, _computed2.default)(cfg, props); | ||
var expected = 6; | ||
var actual = updated.value; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should work with its documented example - sum', function () { | ||
var updated = (0, _computed2.default)(exampleCfg, exampleProps); | ||
var expected = 9; | ||
var actual = updated.sum; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should work with its documented example - product', function () { | ||
var updated = (0, _computed2.default)(exampleCfg, exampleProps); | ||
var expected = 24; | ||
var actual = updated.product; | ||
expect(actual).to.equal(expected); | ||
}); | ||
}); /* globals describe, it, expect */ | ||
var exampleCfg = { | ||
sum: function sum(_ref) { | ||
var x = _ref.x, | ||
y = _ref.y, | ||
z = _ref.z; | ||
return x + y + z; | ||
}, | ||
product: function product(_ref2) { | ||
var x = _ref2.x, | ||
y = _ref2.y, | ||
z = _ref2.z; | ||
return x * y * z; | ||
} | ||
}; | ||
var exampleProps = { | ||
x: 2, | ||
y: 3, | ||
z: 4 | ||
}; | ||
it('should add new props to updated object', function () { | ||
var props = { | ||
value: true | ||
}; | ||
var cfg = { | ||
count: function count() { | ||
return 1; | ||
} | ||
}; | ||
var updated = (0, _computed.default)(cfg, props); | ||
var expected = 1; | ||
var actual = updated.count; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should overwrite properties with computed values', function () { | ||
var props = { | ||
value: true, | ||
count: 2 | ||
}; | ||
var cfg = { | ||
count: function count() { | ||
return 1; | ||
} | ||
}; | ||
var updated = (0, _computed.default)(cfg, props); | ||
var expected = 1; | ||
var actual = updated.count; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should not leak updated prop values into other computed props', function () { | ||
var props = { | ||
count: 1 | ||
}; | ||
var cfg = { | ||
value: function value(_ref3) { | ||
var count = _ref3.count; | ||
return count + 5; | ||
}, | ||
count: function count(_ref4) { | ||
var _count = _ref4.count; | ||
return _count + 1; | ||
} | ||
}; | ||
var updated = (0, _computed.default)(cfg, props); | ||
var expected = 6; | ||
var actual = updated.value; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should work with its documented example - sum', function () { | ||
var updated = (0, _computed.default)(exampleCfg, exampleProps); | ||
var expected = 9; | ||
var actual = updated.sum; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should work with its documented example - product', function () { | ||
var updated = (0, _computed.default)(exampleCfg, exampleProps); | ||
var expected = 24; | ||
var actual = updated.product; | ||
expect(actual).to.equal(expected); | ||
}); | ||
}); |
@@ -1,26 +0,22 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _contextTypes = require('../contextTypes'); | ||
var _contextTypes = _interopRequireDefault(require("../contextTypes")); | ||
var _contextTypes2 = _interopRequireDefault(_contextTypes); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/* globals describe, it, expect */ | ||
describe('contextTypes', function () { | ||
it('should assign contextTypes to contextTypes of render method', function () { | ||
var render = function render() {}; | ||
it('should assign contextTypes to contextTypes of render method', function () { | ||
var render = function render() {}; | ||
var cfg = { | ||
foo: function foo() { | ||
return true; | ||
} | ||
}; | ||
(0, _contextTypes2.default)(cfg, render); | ||
var expected = true; | ||
var actual = render.contextTypes.foo(); | ||
expect(actual).to.equal(expected); | ||
}); | ||
}); /* globals describe, it, expect */ | ||
var cfg = { | ||
foo: function foo() { | ||
return true; | ||
} | ||
}; | ||
(0, _contextTypes.default)(cfg, render); | ||
var expected = true; | ||
var actual = render.contextTypes.foo(); | ||
expect(actual).to.equal(expected); | ||
}); | ||
}); |
@@ -1,66 +0,55 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _react = require('react'); | ||
var _react = _interopRequireDefault(require("react")); | ||
var _react2 = _interopRequireDefault(_react); | ||
var _enzyme = require("enzyme"); | ||
var _enzyme = require('enzyme'); | ||
var _defaultProps = _interopRequireDefault(require("../defaultProps")); | ||
var _defaultProps = require('../defaultProps'); | ||
var _defaultProps2 = _interopRequireDefault(_defaultProps); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/* globals describe, it, expect */ | ||
describe('defaultProps', function () { | ||
var Simple = function Simple(props) { | ||
return _react.default.createElement("div", props); | ||
}; | ||
var Simple = function Simple(props) { | ||
return _react2.default.createElement('div', props); | ||
}; | ||
Simple.defaultProps = { | ||
color: 'blue', | ||
children: 'Content' | ||
}; | ||
Simple.defaultProps = { | ||
color: 'blue', | ||
children: 'Content' | ||
}; | ||
it('should assign object to defaultProps on render method', function () { | ||
var render = function render() {}; | ||
it('should assign object to defaultProps on render method', function () { | ||
var render = function render() {}; | ||
var props = { | ||
value: true | ||
}; | ||
(0, _defaultProps2.default)(props, render); | ||
var expected = true; | ||
var actual = render.defaultProps.value; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should add omitted props', function () { | ||
var subject = (0, _enzyme.shallow)(_react2.default.createElement(Simple, null)); | ||
var expected = Simple.defaultProps.children; | ||
var actual = subject.prop('children'); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should add explicitly undefined props', function () { | ||
var subject = (0, _enzyme.shallow)(_react2.default.createElement(Simple, { color: void 0 })); | ||
var expected = Simple.defaultProps.color; | ||
var actual = subject.prop('color'); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should allow defaults to be overridden', function () { | ||
var color = 'green'; | ||
var subject = (0, _enzyme.shallow)(_react2.default.createElement(Simple, { color: color })); | ||
var expected = color; | ||
var actual = subject.prop('color'); | ||
expect(actual).to.equal(expected); | ||
}); | ||
}); /* globals describe, it, expect */ | ||
var props = { | ||
value: true | ||
}; | ||
(0, _defaultProps.default)(props, render); | ||
var expected = true; | ||
var actual = render.defaultProps.value; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should add omitted props', function () { | ||
var subject = (0, _enzyme.shallow)(_react.default.createElement(Simple, null)); | ||
var expected = Simple.defaultProps.children; | ||
var actual = subject.prop('children'); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should add explicitly undefined props', function () { | ||
var subject = (0, _enzyme.shallow)(_react.default.createElement(Simple, { | ||
color: void 0 | ||
})); | ||
var expected = Simple.defaultProps.color; | ||
var actual = subject.prop('color'); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should allow defaults to be overridden', function () { | ||
var color = 'green'; | ||
var subject = (0, _enzyme.shallow)(_react.default.createElement(Simple, { | ||
color: color | ||
})); | ||
var expected = color; | ||
var actual = subject.prop('color'); | ||
expect(actual).to.equal(expected); | ||
}); | ||
}); |
@@ -1,114 +0,100 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var _react = _interopRequireDefault(require("react")); | ||
var _react = require('react'); | ||
var _propTypes = _interopRequireDefault(require("prop-types")); | ||
var _react2 = _interopRequireDefault(_react); | ||
var _enzyme = require("enzyme"); | ||
var _propTypes = require('prop-types'); | ||
var _kind = _interopRequireDefault(require("../kind")); | ||
var _propTypes2 = _interopRequireDefault(_propTypes); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _enzyme = require('enzyme'); | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
var _kind = require('../kind'); | ||
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } | ||
var _kind2 = _interopRequireDefault(_kind); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } | ||
describe('kind', function () { | ||
var Kind = (0, _kind.default)({ | ||
name: 'Kind', | ||
propTypes: { | ||
prop: _propTypes.default.number.isRequired, | ||
label: _propTypes.default.string | ||
}, | ||
defaultProps: { | ||
label: 'Label' | ||
}, | ||
contextTypes: { | ||
parentLabel: _propTypes.default.string | ||
}, | ||
styles: { | ||
className: 'kind' | ||
}, | ||
handlers: { | ||
onClick: function onClick() {} | ||
}, | ||
computed: { | ||
value: function value(_ref) { | ||
var prop = _ref.prop; | ||
return prop + 1; | ||
} | ||
}, | ||
render: function render(_ref2) { | ||
var label = _ref2.label, | ||
value = _ref2.value, | ||
rest = _objectWithoutProperties(_ref2, ["label", "value"]); | ||
var Kind = (0, _kind2.default)({ | ||
name: 'Kind', | ||
propTypes: { | ||
prop: _propTypes2.default.number.isRequired, | ||
label: _propTypes2.default.string | ||
}, | ||
defaultProps: { | ||
label: 'Label' | ||
}, | ||
contextTypes: { | ||
parentLabel: _propTypes2.default.string | ||
}, | ||
styles: { | ||
className: 'kind' | ||
}, | ||
handlers: { | ||
onClick: function onClick() {} | ||
}, | ||
computed: { | ||
value: function value(_ref) { | ||
var prop = _ref.prop; | ||
return prop + 1; | ||
} | ||
}, | ||
render: function render(_ref2) { | ||
var label = _ref2.label, | ||
value = _ref2.value, | ||
rest = _objectWithoutProperties(_ref2, ['label', 'value']); | ||
delete rest.prop; | ||
return _react.default.createElement("div", _extends({}, rest, { | ||
title: label | ||
}), value); | ||
} | ||
}); | ||
it('should assign name to displayName', function () { | ||
var expected = 'Kind'; | ||
var actual = Kind.displayName; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should default {label} property', function () { | ||
var subject = _react.default.createElement(Kind, { | ||
prop: 1 | ||
}); | ||
delete rest.prop; | ||
return _react2.default.createElement( | ||
'div', | ||
_extends({}, rest, { title: label }), | ||
value | ||
); | ||
} | ||
}); | ||
var expected = 'Label'; | ||
var actual = subject.props.label; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should default {label} property when explicitly undefined', function () { | ||
// Explicitly testing for undefined | ||
// eslint-disable-next-line no-undefined | ||
var subject = _react.default.createElement(Kind, { | ||
prop: 1, | ||
label: undefined | ||
}); | ||
it('should assign name to displayName', function () { | ||
var expected = 'Kind'; | ||
var actual = Kind.displayName; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should default {label} property', function () { | ||
var subject = _react2.default.createElement(Kind, { prop: 1 }); | ||
var expected = 'Label'; | ||
var actual = subject.props.label; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should default {label} property when explicitly undefined', function () { | ||
// Explicitly testing for undefined | ||
// eslint-disable-next-line no-undefined | ||
var subject = _react2.default.createElement(Kind, { prop: 1, label: undefined }); | ||
var expected = 'Label'; | ||
var actual = subject.props.label; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should add className defined in styles', function () { | ||
var subject = (0, _enzyme.mount)(_react2.default.createElement(Kind, { prop: 1 })); | ||
var expected = 'kind'; | ||
var actual = subject.find('div').prop('className'); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should compute {value} property', function () { | ||
var subject = (0, _enzyme.mount)(_react2.default.createElement(Kind, { prop: 1 })); | ||
var expected = 2; | ||
var actual = subject.find('div').prop('children'); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should assign contextTypes when handlers are specified', function () { | ||
var actual = Kind.contextTypes != null; | ||
var expected = true; | ||
expect(actual).to.equal(expected); | ||
}); | ||
var expected = 'Label'; | ||
var actual = subject.props.label; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should add className defined in styles', function () { | ||
var subject = (0, _enzyme.mount)(_react.default.createElement(Kind, { | ||
prop: 1 | ||
})); | ||
var expected = 'kind'; | ||
var actual = subject.find('div').prop('className'); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should compute {value} property', function () { | ||
var subject = (0, _enzyme.mount)(_react.default.createElement(Kind, { | ||
prop: 1 | ||
})); | ||
var expected = 2; | ||
var actual = subject.find('div').prop('children'); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should assign contextTypes when handlers are specified', function () { | ||
var actual = Kind.contextTypes != null; | ||
var expected = true; | ||
expect(actual).to.equal(expected); | ||
}); | ||
}); |
@@ -1,22 +0,18 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _name = require('../name'); | ||
var _name = _interopRequireDefault(require("../name")); | ||
var _name2 = _interopRequireDefault(_name); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/* globals describe, it, expect */ | ||
describe('name', function () { | ||
it('should assign name to displayName of render method', function () { | ||
var render = function render() {}; | ||
it('should assign name to displayName of render method', function () { | ||
var render = function render() {}; | ||
var cfg = 'MyComponent'; | ||
(0, _name2.default)(cfg, render); | ||
var expected = cfg; | ||
var actual = render.displayName; | ||
expect(actual).to.equal(expected); | ||
}); | ||
}); /* globals describe, it, expect */ | ||
var cfg = 'MyComponent'; | ||
(0, _name.default)(cfg, render); | ||
var expected = cfg; | ||
var actual = render.displayName; | ||
expect(actual).to.equal(expected); | ||
}); | ||
}); |
@@ -1,26 +0,22 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _propTypes = require('../propTypes'); | ||
var _propTypes = _interopRequireDefault(require("../propTypes")); | ||
var _propTypes2 = _interopRequireDefault(_propTypes); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/* globals describe, it, expect */ | ||
describe('propTypes', function () { | ||
it('should assign propTypes to propTypes of render method', function () { | ||
var render = function render() {}; | ||
it('should assign propTypes to propTypes of render method', function () { | ||
var render = function render() {}; | ||
var cfg = { | ||
count: function count() { | ||
return true; | ||
} | ||
}; | ||
(0, _propTypes2.default)(cfg, render); | ||
var expected = true; | ||
var actual = render.propTypes.count(); | ||
expect(actual).to.equal(expected); | ||
}); | ||
}); /* globals describe, it, expect */ | ||
var cfg = { | ||
count: function count() { | ||
return true; | ||
} | ||
}; | ||
(0, _propTypes.default)(cfg, render); | ||
var expected = true; | ||
var actual = render.propTypes.count(); | ||
expect(actual).to.equal(expected); | ||
}); | ||
}); |
/* globals describe, it, expect */ | ||
// Removing the ref feature for now (or permanently) | ||
// Removing the ref feature for now (or permanently) | ||
/* | ||
@@ -5,0 +5,0 @@ import ref from '../ref'; |
@@ -1,225 +0,174 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; /* globals describe, it, expect */ | ||
var _styles = _interopRequireDefault(require("../styles")); | ||
var _styles = require('../styles'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _styles2 = _interopRequireDefault(_styles); | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
describe('styles', function () { | ||
var css = { | ||
button: 'unambiguous-button-class-name', | ||
client: 'unambiguous-button-class-name-client' | ||
}; // className tests | ||
var css = { | ||
button: 'unambiguous-button-class-name', | ||
client: 'unambiguous-button-class-name-client' | ||
}; | ||
it('should add cfg.className to props', function () { | ||
var cfg = { | ||
className: 'button' | ||
}; | ||
var updated = (0, _styles.default)(cfg, {}); | ||
var expected = cfg.className; | ||
var actual = updated.className; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should resolve cfg.className to the cfg.css map', function () { | ||
var cfg = { | ||
css: css, | ||
className: 'button' | ||
}; | ||
var updated = (0, _styles.default)(cfg, {}); | ||
var expected = css.button; | ||
var actual = updated.className; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should pass through props.className when cfg.className absent', function () { | ||
var props = { | ||
className: 'button' | ||
}; | ||
var updated = (0, _styles.default)({}, props); | ||
var expected = props.className; | ||
var actual = updated.className; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should append cfg.className with props.className', function () { | ||
var props = { | ||
className: 'custom-button' | ||
}; | ||
var cfg = { | ||
className: 'button' | ||
}; | ||
var updated = (0, _styles.default)(cfg, props); | ||
var expected = props.className; | ||
var actual = updated.className; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should resolve cfg.className and append with props.className', function () { | ||
var props = { | ||
className: 'custom-button' | ||
}; | ||
var cfg = { | ||
css: css, | ||
className: 'button' | ||
}; | ||
var updated = (0, _styles.default)(cfg, props); | ||
var expected = props.className; | ||
var actual = updated.className; | ||
expect(actual).to.equal(expected); | ||
}); // style tests | ||
// className tests | ||
it('should add cfg.style to props', function () { | ||
var cfg = { | ||
style: { | ||
color: 'green' | ||
} | ||
}; | ||
var updated = (0, _styles.default)(cfg, {}); | ||
var expected = cfg.style.color; | ||
var actual = updated.style.color; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should pass through props.style when cfg.style absent', function () { | ||
var props = { | ||
style: { | ||
color: 'green' | ||
} | ||
}; | ||
var updated = (0, _styles.default)({}, props); | ||
var expected = props.style.color; | ||
var actual = updated.style.color; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should merge cfg.style and props.style', function () { | ||
var props = { | ||
style: { | ||
color: 'green' | ||
} | ||
}; | ||
var cfg = { | ||
style: { | ||
border: '1px solid black' | ||
} | ||
}; | ||
var updated = (0, _styles.default)(cfg, props); | ||
var expected = 2; | ||
var actual = Object.keys(updated.style).length; | ||
expect(actual).to.equal(expected); | ||
}); // Doesn't support merging shorthand properties and individual properties | ||
// e.g. borderWidth: 3px + border: 1px solid black = border: 3px solid black | ||
it('should add cfg.className to props', function () { | ||
var cfg = { | ||
className: 'button' | ||
}; | ||
it('should not merge shorthand properties', function () { | ||
var props = { | ||
style: { | ||
borderWidth: '3px' | ||
} | ||
}; | ||
var cfg = { | ||
style: { | ||
border: '1px solid black' | ||
} | ||
}; | ||
var updated = (0, _styles.default)(cfg, props); | ||
var expected = 1; | ||
var actual = Object.keys(updated.style).length; | ||
expect(actual).to.not.equal(expected); | ||
}); // styler tests | ||
var updated = (0, _styles2.default)(cfg, {}); | ||
it('should add styler.join() to props', function () { | ||
var updated = (0, _styles.default)({}, {}); | ||
var expected = 'function'; | ||
var expected = cfg.className; | ||
var actual = updated.className; | ||
var actual = _typeof(updated.styler.join); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should resolve cfg.className to the cfg.css map', function () { | ||
var cfg = { | ||
css: css, | ||
className: 'button' | ||
}; | ||
var updated = (0, _styles2.default)(cfg, {}); | ||
var expected = css.button; | ||
var actual = updated.className; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should pass through props.className when cfg.className absent', function () { | ||
var props = { | ||
className: 'button' | ||
}; | ||
var updated = (0, _styles2.default)({}, props); | ||
var expected = props.className; | ||
var actual = updated.className; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should append cfg.className with props.className', function () { | ||
var props = { | ||
className: 'custom-button' | ||
}; | ||
var cfg = { | ||
className: 'button' | ||
}; | ||
var updated = (0, _styles2.default)(cfg, props); | ||
var expected = props.className; | ||
var actual = updated.className; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should resolve cfg.className and append with props.className', function () { | ||
var props = { | ||
className: 'custom-button' | ||
}; | ||
var cfg = { | ||
css: css, | ||
className: 'button' | ||
}; | ||
var updated = (0, _styles2.default)(cfg, props); | ||
var expected = props.className; | ||
var actual = updated.className; | ||
expect(actual).to.equal(expected); | ||
}); | ||
// style tests | ||
it('should add cfg.style to props', function () { | ||
var cfg = { | ||
style: { | ||
color: 'green' | ||
} | ||
}; | ||
var updated = (0, _styles2.default)(cfg, {}); | ||
var expected = cfg.style.color; | ||
var actual = updated.style.color; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should pass through props.style when cfg.style absent', function () { | ||
var props = { | ||
style: { | ||
color: 'green' | ||
} | ||
}; | ||
var updated = (0, _styles2.default)({}, props); | ||
var expected = props.style.color; | ||
var actual = updated.style.color; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should merge cfg.style and props.style', function () { | ||
var props = { | ||
style: { | ||
color: 'green' | ||
} | ||
}; | ||
var cfg = { | ||
style: { | ||
border: '1px solid black' | ||
} | ||
}; | ||
var updated = (0, _styles2.default)(cfg, props); | ||
var expected = 2; | ||
var actual = Object.keys(updated.style).length; | ||
expect(actual).to.equal(expected); | ||
}); | ||
// Doesn't support merging shorthand properties and individual properties | ||
// e.g. borderWidth: 3px + border: 1px solid black = border: 3px solid black | ||
it('should not merge shorthand properties', function () { | ||
var props = { | ||
style: { | ||
borderWidth: '3px' | ||
} | ||
}; | ||
var cfg = { | ||
style: { | ||
border: '1px solid black' | ||
} | ||
}; | ||
var updated = (0, _styles2.default)(cfg, props); | ||
var expected = 1; | ||
var actual = Object.keys(updated.style).length; | ||
expect(actual).to.not.equal(expected); | ||
}); | ||
// styler tests | ||
it('should add styler.join() to props', function () { | ||
var updated = (0, _styles2.default)({}, {}); | ||
var expected = 'function'; | ||
var actual = _typeof(updated.styler.join); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should join classes together with a space', function () { | ||
var updated = (0, _styles2.default)({}, {}); | ||
var expected = 'abc def'; | ||
var actual = updated.styler.join('abc', 'def'); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should resolve join classes to css map', function () { | ||
var updated = (0, _styles2.default)({ css: css }, {}); | ||
var expected = css.button + ' ' + css.client; | ||
var actual = updated.styler.join('button', 'client'); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should not resolve author classes to css map', function () { | ||
var cfg = { | ||
css: css, | ||
className: 'button' | ||
}; | ||
var props = { | ||
className: 'button' | ||
}; | ||
var updated = (0, _styles2.default)(cfg, props); | ||
var expected = css.button + ' button'; | ||
var actual = updated.className; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should append resolved class names to props.className', function () { | ||
var cfg = { | ||
css: css, | ||
className: 'button' | ||
}; | ||
var props = { | ||
className: 'button' | ||
}; | ||
var updated = (0, _styles2.default)(cfg, props); | ||
var expected = css.button + ' button ' + css.client; | ||
var actual = updated.styler.append('client'); | ||
expect(actual).to.equal(expected); | ||
}); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should join classes together with a space', function () { | ||
var updated = (0, _styles.default)({}, {}); | ||
var expected = 'abc def'; | ||
var actual = updated.styler.join('abc', 'def'); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should resolve join classes to css map', function () { | ||
var updated = (0, _styles.default)({ | ||
css: css | ||
}, {}); | ||
var expected = css.button + ' ' + css.client; | ||
var actual = updated.styler.join('button', 'client'); | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should not resolve author classes to css map', function () { | ||
var cfg = { | ||
css: css, | ||
className: 'button' | ||
}; | ||
var props = { | ||
className: 'button' | ||
}; | ||
var updated = (0, _styles.default)(cfg, props); | ||
var expected = css.button + ' button'; | ||
var actual = updated.className; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('should append resolved class names to props.className', function () { | ||
var cfg = { | ||
css: css, | ||
className: 'button' | ||
}; | ||
var props = { | ||
className: 'button' | ||
}; | ||
var updated = (0, _styles.default)(cfg, props); | ||
var expected = css.button + ' button ' + css.client; | ||
var actual = updated.styler.append('client'); | ||
expect(actual).to.equal(expected); | ||
}); | ||
}); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
value: true | ||
}); | ||
var addInternalProp = exports.addInternalProp = function addInternalProp(props, name, value) { | ||
if (name in props) { | ||
props[name] = value; | ||
} else { | ||
Object.defineProperty(props, name, { | ||
value: value, | ||
enumerable: false, | ||
writable: true | ||
}); | ||
} | ||
exports.addInternalProp = void 0; | ||
return props; | ||
}; | ||
var addInternalProp = function addInternalProp(props, name, value) { | ||
if (name in props) { | ||
props[name] = value; | ||
} else { | ||
Object.defineProperty(props, name, { | ||
value: value, | ||
enumerable: false, | ||
writable: true | ||
}); | ||
} | ||
return props; | ||
}; | ||
exports.addInternalProp = addInternalProp; |
{ | ||
"name": "@enact/core", | ||
"version": "1.13.3", | ||
"version": "1.13.4", | ||
"description": "Enact is an open source JavaScript framework containing everything you need to create a fast, scalable mobile or web application.", | ||
@@ -31,9 +31,9 @@ "main": "index.js", | ||
"dependencies": { | ||
"classnames": "~2.2.5", | ||
"invariant": "~2.2.2", | ||
"prop-types": "~15.6.0", | ||
"ramda": "~0.24.1", | ||
"react": "~15.6.1", | ||
"react-dom": "~15.6.1" | ||
"classnames": "^2.2.6", | ||
"invariant": "^2.2.4", | ||
"prop-types": "^15.6.2", | ||
"ramda": "^0.24.1", | ||
"react": "^15.6.2", | ||
"react-dom": "^15.6.2" | ||
} | ||
} |
@@ -1,83 +0,143 @@ | ||
'use strict'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
value: true | ||
}); | ||
exports.platform = exports.detect = undefined; | ||
exports.platform = exports.detect = exports.default = void 0; | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; /** | ||
* Exports the {@link core/platform.detect} method and the {@link core/platform.platform} | ||
* object to get information about the current platform. The default export is | ||
* {@link core/platform.platform}. | ||
* | ||
* @module core/platform | ||
*/ | ||
var _uniq = _interopRequireDefault(require("ramda/src/uniq")); | ||
var _uniq = require('ramda/src/uniq'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _uniq2 = _interopRequireDefault(_uniq); | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); } | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); } | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
var hasGesture = function hasGesture() { | ||
return Boolean('ongesturestart' in window || 'onmsgesturestart' in window && (window.navigator.msMaxTouchPoints > 1 || window.navigator.maxTouchPoints > 1)); | ||
return Boolean('ongesturestart' in window || 'onmsgesturestart' in window && (window.navigator.msMaxTouchPoints > 1 || window.navigator.maxTouchPoints > 1)); | ||
}; | ||
var hasTouch = function hasTouch() { | ||
return Boolean('ontouchstart' in window || window.navigator.msMaxTouchPoints || window.navigator.msManipulationViewsEnabled && window.navigator.maxTouchPoints); | ||
return Boolean('ontouchstart' in window || window.navigator.msMaxTouchPoints || window.navigator.msManipulationViewsEnabled && window.navigator.maxTouchPoints); | ||
}; | ||
var platforms = [ | ||
// Windows Phone 7 - 10 | ||
{ platform: 'windowsPhone', regex: /Windows Phone (?:OS )?(\d+)[.\d]+/ }, | ||
// Android 4+ using Chrome | ||
{ platform: 'androidChrome', regex: /Android .* Chrome\/(\d+)[.\d]+/ }, | ||
// Android 2 - 4 | ||
{ platform: 'android', regex: /Android(?:\s|\/)(\d+)/ }, | ||
// Kindle Fire | ||
var platforms = [// Windows Phone 7 - 10 | ||
{ | ||
platform: 'windowsPhone', | ||
regex: /Windows Phone (?:OS )?(\d+)[.\d]+/ | ||
}, // Android 4+ using Chrome | ||
{ | ||
platform: 'androidChrome', | ||
regex: /Android .* Chrome\/(\d+)[.\d]+/ | ||
}, // Android 2 - 4 | ||
{ | ||
platform: 'android', | ||
regex: /Android(?:\s|\/)(\d+)/ | ||
}, // Kindle Fire | ||
// Force version to 2, (desktop mode does not list android version) | ||
{ platform: 'android', regex: /Silk\/1./, forceVersion: 2, extra: { silk: 1 } }, | ||
// Kindle Fire HD (Silk versions 2 or 3) | ||
{ | ||
platform: 'android', | ||
regex: /Silk\/1./, | ||
forceVersion: 2, | ||
extra: { | ||
silk: 1 | ||
} | ||
}, // Kindle Fire HD (Silk versions 2 or 3) | ||
// Force version to 4 | ||
{ platform: 'android', regex: /Silk\/2./, forceVersion: 4, extra: { silk: 2 } }, { platform: 'android', regex: /Silk\/3./, forceVersion: 4, extra: { silk: 3 } }, | ||
// IE 8 - 10 | ||
{ platform: 'ie', regex: /MSIE (\d+)/ }, | ||
// IE 11 | ||
{ platform: 'ie', regex: /Trident\/.*; rv:(\d+)/ }, | ||
// Edge | ||
{ platform: 'edge', regex: /Edge\/(\d+)/ }, | ||
// iOS 3 - 5 | ||
{ | ||
platform: 'android', | ||
regex: /Silk\/2./, | ||
forceVersion: 4, | ||
extra: { | ||
silk: 2 | ||
} | ||
}, { | ||
platform: 'android', | ||
regex: /Silk\/3./, | ||
forceVersion: 4, | ||
extra: { | ||
silk: 3 | ||
} | ||
}, // IE 8 - 10 | ||
{ | ||
platform: 'ie', | ||
regex: /MSIE (\d+)/ | ||
}, // IE 11 | ||
{ | ||
platform: 'ie', | ||
regex: /Trident\/.*; rv:(\d+)/ | ||
}, // Edge | ||
{ | ||
platform: 'edge', | ||
regex: /Edge\/(\d+)/ | ||
}, // iOS 3 - 5 | ||
// Apple likes to make this complicated | ||
{ platform: 'ios', regex: /iP(?:hone|ad;(?: U;)? CPU) OS (\d+)/ }, | ||
// webOS 1 - 3 | ||
{ platform: 'webos', regex: /(?:web|hpw)OS\/(\d+)/ }, | ||
// webOS 4 / OpenWebOS | ||
{ platform: 'webos', regex: /WebAppManager|Isis|webOS\./, forceVersion: 4 }, | ||
// Open webOS release LuneOS | ||
{ platform: 'webos', regex: /LuneOS/, forceVersion: 4, extra: { luneos: 1 } }, | ||
// desktop Safari | ||
{ platform: 'safari', regex: /Version\/(\d+)[.\d]+\s+Safari/ }, | ||
// desktop Chrome | ||
{ platform: 'chrome', regex: /Chrome\/(\d+)[.\d]+/ }, | ||
// Firefox on Android | ||
{ platform: 'androidFirefox', regex: /Android;.*Firefox\/(\d+)/ }, | ||
// FirefoxOS | ||
{ platform: 'firefoxOS', regex: /Mobile;.*Firefox\/(\d+)/ }, | ||
// desktop Firefox | ||
{ platform: 'firefox', regex: /Firefox\/(\d+)/ }, | ||
// Blackberry Playbook | ||
{ platform: 'blackberry', regex: /PlayBook/i, forceVersion: 2 }, | ||
// Blackberry 10+ | ||
{ platform: 'blackberry', regex: /BB1\d;.*Version\/(\d+\.\d+)/ }, | ||
// Tizen | ||
{ platform: 'tizen', regex: /Tizen (\d+)/ }]; | ||
{ | ||
platform: 'ios', | ||
regex: /iP(?:hone|ad;(?: U;)? CPU) OS (\d+)/ | ||
}, // webOS 1 - 3 | ||
{ | ||
platform: 'webos', | ||
regex: /(?:web|hpw)OS\/(\d+)/ | ||
}, // webOS 4 / OpenWebOS | ||
{ | ||
platform: 'webos', | ||
regex: /WebAppManager|Isis|webOS\./, | ||
forceVersion: 4 | ||
}, // Open webOS release LuneOS | ||
{ | ||
platform: 'webos', | ||
regex: /LuneOS/, | ||
forceVersion: 4, | ||
extra: { | ||
luneos: 1 | ||
} | ||
}, // desktop Safari | ||
{ | ||
platform: 'safari', | ||
regex: /Version\/(\d+)[.\d]+\s+Safari/ | ||
}, // desktop Chrome | ||
{ | ||
platform: 'chrome', | ||
regex: /Chrome\/(\d+)[.\d]+/ | ||
}, // Firefox on Android | ||
{ | ||
platform: 'androidFirefox', | ||
regex: /Android;.*Firefox\/(\d+)/ | ||
}, // FirefoxOS | ||
{ | ||
platform: 'firefoxOS', | ||
regex: /Mobile;.*Firefox\/(\d+)/ | ||
}, // desktop Firefox | ||
{ | ||
platform: 'firefox', | ||
regex: /Firefox\/(\d+)/ | ||
}, // Blackberry Playbook | ||
{ | ||
platform: 'blackberry', | ||
regex: /PlayBook/i, | ||
forceVersion: 2 | ||
}, // Blackberry 10+ | ||
{ | ||
platform: 'blackberry', | ||
regex: /BB1\d;.*Version\/(\d+\.\d+)/ | ||
}, // Tizen | ||
{ | ||
platform: 'tizen', | ||
regex: /Tizen (\d+)/ | ||
}]; | ||
var ua = function ua() { | ||
return window.navigator ? window.navigator.userAgent : ''; | ||
return window.navigator ? window.navigator.userAgent : ''; | ||
}; | ||
var _platform = void 0; | ||
var _platform; | ||
/** | ||
@@ -94,46 +154,49 @@ * {@link core/platform.detect} returns the {@link core/platform.platform} object. | ||
var detect = function detect() { | ||
if (_platform) { | ||
// if we've already determined the platform, we'll use that determination | ||
return _platform; | ||
} else if (typeof window === 'undefined') { | ||
return { | ||
gesture: false, | ||
node: true, | ||
touch: false, | ||
unknown: true | ||
}; | ||
} | ||
if (_platform) { | ||
// if we've already determined the platform, we'll use that determination | ||
return _platform; | ||
} else if (typeof window === 'undefined') { | ||
return { | ||
gesture: false, | ||
node: true, | ||
touch: false, | ||
unknown: true | ||
}; | ||
} | ||
var userAgent = ua(); | ||
var userAgent = ua(); | ||
_platform = { | ||
gesture: hasGesture(), | ||
node: false, | ||
touch: hasTouch(), | ||
unknown: true | ||
}; | ||
_platform = { | ||
gesture: hasGesture(), | ||
node: false, | ||
touch: hasTouch(), | ||
unknown: true | ||
}; | ||
for (var i = 0, p, m, v; p = platforms[i]; i++) { | ||
m = p.regex.exec(userAgent); | ||
for (var i = 0, p, m, v; p = platforms[i]; i++) { | ||
m = p.regex.exec(userAgent); | ||
if (m) { | ||
_platform.unknown = false; | ||
if (m) { | ||
_platform.unknown = false; | ||
if (p.forceVersion) { | ||
v = p.forceVersion; | ||
} else { | ||
v = Number(m[1]); | ||
} | ||
_platform[p.platform] = v; | ||
if (p.extra) { | ||
_platform = _extends({}, _platform, p.extra); | ||
} | ||
_platform.platformName = p.platform; | ||
break; | ||
} | ||
} | ||
if (p.forceVersion) { | ||
v = p.forceVersion; | ||
} else { | ||
v = Number(m[1]); | ||
} | ||
return _platform; | ||
_platform[p.platform] = v; | ||
if (p.extra) { | ||
_platform = _objectSpread({}, _platform, p.extra); | ||
} | ||
_platform.platformName = p.platform; | ||
break; | ||
} | ||
} | ||
return _platform; | ||
}; | ||
/** | ||
@@ -154,17 +217,18 @@ * {@link core/platform.platform} provides basic information about the running platform. | ||
exports.detect = detect; | ||
var platform = {}; | ||
['gesture', 'node', 'platformName', 'touch', 'unknown'].concat(_toConsumableArray((0, _uniq2.default)(platforms.map(function (p) { | ||
return p.platform; | ||
exports.platform = platform; | ||
['gesture', 'node', 'platformName', 'touch', 'unknown'].concat(_toConsumableArray((0, _uniq.default)(platforms.map(function (p) { | ||
return p.platform; | ||
})))).forEach(function (name) { | ||
Object.defineProperty(platform, name, { | ||
enumerable: true, | ||
get: function get() { | ||
var p = detect(); | ||
return p[name]; | ||
} | ||
}); | ||
Object.defineProperty(platform, name, { | ||
enumerable: true, | ||
get: function get() { | ||
var p = detect(); | ||
return p[name]; | ||
} | ||
}); | ||
}); | ||
exports.default = platform; | ||
exports.detect = detect; | ||
exports.platform = platform; | ||
var _default = platform; | ||
exports.default = _default; |
443
util/Job.js
@@ -1,11 +0,14 @@ | ||
'use strict'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
value: true | ||
}); | ||
exports.Job = exports.default = void 0; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
/** | ||
@@ -15,261 +18,233 @@ * @class Job | ||
*/ | ||
var Job = function () { | ||
/** | ||
* @constructor | ||
* @memberof core/util.Job | ||
* @param {Function} fn function to execute as the requested job. | ||
* @param {Number} timeout The number of milliseconds to wait before starting the job. | ||
*/ | ||
function Job(fn, timeout) { | ||
_classCallCheck(this, Job); | ||
_initialiseProps.call(this); | ||
this.fn = fn; | ||
this.timeout = timeout; | ||
} | ||
_createClass(Job, [{ | ||
key: 'run', | ||
value: function run(args) { | ||
// don't want to inadvertently apply Job's context on `fn` | ||
this.fn.apply(null, args); | ||
} | ||
/** | ||
* Starts the job. | ||
* | ||
* @method | ||
var Job = | ||
/*#__PURE__*/ | ||
function () { | ||
/** | ||
* @constructor | ||
* @memberof core/util.Job | ||
* @param {...*} [args] Any args passed are forwarded to the callback | ||
* @returns {undefined} | ||
* @param {Function} fn function to execute as the requested job. | ||
* @param {Number} timeout The number of milliseconds to wait before starting the job. | ||
*/ | ||
function Job(fn, timeout) { | ||
_classCallCheck(this, Job); | ||
_initialiseProps.call(this); | ||
/** | ||
* Starts the job in `timeout` milliseconds | ||
* | ||
* @method | ||
* @memberof core/util.Job | ||
* @param {Number} timeout The number of milliseconds to wait before starting the job. | ||
* This supersedes the timeout set at construction or by | ||
* `setTimeout`. | ||
* @param {...*} [args] Any args passed are forwarded to the callback | ||
* @returns {undefined} | ||
*/ | ||
this.fn = fn; | ||
this.timeout = timeout; | ||
} | ||
_createClass(Job, [{ | ||
key: "run", | ||
value: function run(args) { | ||
// don't want to inadvertently apply Job's context on `fn` | ||
this.fn.apply(null, args); | ||
} | ||
/** | ||
* Starts the job. | ||
* | ||
* @method | ||
* @memberof core/util.Job | ||
* @param {...*} [args] Any args passed are forwarded to the callback | ||
* @returns {undefined} | ||
*/ | ||
/** | ||
* Stops the job. | ||
* | ||
* @method | ||
* @memberof core/util.Job | ||
* @returns {undefined} | ||
*/ | ||
}]); | ||
return Job; | ||
}(); | ||
/** | ||
* Executes the job immediately, then prevents any other calls to `throttle()` from running | ||
* until the `timeout` configured at construction or via `setTimeout` passes. | ||
* | ||
* @method | ||
* @memberof core/util.Job | ||
* @param {...*} args Any args passed are forwarded to the callback | ||
* @returns {undefined} | ||
* @public | ||
*/ | ||
exports.Job = Job; | ||
/** | ||
* Executes the job immediately, then prevents any other calls to `throttle()` from running for | ||
* `timeout` milliseconds. | ||
* | ||
* @method | ||
* @memberof core/util.Job | ||
* @param {Number} timeout The number of milliseconds to wait before allowing the job to | ||
* be ran again. This supersedes the timeout set at construction | ||
* or by `setTimeout`. | ||
* @param {...*} [args] Any args passed are forwarded to the callback | ||
* @returns {undefined} | ||
* @public | ||
*/ | ||
/** | ||
* Executes job when the CPU is idle. | ||
* | ||
* @method | ||
* @memberof core/util.Job | ||
* @param {...*} [args] Any args passed are forwarded to the callback | ||
* @returns {undefined} | ||
* @public | ||
*/ | ||
/** | ||
* Executes job when the CPU is idle, or when the timeout is reached, whichever occurs first. | ||
* | ||
* @method | ||
* @memberof core/util.Job | ||
* @param {Number} timeout The number of milliseconds to wait before executing the | ||
* job. This guarantees that the job is run, if a positive value | ||
* is specified. | ||
* @param {...*} [args] Any args passed are forwarded to the callback | ||
* @returns {undefined} | ||
* @public | ||
*/ | ||
/** | ||
* Executes job before the next repaint. | ||
* | ||
* @method | ||
* @memberof core/util.Job | ||
* @param {...*} [args] Any args passed are forwarded to the callback | ||
* @returns {undefined} | ||
* @public | ||
*/ | ||
/** | ||
* Executes job before the next repaint after a given amount of timeout. | ||
* | ||
* @method | ||
* @memberof core/util.Job | ||
* @param {Number} timeout The number of milliseconds to wait before running requestAnimationFrame. | ||
* @param {...*} [args] Any args passed are forwarded to the callback | ||
* @returns {undefined} | ||
* @public | ||
*/ | ||
}]); | ||
return Job; | ||
}(); | ||
var _initialiseProps = function _initialiseProps() { | ||
var _this = this; | ||
var _this = this; | ||
this.id = null; | ||
this.fn = null; | ||
this.timeout = null; | ||
this.type = null; | ||
Object.defineProperty(this, "id", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: null | ||
}); | ||
Object.defineProperty(this, "fn", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: null | ||
}); | ||
Object.defineProperty(this, "timeout", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: null | ||
}); | ||
Object.defineProperty(this, "type", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: null | ||
}); | ||
Object.defineProperty(this, "start", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: function value() { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
this.start = function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_this.startAfter.apply(_this, [_this.timeout].concat(args)); | ||
} | ||
}); | ||
Object.defineProperty(this, "startAfter", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: function value(timeout) { | ||
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
args[_key2 - 1] = arguments[_key2]; | ||
} | ||
_this.startAfter.apply(_this, [_this.timeout].concat(args)); | ||
}; | ||
_this.stop(); | ||
this.startAfter = function (timeout) { | ||
for (var _len2 = arguments.length, args = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
args[_key2 - 1] = arguments[_key2]; | ||
} | ||
_this.type = 'timeout'; | ||
_this.id = setTimeout(function () { | ||
return _this.run(args); | ||
}, timeout); | ||
} | ||
}); | ||
Object.defineProperty(this, "stop", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: function value() { | ||
if (_this.id) { | ||
if (_this.type === 'idle') { | ||
window.cancelIdleCallback(_this.id); | ||
} else if (_this.type === 'raf') { | ||
window.cancelAnimationFrame(_this.id); | ||
} else { | ||
clearTimeout(_this.id); | ||
} | ||
_this.stop(); | ||
_this.type = 'timeout'; | ||
_this.id = setTimeout(function () { | ||
return _this.run(args); | ||
}, timeout); | ||
}; | ||
_this.id = null; | ||
} | ||
} | ||
}); | ||
Object.defineProperty(this, "throttle", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: function value() { | ||
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { | ||
args[_key3] = arguments[_key3]; | ||
} | ||
this.stop = function () { | ||
if (_this.id) { | ||
if (_this.type === 'idle') { | ||
window.cancelIdleCallback(_this.id); | ||
} else if (_this.type === 'raf') { | ||
window.cancelAnimationFrame(_this.id); | ||
} else { | ||
clearTimeout(_this.id); | ||
} | ||
_this.id = null; | ||
} | ||
}; | ||
_this.throttleUntil.apply(_this, [_this.timeout].concat(args)); | ||
} | ||
}); | ||
Object.defineProperty(this, "throttleUntil", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: function value(timeout) { | ||
if (!_this.id) { | ||
for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) { | ||
args[_key4 - 1] = arguments[_key4]; | ||
} | ||
this.throttle = function () { | ||
for (var _len3 = arguments.length, args = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { | ||
args[_key3] = arguments[_key3]; | ||
} | ||
_this.run(args); | ||
_this.throttleUntil.apply(_this, [_this.timeout].concat(args)); | ||
}; | ||
_this.id = setTimeout(_this.stop, timeout); | ||
} | ||
} | ||
}); | ||
Object.defineProperty(this, "idle", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: function value() { | ||
for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) { | ||
args[_key5] = arguments[_key5]; | ||
} | ||
this.throttleUntil = function (timeout) { | ||
for (var _len4 = arguments.length, args = Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) { | ||
args[_key4 - 1] = arguments[_key4]; | ||
} | ||
_this.idleUntil.apply(_this, [null].concat(args)); | ||
} | ||
}); | ||
Object.defineProperty(this, "idleUntil", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: function value(timeout) { | ||
for (var _len6 = arguments.length, args = new Array(_len6 > 1 ? _len6 - 1 : 0), _key6 = 1; _key6 < _len6; _key6++) { | ||
args[_key6 - 1] = arguments[_key6]; | ||
} | ||
if (!_this.id) { | ||
_this.run(args); | ||
_this.id = setTimeout(_this.stop, timeout); | ||
} | ||
}; | ||
if (typeof window !== 'undefined') { | ||
if (window.requestIdleCallback) { | ||
_this.type = 'idle'; | ||
_this.id = window.requestIdleCallback(function () { | ||
return _this.run(args); | ||
}, { | ||
timeout: timeout | ||
}); | ||
} else { | ||
// If requestIdleCallback is not supported just run the function immediately | ||
_this.fn.apply(_this, args); | ||
} | ||
} | ||
} | ||
}); | ||
Object.defineProperty(this, "startRaf", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: function value() { | ||
for (var _len7 = arguments.length, args = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) { | ||
args[_key7] = arguments[_key7]; | ||
} | ||
this.idle = function () { | ||
for (var _len5 = arguments.length, args = Array(_len5), _key5 = 0; _key5 < _len5; _key5++) { | ||
args[_key5] = arguments[_key5]; | ||
} | ||
_this.startRafAfter.apply(_this, [_this.timeout].concat(args)); | ||
} | ||
}); | ||
Object.defineProperty(this, "startRafAfter", { | ||
configurable: true, | ||
enumerable: true, | ||
writable: true, | ||
value: function value(timeout) { | ||
for (var _len8 = arguments.length, args = new Array(_len8 > 1 ? _len8 - 1 : 0), _key8 = 1; _key8 < _len8; _key8++) { | ||
args[_key8 - 1] = arguments[_key8]; | ||
} | ||
_this.idleUntil.apply(_this, [null].concat(args)); | ||
}; | ||
_this.type = 'raf'; | ||
this.idleUntil = function (timeout) { | ||
for (var _len6 = arguments.length, args = Array(_len6 > 1 ? _len6 - 1 : 0), _key6 = 1; _key6 < _len6; _key6++) { | ||
args[_key6 - 1] = arguments[_key6]; | ||
} | ||
if (typeof window !== 'undefined') { | ||
var time = null; | ||
if (typeof window !== 'undefined') { | ||
if (window.requestIdleCallback) { | ||
_this.type = 'idle'; | ||
_this.id = window.requestIdleCallback(function () { | ||
return _this.run(args); | ||
}, { timeout: timeout }); | ||
} else { | ||
// If requestIdleCallback is not supported just run the function immediately | ||
_this.fn.apply(_this, args); | ||
} | ||
} | ||
}; | ||
var callback = function callback(timestamp) { | ||
if (time === null) { | ||
time = timestamp; | ||
} | ||
this.startRaf = function () { | ||
for (var _len7 = arguments.length, args = Array(_len7), _key7 = 0; _key7 < _len7; _key7++) { | ||
args[_key7] = arguments[_key7]; | ||
} | ||
if (timeout && timestamp - time < timeout) { | ||
_this.id = window.requestAnimationFrame(callback); | ||
} else { | ||
time = null; | ||
_this.startRafAfter.apply(_this, [_this.timeout].concat(args)); | ||
}; | ||
_this.run(args); | ||
this.startRafAfter = function (timeout) { | ||
for (var _len8 = arguments.length, args = Array(_len8 > 1 ? _len8 - 1 : 0), _key8 = 1; _key8 < _len8; _key8++) { | ||
args[_key8 - 1] = arguments[_key8]; | ||
} | ||
window.cancelAnimationFrame(_this.id); | ||
_this.id = null; | ||
} | ||
}; | ||
_this.type = 'raf'; | ||
if (typeof window !== 'undefined') { | ||
var time = null; | ||
var callback = function callback(timestamp) { | ||
if (time === null) { | ||
time = timestamp; | ||
} | ||
if (timeout && timestamp - time < timeout) { | ||
_this.id = window.requestAnimationFrame(callback); | ||
} else { | ||
time = null; | ||
_this.run(args); | ||
window.cancelAnimationFrame(_this.id); | ||
_this.id = null; | ||
} | ||
}; | ||
_this.id = window.requestAnimationFrame(callback); | ||
} else { | ||
// If requestAnimationFrame is not supported just run the function immediately | ||
_this.fn.apply(_this, args); | ||
} | ||
}; | ||
_this.id = window.requestAnimationFrame(callback); | ||
} else { | ||
// If requestAnimationFrame is not supported just run the function immediately | ||
_this.fn.apply(_this, args); | ||
} | ||
} | ||
}); | ||
}; | ||
exports.default = Job; | ||
exports.Job = Job; | ||
var _default = Job; | ||
exports.default = _default; |
@@ -1,109 +0,101 @@ | ||
'use strict'; | ||
"use strict"; | ||
var _Job = require('../Job'); | ||
var _Job = _interopRequireDefault(require("../Job")); | ||
var _Job2 = _interopRequireDefault(_Job); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
describe('Job', function () { | ||
describe('#start', function () { | ||
it('should start job', function (done) { | ||
var j = new _Job2.default(done, 10); | ||
j.start(); | ||
}); | ||
describe('#start', function () { | ||
it('should start job', function (done) { | ||
var j = new _Job.default(done, 10); | ||
j.start(); | ||
}); | ||
it('should pass args to fn', function (done) { | ||
var value = 'argument'; | ||
it('should pass args to fn', function (done) { | ||
var value = 'argument'; | ||
var fn = function fn(arg) { | ||
if (arg === value) { | ||
done(); | ||
} else { | ||
done(new Error('fn did not receive argument')); | ||
} | ||
}; | ||
var fn = function fn(arg) { | ||
if (arg === value) { | ||
done(); | ||
} else { | ||
done(new Error('fn did not receive argument')); | ||
} | ||
}; | ||
var j = new _Job2.default(fn, 10); | ||
j.start(value); | ||
}); | ||
}); | ||
var j = new _Job.default(fn, 10); | ||
j.start(value); | ||
}); | ||
}); | ||
describe('#stop', function () { | ||
it('should stop job', function (done) { | ||
var ran = false; | ||
var j = new _Job.default(function () { | ||
ran = true; | ||
done(new Error('job wasn\'t stopped')); | ||
}, 10); | ||
j.start(); | ||
j.stop(); | ||
window.setTimeout(function () { | ||
if (!ran) done(); | ||
}, 30); | ||
}); | ||
}); | ||
describe('#throttle', function () { | ||
it('should throttle job', function (done) { | ||
var number = 0; | ||
var j = new _Job.default(function () { | ||
number++; | ||
}, 20); | ||
j.throttle(); | ||
window.setTimeout(function () { | ||
j.throttle(); | ||
}, 5); | ||
window.setTimeout(function () { | ||
j.throttle(); | ||
}, 15); | ||
window.setTimeout(function () { | ||
j.throttle(); | ||
}, 25); | ||
window.setTimeout(function () { | ||
if (number === 2) { | ||
done(); | ||
} else { | ||
done(new Error('too many or too few calls' + number)); | ||
} | ||
}, 30); | ||
}); | ||
it('should pass args to fn', function (done) { | ||
var value = 'argument'; | ||
describe('#stop', function () { | ||
it('should stop job', function (done) { | ||
var ran = false; | ||
var j = new _Job2.default(function () { | ||
ran = true; | ||
done(new Error('job wasn\'t stopped')); | ||
}, 10); | ||
var fn = function fn(arg) { | ||
if (arg === value) { | ||
done(); | ||
} else { | ||
done(new Error('fn did not receive argument')); | ||
} | ||
}; | ||
j.start(); | ||
j.stop(); | ||
var j = new _Job.default(fn, 10); | ||
j.throttle(value); | ||
}); | ||
}); | ||
describe('#idle', function () { | ||
it('should start job', function (done) { | ||
var j = new _Job.default(done, 10); | ||
j.idle(); | ||
}); | ||
it('should pass args to fn', function (done) { | ||
var value = 'argument'; | ||
window.setTimeout(function () { | ||
if (!ran) done(); | ||
}, 30); | ||
}); | ||
}); | ||
var fn = function fn(arg) { | ||
if (arg === value) { | ||
done(); | ||
} else { | ||
done(new Error('fn did not receive argument')); | ||
} | ||
}; | ||
describe('#throttle', function () { | ||
it('should throttle job', function (done) { | ||
var number = 0; | ||
var j = new _Job2.default(function () { | ||
number++; | ||
}, 20); | ||
j.throttle(); | ||
window.setTimeout(function () { | ||
j.throttle(); | ||
}, 5); | ||
window.setTimeout(function () { | ||
j.throttle(); | ||
}, 15); | ||
window.setTimeout(function () { | ||
j.throttle(); | ||
}, 25); | ||
window.setTimeout(function () { | ||
if (number === 2) { | ||
done(); | ||
} else { | ||
done(new Error('too many or too few calls' + number)); | ||
} | ||
}, 30); | ||
}); | ||
it('should pass args to fn', function (done) { | ||
var value = 'argument'; | ||
var fn = function fn(arg) { | ||
if (arg === value) { | ||
done(); | ||
} else { | ||
done(new Error('fn did not receive argument')); | ||
} | ||
}; | ||
var j = new _Job2.default(fn, 10); | ||
j.throttle(value); | ||
}); | ||
}); | ||
describe('#idle', function () { | ||
it('should start job', function (done) { | ||
var j = new _Job2.default(done, 10); | ||
j.idle(); | ||
}); | ||
it('should pass args to fn', function (done) { | ||
var value = 'argument'; | ||
var fn = function fn(arg) { | ||
if (arg === value) { | ||
done(); | ||
} else { | ||
done(new Error('fn did not receive argument')); | ||
} | ||
}; | ||
var j = new _Job2.default(fn, 10); | ||
j.idle(value); | ||
}); | ||
}); | ||
var j = new _Job.default(fn, 10); | ||
j.idle(value); | ||
}); | ||
}); | ||
}); |
126
util/util.js
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,68 +6,44 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
exports.perfNow = exports.extractAriaProps = exports.isRenderable = exports.Job = exports.coerceArray = exports.coerceFunction = exports.childrenEquals = exports.cap = undefined; | ||
Object.defineProperty(exports, "Job", { | ||
enumerable: true, | ||
get: function get() { | ||
return _Job.default; | ||
} | ||
}); | ||
exports.perfNow = exports.extractAriaProps = exports.isRenderable = exports.coerceArray = exports.coerceFunction = exports.childrenEquals = exports.cap = void 0; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; /** | ||
* A collection of utility methods. | ||
* | ||
* @module core/util | ||
*/ | ||
var _always = _interopRequireDefault(require("ramda/src/always")); | ||
var _compose = _interopRequireDefault(require("ramda/src/compose")); | ||
var _always = require('ramda/src/always'); | ||
var _equals = _interopRequireDefault(require("ramda/src/equals")); | ||
var _always2 = _interopRequireDefault(_always); | ||
var _is = _interopRequireDefault(require("ramda/src/is")); | ||
var _compose = require('ramda/src/compose'); | ||
var _map = _interopRequireDefault(require("ramda/src/map")); | ||
var _compose2 = _interopRequireDefault(_compose); | ||
var _prop = _interopRequireDefault(require("ramda/src/prop")); | ||
var _equals = require('ramda/src/equals'); | ||
var _react = _interopRequireDefault(require("react")); | ||
var _equals2 = _interopRequireDefault(_equals); | ||
var _sort = _interopRequireDefault(require("ramda/src/sort")); | ||
var _is = require('ramda/src/is'); | ||
var _unless = _interopRequireDefault(require("ramda/src/unless")); | ||
var _is2 = _interopRequireDefault(_is); | ||
var _useWith = _interopRequireDefault(require("ramda/src/useWith")); | ||
var _map = require('ramda/src/map'); | ||
var _when = _interopRequireDefault(require("ramda/src/when")); | ||
var _map2 = _interopRequireDefault(_map); | ||
var _Job = _interopRequireDefault(require("./Job")); | ||
var _prop = require('ramda/src/prop'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _prop2 = _interopRequireDefault(_prop); | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
var _react = require('react'); | ||
var _react2 = _interopRequireDefault(_react); | ||
var _sort = require('ramda/src/sort'); | ||
var _sort2 = _interopRequireDefault(_sort); | ||
var _unless = require('ramda/src/unless'); | ||
var _unless2 = _interopRequireDefault(_unless); | ||
var _useWith = require('ramda/src/useWith'); | ||
var _useWith2 = _interopRequireDefault(_useWith); | ||
var _when = require('ramda/src/when'); | ||
var _when2 = _interopRequireDefault(_when); | ||
var _Job = require('./Job'); | ||
var _Job2 = _interopRequireDefault(_Job); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var orderedKeys = (0, _map2.default)((0, _when2.default)(_react2.default.isValidElement, (0, _prop2.default)('key'))); | ||
var unorderedKeys = (0, _compose2.default)((0, _sort2.default)(function (a, b) { | ||
var orderedKeys = (0, _map.default)((0, _when.default)(_react.default.isValidElement, (0, _prop.default)('key'))); | ||
var unorderedKeys = (0, _compose.default)((0, _sort.default)(function (a, b) { | ||
return a - b; | ||
}), orderedKeys); | ||
var unorderedEquals = (0, _useWith2.default)(_equals2.default, [unorderedKeys, unorderedKeys]); | ||
var orderedEquals = (0, _useWith2.default)(_equals2.default, [orderedKeys, orderedKeys]); | ||
var unorderedEquals = (0, _useWith.default)(_equals.default, [unorderedKeys, unorderedKeys]); | ||
var orderedEquals = (0, _useWith.default)(_equals.default, [orderedKeys, orderedKeys]); | ||
/** | ||
@@ -84,8 +60,10 @@ * Compares the keys of two sets of children and returns `true` if they are equal. | ||
*/ | ||
var childrenEquals = function childrenEquals(prev, next) { | ||
var ordered = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; | ||
var prevChildren = _react2.default.Children.toArray(prev); | ||
var nextChildren = _react2.default.Children.toArray(next); | ||
var prevChildren = _react.default.Children.toArray(prev); | ||
var nextChildren = _react.default.Children.toArray(next); | ||
if (prevChildren.length !== nextChildren.length) { | ||
@@ -96,4 +74,3 @@ return false; | ||
var c2 = nextChildren[0]; | ||
return (0, _equals2.default)(c1, c2); | ||
return (0, _equals.default)(c1, c2); | ||
} else if (ordered) { | ||
@@ -105,3 +82,2 @@ return orderedEquals(prevChildren, nextChildren); | ||
}; | ||
/** | ||
@@ -116,6 +92,9 @@ * Capitalizes a given string (not locale aware). | ||
*/ | ||
exports.childrenEquals = childrenEquals; | ||
var cap = function cap(str) { | ||
return str.slice(0, 1).toUpperCase() + str.slice(1); | ||
}; | ||
/** | ||
@@ -133,4 +112,6 @@ * If `arg` is a function, return it. Otherwise returns a function that returns `arg` | ||
*/ | ||
var coerceFunction = (0, _unless2.default)((0, _is2.default)(Function), _always2.default); | ||
exports.cap = cap; | ||
var coerceFunction = (0, _unless.default)((0, _is.default)(Function), _always.default); | ||
/** | ||
@@ -151,6 +132,8 @@ * If `arg` is array-like, return it. Otherwise returns a single element array containing `arg` | ||
*/ | ||
exports.coerceFunction = coerceFunction; | ||
var coerceArray = function coerceArray(array) { | ||
return Array.isArray(array) ? array : [array]; | ||
}; | ||
/** | ||
@@ -164,7 +147,11 @@ * Loosely determines if `tag` is a renderable component (either a string or a function) | ||
*/ | ||
exports.coerceArray = coerceArray; | ||
var isRenderable = function isRenderable(tag) { | ||
var type = typeof tag === 'undefined' ? 'undefined' : _typeof(tag); | ||
var type = _typeof(tag); | ||
return type === 'function' || type === 'string'; | ||
}; | ||
/** | ||
@@ -180,2 +167,6 @@ * Removes `aria-` prefixed props and the `role` prop from `props` and returns them in a new object. | ||
*/ | ||
exports.isRenderable = isRenderable; | ||
var extractAriaProps = function extractAriaProps(props) { | ||
@@ -189,6 +180,4 @@ var aria = {}; | ||
}); | ||
return aria; | ||
}; | ||
/** | ||
@@ -201,4 +190,8 @@ * Gets current timestamp of either `window.performance.now` or `Date.now` | ||
*/ | ||
exports.extractAriaProps = extractAriaProps; | ||
var perfNow = function perfNow() { | ||
if ((typeof window === 'undefined' ? 'undefined' : _typeof(window)) === 'object') { | ||
if ((typeof window === "undefined" ? "undefined" : _typeof(window)) === 'object') { | ||
return window.performance.now(); | ||
@@ -210,9 +203,2 @@ } else { | ||
exports.cap = cap; | ||
exports.childrenEquals = childrenEquals; | ||
exports.coerceFunction = coerceFunction; | ||
exports.coerceArray = coerceArray; | ||
exports.Job = _Job2.default; | ||
exports.isRenderable = isRenderable; | ||
exports.extractAriaProps = extractAriaProps; | ||
exports.perfNow = perfNow; |
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
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
144218
3793
57
+ Addedclassnames@2.5.1(transitive)
+ Addedprop-types@15.8.1(transitive)
+ Addedreact@15.7.0(transitive)
+ Addedreact-dom@15.7.0(transitive)
+ Addedreact-is@16.13.1(transitive)
- Removedclassnames@2.2.6(transitive)
- Removedprop-types@15.6.2(transitive)
- Removedreact@15.6.2(transitive)
- Removedreact-dom@15.6.2(transitive)
Updatedclassnames@^2.2.6
Updatedinvariant@^2.2.4
Updatedprop-types@^15.6.2
Updatedramda@^0.24.1
Updatedreact@^15.6.2
Updatedreact-dom@^15.6.2