Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@enact/core

Package Overview
Dependencies
Maintainers
1
Versions
218
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@enact/core - npm Package Compare versions

Comparing version 1.7.0 to 2.0.0-alpha.1

4

CHANGELOG.md

@@ -5,2 +5,6 @@ # Change Log

## [2.0.0-alpha.1] - 2017-08-27
No significant changes.
## [1.7.0] - 2017-08-23

@@ -7,0 +11,0 @@

@@ -21,3 +21,5 @@ /**

* }
* );
* ).finally(() => {
* console.log('This will log at the end no matter what happens within the handler above')
* });
* ```

@@ -81,2 +83,6 @@ *

* handling flow. Any input function that returns a falsey value will stop the chain.
*
* The returned handler function has a `finally()` member that accepts a function and returns a new
* handler function. The accepted function is called once the original handler completes regardless
* of the returned value.
*

@@ -99,3 +105,3 @@ * @method handle

return function (ev, props, context) {
var fn = function fn(ev, props, context) {
// if handle() was bound to a class, use its props and context. otherwise, we accept

@@ -110,2 +116,18 @@ // incoming props/context as would be provided by computed/handlers from kind()

};
fn.finally = function (cleanup) {
return function () {
var result = false;
try {
result = fn.apply(undefined, arguments);
} finally {
cleanup.apply(undefined, arguments);
}
return result;
};
};
return fn;
};

@@ -137,6 +159,41 @@

return cond(handlers);
return handle.call(this, cond(handlers));
};
/**
* A function that always returns `true`. Optionally accepts a `handler` function which is called
* before returning `true`.
*
* ```
* // Used to coerce an existing function into a handler change
* const coercedHandler = handle(
* returnsTrue(doesSomething),
* willAlwaysBeCalled
* );
*
* // Used to emulate if/else blocks with `oneOf`
* const ifElseHandler = oneOf(
* [forKey('enter'), handleEnter],
* [returnsTrue, handleOtherwise]
* );
* ```
*
* @method returnsTrue
* @memberof core/handle
* @param {[Function]} handler Handler function called before returning `true`
* @returns {Function} A function that returns true
*/
var returnsTrue = handle.returnsTrue = function (handler) {
if (handler) {
return function () {
handler.apply(undefined, arguments);
return true;
};
}
return true;
};
/**
* Calls a named function on the event and returns `true`

@@ -421,2 +478,2 @@ *

export default handle;
export { callOnEvent, forward, forwardWithPrevent, forEventProp, forKey, forKeyCode, forProp, handle, log, oneOf, _preventDefault as preventDefault, stop, stopImmediate };
export { callOnEvent, forward, forwardWithPrevent, forEventProp, forKey, forKeyCode, forProp, handle, log, oneOf, _preventDefault as preventDefault, returnsTrue, stop, stopImmediate };

@@ -235,2 +235,46 @@ 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; };

describe('finally', function () {
it('should call the finally callback when handle returns true', function () {
var finallyCallback = sinon.spy();
var callback = handle(returnsTrue).finally(finallyCallback);
callback(makeEvent());
var expected = true;
var actual = finallyCallback.calledOnce;
expect(actual).to.equal(expected);
});
it('should call the finally callback when handle returns false', function () {
var finallyCallback = sinon.spy();
var callback = handle(returnsFalse).finally(finallyCallback);
callback(makeEvent());
var expected = true;
var actual = finallyCallback.calledOnce;
expect(actual).to.equal(expected);
});
it('should call the finally callback when handle throws an error', function () {
var finallyCallback = sinon.spy();
var callback = handle(function () {
throw new Error('Something has gone awry ...');
}).finally(finallyCallback);
try {
callback(makeEvent());
} catch (e) {
// we don't want the error to interrupt the test
}
var expected = true;
var actual = finallyCallback.calledOnce;
expect(actual).to.equal(expected);
});
});
describe('#oneOf', function () {

@@ -285,10 +329,9 @@ it('should call each handler until one passes', function () {

it('should return the value from the passed condition branch', function () {
var handler = sinon.spy(function () {
it('should return true when the passed condition branch returns a truthy value', function () {
var callback = oneOf([returnsTrue, function () {
return 'ok';
});
var callback = oneOf([returnsTrue, handler]);
}]);
var expected = callback();
var actual = 'ok';
var expected = true;
var actual = callback();

@@ -298,2 +341,22 @@ expect(actual).to.equal(expected);

it('should return false when the passed condition branch returns a falsey value', function () {
var callback = oneOf([returnsTrue, function () {
return null;
}]);
var expected = false;
var actual = callback();
expect(actual).to.equal(expected);
});
it('should return false when no conditions pass', function () {
var callback = oneOf([returnsFalse, returnsTrue], [returnsFalse, returnsTrue]);
var expected = false;
var actual = callback();
expect(actual).to.equal(expected);
});
it('should support bound handlers', function () {

@@ -315,3 +378,49 @@ var componentInstance = {

});
it('should include object props as second arg when bound', function () {
var componentInstance = {
props: {
value: 1
}
};
var handler = sinon.spy();
var o = oneOf.bind(componentInstance);
var callback = o([returnsTrue, 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 = sinon.spy();
var o = oneOf.bind(componentInstance);
var callback = o([returnsTrue, handler]);
callback();
var expected = 1;
var actual = handler.firstCall.args[2].value;
expect(actual).to.equal(expected);
});
it('should support finally callback', function () {
var handler = sinon.spy();
var callback = oneOf([returnsFalse, returnsTrue], [returnsFalse, returnsTrue]).finally(handler);
callback();
var expected = true;
var actual = handler.calledOnce;
expect(actual).to.equal(expected);
});
});
});
import { isRenderable } from '../util';
import mergeDeepWithKey from 'ramda/src/mergeDeepWithKey';
var mergeFn = function mergeFn(key, defaultValue, userValue) {
// eslint-disable-next-line no-undefined
if (userValue === undefined) {
return defaultValue;
}
return userValue;
};
/**

@@ -56,3 +66,3 @@ * Constructs a Higher-order Component using an optional set of default configuration parameters and

} else {
var cfg = Object.assign({}, defaults, config);
var cfg = mergeDeepWithKey(mergeFn, defaults, config);
if (isRenderable(maybeWrapped)) {

@@ -59,0 +69,0 @@ return factory(cfg, maybeWrapped);

5

package.json
{
"name": "@enact/core",
"version": "1.7.0",
"version": "2.0.0-alpha.1",
"description": "Enact is an open source JavaScript framework containing everything you need to create a fast, scalable mobile or web application.",

@@ -36,4 +36,5 @@ "main": "index.js",

"react": "~15.6.1",
"react-dom": "~15.6.1"
"react-dom": "~15.6.1",
"recompose": "^0.25.0"
}
}

@@ -19,2 +19,3 @@ 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; };

import when from 'ramda/src/when';
import withContext from 'recompose/withContext';

@@ -142,2 +143,33 @@ import Job from './Job';

export { cap, childrenEquals, coerceFunction, coerceArray, Job, isRenderable, extractAriaProps };
/*
* Accepts a `contextTypes` object and a component, then matches those contextTypes with incoming
* props on the component, and sends them to context on that component for children to to access.
*
* Usage:
* ```
* const contextTypes = {
* alignment: PropTypes.string
* };
*
* const Component = withContextFromProps(contextTypes, BaseBase);
*
* // The `alignment` will now be available as a context key in Component's children.
* ```
*
* @param {Object} propsList A contextTypes object full of keys to be used as prop->context and
* their PropTypes as keys
* @param {Component} Wrapped A component to apply this to
*
* @return {Component} The component, now with context on it
* @private
*/
var withContextFromProps = function withContextFromProps(propsList, Wrapped) {
return withContext(propsList, function (props) {
return Object.keys(propsList).reduce(function (obj, key) {
obj[key] = props[key];
return obj;
}, {});
})(Wrapped);
};
export { cap, childrenEquals, coerceFunction, coerceArray, Job, isRenderable, extractAriaProps, withContextFromProps };
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc