@enact/core
Advanced tools
Comparing version 1.0.0-alpha.5 to 1.0.0-beta.1
@@ -10,12 +10,24 @@ 'use strict'; | ||
/** | ||
* Accelerator provides logic for accelerating and throttling. | ||
* | ||
* Returns a generator function. | ||
* | ||
* @module core/Accelerator | ||
* @public | ||
*/ | ||
var Accelerator = function Accelerator(frequency) { | ||
* Provides the {@link core/Accelerator.Accelerator} class. | ||
* | ||
* @module core/Accelerator | ||
*/ | ||
/** | ||
* @class Accelerator | ||
* @memberof core/Accelerator | ||
*/ | ||
var Accelerator = | ||
/** | ||
* @constructor | ||
* @param {Number[]} frequency - Controls the frequency with which the acceleration will | ||
* "freeze". While frozen, the current target item cannot change, and all events are directed | ||
* to it. | ||
* @memberof core/Accelerator.Accelerator | ||
*/ | ||
function Accelerator() { | ||
var _this = this; | ||
var frequency = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [3, 3, 3, 2, 2, 2, 1]; | ||
_classCallCheck(this, Accelerator); | ||
@@ -82,86 +94,90 @@ | ||
/** | ||
* Whether the instance is currently in an accelerating state. | ||
* | ||
* @type {Boolean} | ||
* @default false | ||
*/ | ||
/* | ||
* Whether the instance is currently in an accelerating state. | ||
* | ||
* @type {Boolean} | ||
* @default false | ||
*/ | ||
this.accelerating = false; | ||
/** | ||
* The current count of skipped events. | ||
* | ||
* @type {Integer} | ||
* @default 0 | ||
*/ | ||
/* | ||
* The current count of skipped events. | ||
* | ||
* @type {Number} | ||
* @default 0 | ||
*/ | ||
this.skipped = 0; | ||
/** | ||
* The timestamp of the last evaluated event. | ||
* | ||
* @type {Integer} | ||
* @default 0 | ||
*/ | ||
/* | ||
* The timestamp of the last evaluated event. | ||
* | ||
* @type {Number} | ||
* @default 0 | ||
*/ | ||
this.time = 0; | ||
/** | ||
* The keyCode of the last evaluated event. | ||
* | ||
* @type {Integer} | ||
* @default 0 | ||
*/ | ||
/* | ||
* The keyCode of the last evaluated event. | ||
* | ||
* @type {Number} | ||
* @default 0 | ||
*/ | ||
this.keyCode = 0; | ||
/** | ||
* Whether the instance is in a state of being canceled. | ||
* | ||
* @type {Boolean} | ||
* @default false | ||
*/ | ||
/* | ||
* Whether the instance is in a state of being canceled. | ||
* | ||
* @type {Boolean} | ||
* @default false | ||
*/ | ||
this.canceled = false; | ||
/** | ||
* Controls the frequency with which the acceleration will "freeze". While frozen, | ||
* the current target item cannot change, and all events are directed to it. | ||
/* | ||
* Controls the frequency with which the acceleration will "freeze". While frozen, | ||
* the current target item cannot change, and all events are directed to it. | ||
* | ||
* @type {Array} | ||
* @default [3, 3, 3, 2, 2, 2, 1] | ||
* @public | ||
*/ | ||
this.frequency = frequency; | ||
} | ||
/** | ||
* Called with the current keydown event and callback, which will be called when the event is | ||
* allowed through. | ||
* | ||
* @type {Array} | ||
* @default [3, 3, 3, 2, 2, 2, 1] | ||
* @param {Object} event - The current event to validate. | ||
* @param {Function} callback - The callback to execute. | ||
* @returns {Boolean} `true` if the event was consumed by processKey and callback was not called | ||
* @public | ||
* @memberof core/Accelerator.Accelerator | ||
*/ | ||
this.frequency = frequency || [3, 3, 3, 2, 2, 2, 1]; | ||
} | ||
/** | ||
* Called with the current keydown event and callback, which will be called when the event is | ||
* allowed through. | ||
* | ||
* @param {Object} event - The current event to validate. | ||
* @param {Function} callback - The callback to execute. | ||
* @returns {Boolean} `true` if the event was consumed by processKey and callback was not called | ||
* @public | ||
*/ | ||
/** | ||
* Resets the Accelerator instance to the default values. | ||
* | ||
* @returns {undefined} | ||
* @public | ||
*/ | ||
* Resets the Accelerator instance to the default values. | ||
* | ||
* @returns {undefined} | ||
* @public | ||
* @memberof core/Accelerator.Accelerator | ||
*/ | ||
/** | ||
* Cancels the Accelerator. | ||
* | ||
* @returns {undefined} | ||
* @public | ||
*/ | ||
* Cancels the Accelerator. | ||
* | ||
* @returns {undefined} | ||
* @public | ||
* @memberof core/Accelerator.Accelerator | ||
*/ | ||
/** | ||
* Verifies that the Accelerator is active. | ||
* | ||
* @returns {Boolean} `true` if the Accelerator is active; otherwise, `false`. | ||
* @public | ||
*/ | ||
* Verifies that the Accelerator is active. | ||
* | ||
* @returns {Boolean} `true` if the Accelerator is active; otherwise, `false`. | ||
* @public | ||
* @memberof core/Accelerator.Accelerator | ||
*/ | ||
; | ||
@@ -168,0 +184,0 @@ |
@@ -5,2 +5,8 @@ # Change Log | ||
## [1.0.0-beta.1] - 2016-12-30 | ||
### Added | ||
- `core/factory` which provides the means to support design-time customization of components | ||
## [1.0.0-alpha.5] - 2016-12-16 | ||
@@ -7,0 +13,0 @@ |
@@ -8,5 +8,5 @@ 'use strict'; | ||
var _ramda = require('ramda'); | ||
var _curry = require('ramda/src/curry'); | ||
var _ramda2 = _interopRequireDefault(_ramda); | ||
var _curry2 = _interopRequireDefault(_curry); | ||
@@ -47,3 +47,3 @@ var _listeners = require('./listeners'); | ||
*/ | ||
var invoker = _ramda2.default.curry(function (ev, fn) { | ||
var invoker = (0, _curry2.default)(function (ev, fn) { | ||
try { | ||
@@ -50,0 +50,0 @@ fn(ev); |
@@ -8,6 +8,10 @@ 'use strict'; | ||
var _ramda = require('ramda'); | ||
var _curry = require('ramda/src/curry'); | ||
var _ramda2 = _interopRequireDefault(_ramda); | ||
var _curry2 = _interopRequireDefault(_curry); | ||
var _reduce = require('ramda/src/reduce'); | ||
var _reduce2 = _interopRequireDefault(_reduce); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -31,9 +35,13 @@ | ||
*/ | ||
var handle = _ramda2.default.unapply(function (handlers) { | ||
var handle = function handle() { | ||
for (var _len = arguments.length, handlers = Array(_len), _key = 0; _key < _len; _key++) { | ||
handlers[_key] = arguments[_key]; | ||
} | ||
return function () { | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
return _ramda2.default.reduce(function (acc, handler) { | ||
return (0, _reduce2.default)(function (acc, handler) { | ||
if (acc) { | ||
@@ -52,3 +60,3 @@ // if a prior handler returned true, do not call any more handlers | ||
}; | ||
}); | ||
}; | ||
@@ -84,4 +92,4 @@ /** | ||
return function () { | ||
for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
for (var _len3 = arguments.length, args = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { | ||
args[_key3] = arguments[_key3]; | ||
} | ||
@@ -131,3 +139,3 @@ | ||
*/ | ||
var forProp = handle.forProp = _ramda2.default.curry(function (prop, value) { | ||
var forProp = handle.forProp = (0, _curry2.default)(function (prop, value) { | ||
return function (e) { | ||
@@ -134,0 +142,0 @@ return e[prop] !== value; |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,10 +6,2 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
exports.computedChain = exports.computed = undefined; | ||
var _ramda = require('ramda'); | ||
var _ramda2 = _interopRequireDefault(_ramda); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/** | ||
@@ -61,33 +53,3 @@ * Accepts an object of computed property configurations and a property object, passes the property | ||
// Reducer to chain computed property transformations | ||
var reduceComputed = _ramda2.default.reduce(function (acc, v) { | ||
return _ramda2.default.assoc(v[0], v[1](acc), acc); | ||
}); | ||
/** | ||
* Alternate implementation that passes the altered props to each computed handler so computed props | ||
* can be built on other computed props. | ||
* | ||
* ``` | ||
* const cfg = { | ||
* sum: ({x,y,z}) => x+y+z, | ||
* doubleSum: ({sum}) => sum * 2 | ||
* } | ||
* const props = { | ||
* x: 2, | ||
* y: 3, | ||
* z: 4 | ||
* } | ||
* computed(cfg)(props) // => {x: 2, y: 3, z: 4, sum: 9, doubleSum: 18} | ||
* ``` | ||
* | ||
* @method computedChain | ||
* @param {Object} cfg Configuration object mapping transformation functions to property names | ||
* @returns {Function} Function accepting props and returning update props with computed properties | ||
* @public | ||
*/ | ||
var computedChain = _ramda2.default.useWith(_ramda2.default.flip(reduceComputed), [_ramda2.default.toPairs, _ramda2.default.identity]); | ||
exports.default = computed; | ||
exports.computed = computed; | ||
exports.computedChain = computedChain; | ||
exports.computed = computed; |
@@ -8,6 +8,14 @@ 'use strict'; | ||
var _ramda = require('ramda'); | ||
var _curry = require('ramda/src/curry'); | ||
var _ramda2 = _interopRequireDefault(_ramda); | ||
var _curry2 = _interopRequireDefault(_curry); | ||
var _compose = require('ramda/src/compose'); | ||
var _compose2 = _interopRequireDefault(_compose); | ||
var _merge = require('ramda/src/merge'); | ||
var _merge2 = _interopRequireDefault(_merge); | ||
var _classnames = require('classnames'); | ||
@@ -22,3 +30,3 @@ | ||
// Joins two strings in a className-friendly way | ||
var joinClasses = _ramda2.default.curryN(2, function (a, b) { | ||
var joinClasses = (0, _curry2.default)(function (a, b) { | ||
return a + ' ' + b; | ||
@@ -29,9 +37,13 @@ }); | ||
// is falsey, returns the truthy one or the first if both are falsey. | ||
var bothOrEither = function bothOrEither(fn) { | ||
return _ramda2.default.ifElse(_ramda2.default.and, fn, _ramda2.default.or); | ||
}; | ||
var bothOrEither = (0, _curry2.default)(function (fn, a, b) { | ||
if (a && b) { | ||
return fn(a, b); | ||
} else { | ||
return b || a; | ||
} | ||
}); | ||
// Returns either the value for the property or the property name itself | ||
var propOrSelf = _ramda2.default.curryN(2, function (b, a) { | ||
return _ramda2.default.propOr(a, a, b); | ||
var propOrSelf = (0, _curry2.default)(function (obj, prop) { | ||
return obj && obj[prop] || prop; | ||
}); | ||
@@ -41,16 +53,32 @@ | ||
// the class names to their css-modules name | ||
var resolveClassNames = _ramda2.default.useWith(_ramda2.default.compose(_ramda2.default.join(' '), _ramda2.default.map), [propOrSelf, _ramda2.default.split(' ')]); | ||
var resolveClassNames = (0, _curry2.default)(function (css, className) { | ||
if (css && className) { | ||
return className.split(' ').map(propOrSelf(css)).join(' '); | ||
} | ||
// If css and className are truthy, resolve the className. Otherwise, return className defaulted to '' | ||
var resolveOrSelf = _ramda2.default.ifElse(_ramda2.default.and, resolveClassNames, _ramda2.default.flip(_ramda2.default.defaultTo(''))); | ||
return className; | ||
}); | ||
// Takes a styles config object and either resolves `className` with `css` or `className` iself | ||
var localClassName = _ramda2.default.compose(_ramda2.default.apply(resolveOrSelf), _ramda2.default.props(['css', 'className'])); | ||
var localClassName = function localClassName(_ref) { | ||
var css = _ref.css, | ||
className = _ref.className; | ||
return resolveClassNames(css, className) || ''; | ||
}; | ||
// Merges the locally-resolved className and the className from the props | ||
var mergeClassName = _ramda2.default.useWith(bothOrEither(joinClasses), [localClassName, _ramda2.default.prop('className')]); | ||
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 | ||
var mergeStyle = _ramda2.default.useWith(bothOrEither(_ramda2.default.merge), [_ramda2.default.prop('style'), _ramda2.default.prop('style')]); | ||
var mergeStyle = function mergeStyle(_ref3, _ref4) { | ||
var componentStyle = _ref3.style; | ||
var authorStyle = _ref4.style; | ||
return bothOrEither(_merge2.default, componentStyle, authorStyle); | ||
}; | ||
/** | ||
@@ -66,3 +94,3 @@ * Creates the `join()` method of the styler | ||
if (cfg.css) { | ||
return _ramda2.default.compose(resolveClassNames(cfg.css), _classnames2.default); | ||
return (0, _compose2.default)(resolveClassNames(cfg.css), _classnames2.default); | ||
} | ||
@@ -76,9 +104,9 @@ | ||
* | ||
* @method append | ||
* @param {Object} props Render props updated by styles with `className` and `styler.join` | ||
* @returns {Function} `append()` | ||
* @method append | ||
*/ | ||
var append = function append(props) { | ||
var j = props.styler.join; | ||
return props.className ? _ramda2.default.compose(joinClasses(props.className), j) : j; | ||
return props.className ? (0, _compose2.default)(joinClasses(props.className), j) : j; | ||
}; | ||
@@ -121,5 +149,12 @@ | ||
props.style = mergeStyle(cfg, props); | ||
props[prop] = mergeClassName(cfg, props); | ||
var style = mergeStyle(cfg, props); | ||
if (style) { | ||
props.style = style; | ||
} | ||
var className = mergeClassName(cfg, props); | ||
if (className) { | ||
props[prop] = className; | ||
} | ||
// styler should not be automatically spread onto children | ||
@@ -126,0 +161,0 @@ (0, _util.addInternalProp)(props, 'styler', { |
@@ -108,70 +108,2 @@ 'use strict'; | ||
}); | ||
}); /* globals describe, it, expect */ | ||
describe('computedChain', function () { | ||
it('Should chain the results of each computed prop to the next', function () { | ||
var cfg = { | ||
sum: function sum(_ref5) { | ||
var x = _ref5.x, | ||
y = _ref5.y, | ||
z = _ref5.z; | ||
return x + y + z; | ||
}, | ||
product: function product(_ref6) { | ||
var sum = _ref6.sum, | ||
x = _ref6.x; | ||
return sum * x; | ||
}, | ||
result: function result(_ref7) { | ||
var product = _ref7.product, | ||
label = _ref7.label; | ||
return label + ': ' + product; | ||
} | ||
}; | ||
var props = { | ||
x: 2, | ||
y: 3, | ||
z: 4, | ||
label: 'Product' | ||
}; | ||
var updated = (0, _computed.computedChain)(cfg, props); | ||
var expected = 'Product: 18'; | ||
var actual = updated.result; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('Should execute in the order defined by the cfg', function () { | ||
var cfg = { | ||
// should be NaN since sum won't have been defined yet | ||
product: function product(_ref8) { | ||
var sum = _ref8.sum, | ||
x = _ref8.x; | ||
return sum * x; | ||
}, | ||
sum: function sum(_ref9) { | ||
var x = _ref9.x, | ||
y = _ref9.y, | ||
z = _ref9.z; | ||
return x + y + z; | ||
} | ||
}; | ||
var props = { | ||
x: 2, | ||
y: 3, | ||
z: 4 | ||
}; | ||
var updated = (0, _computed.computedChain)(cfg, props); | ||
var expected = true; | ||
var actual = isNaN(updated.product); | ||
expect(actual).to.equal(expected); | ||
}); | ||
}); | ||
}); /* globals describe, it, expect */ |
@@ -17,3 +17,3 @@ 'use strict'; | ||
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; } /* globals describe, it, expect */ | ||
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; } | ||
@@ -61,9 +61,2 @@ describe('kind', function () { | ||
it('Should require {prop} property', function () { | ||
var expected = true; | ||
var actual = Kind.propTypes.prop({}, 'prop', 'Kind') instanceof Error; | ||
expect(actual).to.equal(expected); | ||
}); | ||
it('Should default {label} property', function () { | ||
@@ -70,0 +63,0 @@ var subject = _react2.default.createElement(Kind, { prop: 1 }); |
{ | ||
"name": "@enact/core", | ||
"version": "1.0.0-alpha.5", | ||
"version": "1.0.0-beta.1", | ||
"description": "Enact is an open source JavaScript framework containing everything you need to create a fast, scalable mobile or web application.", | ||
@@ -37,2 +37,2 @@ "main": "index.js", | ||
} | ||
} | ||
} |
@@ -8,5 +8,5 @@ 'use strict'; | ||
var _ramda = require('ramda'); | ||
var _curry = require('ramda/src/curry'); | ||
var _ramda2 = _interopRequireDefault(_ramda); | ||
var _curry2 = _interopRequireDefault(_curry); | ||
@@ -24,3 +24,3 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
*/ | ||
var isSelected = _ramda2.default.curry(function (item, selected) { | ||
var isSelected = (0, _curry2.default)(function (item, selected) { | ||
return item === selected || Array.isArray(selected) && selected.indexOf(item) >= 0; | ||
@@ -45,3 +45,3 @@ }); | ||
*/ | ||
var select = _ramda2.default.curry(function (mode, item, selected) { | ||
var select = (0, _curry2.default)(function (mode, item, selected) { | ||
if (mode === 'radio') { | ||
@@ -48,0 +48,0 @@ // When selection is disabled, when selecting only 1, or when selecting the |
@@ -10,6 +10,30 @@ 'use strict'; | ||
var _ramda = require('ramda'); | ||
var _always = require('ramda/src/always'); | ||
var _ramda2 = _interopRequireDefault(_ramda); | ||
var _always2 = _interopRequireDefault(_always); | ||
var _compose = require('ramda/src/compose'); | ||
var _compose2 = _interopRequireDefault(_compose); | ||
var _equals = require('ramda/src/equals'); | ||
var _equals2 = _interopRequireDefault(_equals); | ||
var _isArrayLike = require('ramda/src/isArrayLike'); | ||
var _isArrayLike2 = _interopRequireDefault(_isArrayLike); | ||
var _is = require('ramda/src/is'); | ||
var _is2 = _interopRequireDefault(_is); | ||
var _map = require('ramda/src/map'); | ||
var _map2 = _interopRequireDefault(_map); | ||
var _prop = require('ramda/src/prop'); | ||
var _prop2 = _interopRequireDefault(_prop); | ||
var _react = require('react'); | ||
@@ -19,10 +43,22 @@ | ||
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); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var orderedKeys = _ramda2.default.map(_ramda2.default.prop('key')); | ||
var unorderedKeys = _ramda2.default.compose(_ramda2.default.sort(function (a, b) { | ||
var orderedKeys = (0, _map2.default)((0, _prop2.default)('key')); | ||
var unorderedKeys = (0, _compose2.default)((0, _sort2.default)(function (a, b) { | ||
return a - b; | ||
}), orderedKeys); | ||
var unorderedEquals = _ramda2.default.useWith(_ramda2.default.equals, [unorderedKeys, unorderedKeys]); | ||
var orderedEquals = _ramda2.default.useWith(_ramda2.default.equals, [orderedKeys, orderedKeys]); | ||
var unorderedEquals = (0, _useWith2.default)(_equals2.default, [unorderedKeys, unorderedKeys]); | ||
var orderedEquals = (0, _useWith2.default)(_equals2.default, [orderedKeys, orderedKeys]); | ||
@@ -50,3 +86,3 @@ /** | ||
return _ramda2.default.equals(c1, c2); | ||
return (0, _equals2.default)(c1, c2); | ||
} else if (ordered) { | ||
@@ -80,3 +116,3 @@ return orderedEquals(prevChildren, nextChildren); | ||
*/ | ||
var coerceFunction = _ramda2.default.unless(_ramda2.default.is(Function), _ramda2.default.always); | ||
var coerceFunction = (0, _unless2.default)((0, _is2.default)(Function), _always2.default); | ||
@@ -92,6 +128,9 @@ /** | ||
* @see http://ramdajs.com/docs/#isArrayLike | ||
* @param {*} arg Array or value | ||
* @param {*} array Array or value | ||
* @returns {Array} Either `array` or `[array]` | ||
* @method | ||
*/ | ||
var coerceArray = _ramda2.default.unless(_ramda2.default.isArrayLike, _ramda2.default.of); | ||
var coerceArray = function coerceArray(array) { | ||
return (0, _isArrayLike2.default)(array) ? array : [array]; | ||
}; | ||
@@ -98,0 +137,0 @@ /** |
85247
50
2391