🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

preact-redux

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

preact-redux - npm Package Compare versions

Comparing version

to
2.0.0

dist/preact-redux.esm.js

1227

dist/preact-redux.js

@@ -8,3 +8,3 @@ (function (global, factory) {

var Children = {
only: function (children) {
only: function only(children) {
return children && children[0] || null;

@@ -20,34 +20,20 @@ }

func: proptype,
shape: function () {
shape: function shape() {
return proptype;
},
instanceOf: function instanceOf() {
return proptype;
}
};
var storeShape = PropTypes.shape({
subscribe: PropTypes.func.isRequired,
dispatch: PropTypes.func.isRequired,
getState: PropTypes.func.isRequired
});
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj;
};
/**
* Prints a warning in the console if it exists.
*
* @param {String} message The warning message.
* @returns {void}
*/
function warning(message) {
/* eslint-disable no-console */
if (typeof console !== 'undefined' && typeof console.error === 'function') {
console.error(message);
}
/* eslint-enable no-console */
try {
// This error was thrown as a convenience so that you can use this stack
// to find the callsite that caused this warning to fire.
throw new Error(message);
/* eslint-disable no-empty */
} catch (e) {}
/* eslint-enable no-empty */
}
var classCallCheck = function (instance, Constructor) {

@@ -59,2 +45,10 @@ if (!(instance instanceof Constructor)) {

var _extends = Object.assign || function (target) {

@@ -74,2 +68,27 @@ for (var i = 1; i < arguments.length; i++) {

var get = function get(object, property, receiver) {
if (object === null) object = Function.prototype;
var desc = Object.getOwnPropertyDescriptor(object, property);
if (desc === undefined) {
var parent = Object.getPrototypeOf(object);
if (parent === null) {
return undefined;
} else {
return get(parent, property, receiver);
}
} else if ("value" in desc) {
return desc.value;
} else {
var getter = desc.get;
if (getter === undefined) {
return undefined;
}
return getter.call(receiver);
}
};
var inherits = function (subClass, superClass) {

@@ -91,2 +110,22 @@ if (typeof superClass !== "function" && superClass !== null) {

var objectWithoutProperties = function (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;
};
var possibleConstructorReturn = function (self, call) {

@@ -100,2 +139,140 @@ if (!self) {

var set = function set(object, property, value, receiver) {
var desc = Object.getOwnPropertyDescriptor(object, property);
if (desc === undefined) {
var parent = Object.getPrototypeOf(object);
if (parent !== null) {
set(parent, property, value, receiver);
}
} else if ("value" in desc && desc.writable) {
desc.value = value;
} else {
var setter = desc.set;
if (setter !== undefined) {
setter.call(receiver, value);
}
}
return value;
};
// encapsulates the subscription logic for connecting a component to the redux store, as
// well as nesting subscriptions of descendant components, so that we can ensure the
// ancestor components re-render before descendants
var CLEARED = null;
var nullListeners = {
notify: function notify() {}
};
function createListenerCollection() {
// the current/next pattern is copied from redux's createStore code.
// TODO: refactor+expose that code to be reusable here?
var current = [];
var next = [];
return {
clear: function clear() {
next = CLEARED;
current = CLEARED;
},
notify: function notify() {
var listeners = current = next;
for (var i = 0; i < listeners.length; i++) {
listeners[i]();
}
},
subscribe: function subscribe(listener) {
var isSubscribed = true;
if (next === current) next = current.slice();
next.push(listener);
return function unsubscribe() {
if (!isSubscribed || current === CLEARED) return;
isSubscribed = false;
if (next === current) next = current.slice();
next.splice(next.indexOf(listener), 1);
};
}
};
}
var Subscription = function () {
function Subscription(store, parentSub) {
classCallCheck(this, Subscription);
this.store = store;
this.parentSub = parentSub;
this.unsubscribe = null;
this.listeners = nullListeners;
}
Subscription.prototype.addNestedSub = function addNestedSub(listener) {
this.trySubscribe();
return this.listeners.subscribe(listener);
};
Subscription.prototype.notifyNestedSubs = function notifyNestedSubs() {
this.listeners.notify();
};
Subscription.prototype.isSubscribed = function isSubscribed() {
return Boolean(this.unsubscribe);
};
Subscription.prototype.trySubscribe = function trySubscribe() {
if (!this.unsubscribe) {
// this.onStateChange is set by connectAdvanced.initSubscription()
this.unsubscribe = this.parentSub ? this.parentSub.addNestedSub(this.onStateChange) : this.store.subscribe(this.onStateChange);
this.listeners = createListenerCollection();
}
};
Subscription.prototype.tryUnsubscribe = function tryUnsubscribe() {
if (this.unsubscribe) {
this.unsubscribe();
this.unsubscribe = null;
this.listeners.clear();
this.listeners = nullListeners;
}
};
return Subscription;
}();
var storeShape = PropTypes.shape({
subscribe: PropTypes.func.isRequired,
dispatch: PropTypes.func.isRequired,
getState: PropTypes.func.isRequired
});
/**
* Prints a warning in the console if it exists.
*
* @param {String} message The warning message.
* @returns {void}
*/
function warning(message) {
/* eslint-disable no-console */
if (typeof console !== 'undefined' && typeof console.error === 'function') {
console.error(message);
}
/* eslint-enable no-console */
try {
// This error was thrown as a convenience so that if you enable
// "break on all exceptions" in your console,
// it would pause the execution at this line.
throw new Error(message);
/* eslint-disable no-empty */
} catch (e) {}
/* eslint-enable no-empty */
}
var didWarnAboutReceivingStore = false;

@@ -115,3 +292,3 @@ function warnAboutReceivingStore() {

Provider.prototype.getChildContext = function getChildContext() {
return { store: this.store };
return { store: this.store, storeSubscription: null };
};

@@ -129,5 +306,3 @@

Provider.prototype.render = function render() {
var children = this.props.children;
return Children.only(children);
return Children.only(this.props.children);
};

@@ -138,3 +313,3 @@

if (true) {
{
Provider.prototype.componentWillReceiveProps = function (nextProps) {

@@ -152,51 +327,333 @@ var store = this.store;

Provider.childContextTypes = {
store: storeShape.isRequired
store: storeShape.isRequired,
storeSubscription: PropTypes.instanceOf(Subscription)
};
Provider.displayName = 'Provider';
function shallowEqual(objA, objB) {
if (objA === objB) {
return true;
}
/**
* Copyright 2015, Yahoo! Inc.
* Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
*/
var REACT_STATICS = {
childContextTypes: true,
contextTypes: true,
defaultProps: true,
displayName: true,
getDefaultProps: true,
mixins: true,
propTypes: true,
type: true
};
var keysA = Object.keys(objA);
var keysB = Object.keys(objB);
var KNOWN_STATICS = {
name: true,
length: true,
prototype: true,
caller: true,
arguments: true,
arity: true
};
if (keysA.length !== keysB.length) {
return false;
}
var isGetOwnPropertySymbolsAvailable = typeof Object.getOwnPropertySymbols === 'function';
// Test for A's keys different from B.
var hasOwn = Object.prototype.hasOwnProperty;
for (var i = 0; i < keysA.length; i++) {
if (!hasOwn.call(objB, keysA[i]) || objA[keysA[i]] !== objB[keysA[i]]) {
return false;
var index = function hoistNonReactStatics(targetComponent, sourceComponent, customStatics) {
if (typeof sourceComponent !== 'string') {
// don't hoist over string (html) components
var keys = Object.getOwnPropertyNames(sourceComponent);
/* istanbul ignore else */
if (isGetOwnPropertySymbolsAvailable) {
keys = keys.concat(Object.getOwnPropertySymbols(sourceComponent));
}
for (var i = 0; i < keys.length; ++i) {
if (!REACT_STATICS[keys[i]] && !KNOWN_STATICS[keys[i]] && (!customStatics || !customStatics[keys[i]])) {
try {
targetComponent[keys[i]] = sourceComponent[keys[i]];
} catch (error) {}
}
}
}
}
return true;
}
return targetComponent;
};
function wrapActionCreators(actionCreators) {
return function (dispatch) {
return redux.bindActionCreators(actionCreators, dispatch);
var invariant = function () {}
var hotReloadingVersion = 0;
function connectAdvanced(
/*
selectorFactory is a func that is responsible for returning the selector function used to
compute new props from state, props, and dispatch. For example:
export default connectAdvanced((dispatch, options) => (state, props) => ({
thing: state.things[props.thingId],
saveThing: fields => dispatch(actionCreators.saveThing(props.thingId, fields)),
}))(YourComponent)
Access to dispatch is provided to the factory so selectorFactories can bind actionCreators
outside of their selector as an optimization. Options passed to connectAdvanced are passed to
the selectorFactory, along with displayName and WrappedComponent, as the second argument.
Note that selectorFactory is responsible for all caching/memoization of inbound and outbound
props. Do not use connectAdvanced directly without memoizing results between calls to your
selector, otherwise the Connect component will re-render on every state or props change.
*/
selectorFactory) {
var _contextTypes, _childContextTypes;
var _ref = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var _ref$getDisplayName = _ref.getDisplayName;
var getDisplayName = _ref$getDisplayName === undefined ? function (name) {
return 'ConnectAdvanced(' + name + ')';
} : _ref$getDisplayName;
var _ref$methodName = _ref.methodName;
var methodName = _ref$methodName === undefined ? 'connectAdvanced' : _ref$methodName;
var _ref$renderCountProp = _ref.renderCountProp;
var renderCountProp = _ref$renderCountProp === undefined ? undefined : _ref$renderCountProp;
var _ref$shouldHandleStat = _ref.shouldHandleStateChanges;
var shouldHandleStateChanges = _ref$shouldHandleStat === undefined ? true : _ref$shouldHandleStat;
var _ref$storeKey = _ref.storeKey;
var storeKey = _ref$storeKey === undefined ? 'store' : _ref$storeKey;
var _ref$withRef = _ref.withRef;
var withRef = _ref$withRef === undefined ? false : _ref$withRef;
var connectOptions = objectWithoutProperties(_ref, ['getDisplayName', 'methodName', 'renderCountProp', 'shouldHandleStateChanges', 'storeKey', 'withRef']);
var subscriptionKey = storeKey + 'Subscription';
var version = hotReloadingVersion++;
var contextTypes = (_contextTypes = {}, _contextTypes[storeKey] = storeShape, _contextTypes[subscriptionKey] = PropTypes.instanceOf(Subscription), _contextTypes);
var childContextTypes = (_childContextTypes = {}, _childContextTypes[subscriptionKey] = PropTypes.instanceOf(Subscription), _childContextTypes);
return function wrapWithConnect(WrappedComponent) {
invariant(typeof WrappedComponent == 'function', 'You must pass a component to the function returned by ' + ('connect. Instead received ' + WrappedComponent));
var wrappedComponentName = WrappedComponent.displayName || WrappedComponent.name || 'Component';
var displayName = getDisplayName(wrappedComponentName);
var selectorFactoryOptions = _extends({}, connectOptions, {
getDisplayName: getDisplayName,
methodName: methodName,
renderCountProp: renderCountProp,
shouldHandleStateChanges: shouldHandleStateChanges,
storeKey: storeKey,
withRef: withRef,
displayName: displayName,
wrappedComponentName: wrappedComponentName,
WrappedComponent: WrappedComponent
});
var Connect = function (_Component) {
inherits(Connect, _Component);
function Connect(props, context) {
classCallCheck(this, Connect);
var _this = possibleConstructorReturn(this, _Component.call(this, props, context));
_this.version = version;
_this.state = {};
_this.renderCount = 0;
_this.store = _this.props[storeKey] || _this.context[storeKey];
_this.parentSub = props[subscriptionKey] || context[subscriptionKey];
_this.setWrappedInstance = _this.setWrappedInstance.bind(_this);
invariant(_this.store, 'Could not find "' + storeKey + '" in either the context or ' + ('props of "' + displayName + '". ') + 'Either wrap the root component in a <Provider>, ' + ('or explicitly pass "' + storeKey + '" as a prop to "' + displayName + '".'));
// make sure `getState` is properly bound in order to avoid breaking
// custom store implementations that rely on the store's context
_this.getState = _this.store.getState.bind(_this.store);
_this.initSelector();
_this.initSubscription();
return _this;
}
Connect.prototype.getChildContext = function getChildContext() {
var _ref2;
return _ref2 = {}, _ref2[subscriptionKey] = this.subscription || this.parentSub, _ref2;
};
Connect.prototype.componentDidMount = function componentDidMount() {
if (!shouldHandleStateChanges) return;
// componentWillMount fires during server side rendering, but componentDidMount and
// componentWillUnmount do not. Because of this, trySubscribe happens during ...didMount.
// Otherwise, unsubscription would never take place during SSR, causing a memory leak.
// To handle the case where a child component may have triggered a state change by
// dispatching an action in its componentWillMount, we have to re-run the select and maybe
// re-render.
this.subscription.trySubscribe();
this.selector.run(this.props);
if (this.selector.shouldComponentUpdate) this.forceUpdate();
};
Connect.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
this.selector.run(nextProps);
};
Connect.prototype.shouldComponentUpdate = function shouldComponentUpdate() {
return this.selector.shouldComponentUpdate;
};
Connect.prototype.componentWillUnmount = function componentWillUnmount() {
if (this.subscription) this.subscription.tryUnsubscribe();
// these are just to guard against extra memory leakage if a parent element doesn't
// dereference this instance properly, such as an async callback that never finishes
this.subscription = null;
this.store = null;
this.parentSub = null;
this.selector.run = function () {};
};
Connect.prototype.getWrappedInstance = function getWrappedInstance() {
invariant(withRef, 'To access the wrapped instance, you need to specify ' + ('{ withRef: true } in the options argument of the ' + methodName + '() call.'));
return this.wrappedInstance;
};
Connect.prototype.setWrappedInstance = function setWrappedInstance(ref) {
this.wrappedInstance = ref;
};
Connect.prototype.initSelector = function initSelector() {
var dispatch = this.store.dispatch;
var getState = this.getState;
var sourceSelector = selectorFactory(dispatch, selectorFactoryOptions);
// wrap the selector in an object that tracks its results between runs
var selector = this.selector = {
shouldComponentUpdate: true,
props: sourceSelector(getState(), this.props),
run: function runComponentSelector(props) {
try {
var nextProps = sourceSelector(getState(), props);
if (selector.error || nextProps !== selector.props) {
selector.shouldComponentUpdate = true;
selector.props = nextProps;
selector.error = null;
}
} catch (error) {
selector.shouldComponentUpdate = true;
selector.error = error;
}
}
};
};
Connect.prototype.initSubscription = function initSubscription() {
var _this2 = this;
if (shouldHandleStateChanges) {
(function () {
var subscription = _this2.subscription = new Subscription(_this2.store, _this2.parentSub);
var dummyState = {};
subscription.onStateChange = function onStateChange() {
this.selector.run(this.props);
if (!this.selector.shouldComponentUpdate) {
subscription.notifyNestedSubs();
} else {
this.componentDidUpdate = function componentDidUpdate() {
this.componentDidUpdate = undefined;
subscription.notifyNestedSubs();
};
this.setState(dummyState);
}
}.bind(_this2);
})();
}
};
Connect.prototype.isSubscribed = function isSubscribed() {
return Boolean(this.subscription) && this.subscription.isSubscribed();
};
Connect.prototype.addExtraProps = function addExtraProps(props) {
if (!withRef && !renderCountProp) return props;
// make a shallow copy so that fields added don't leak to the original selector.
// this is especially important for 'ref' since that's a reference back to the component
// instance. a singleton memoized selector would then be holding a reference to the
// instance, preventing the instance from being garbage collected, and that would be bad
var withExtras = _extends({}, props);
if (withRef) withExtras.ref = this.setWrappedInstance;
if (renderCountProp) withExtras[renderCountProp] = this.renderCount++;
return withExtras;
};
Connect.prototype.render = function render() {
var selector = this.selector;
selector.shouldComponentUpdate = false;
if (selector.error) {
throw selector.error;
} else {
return preact.h(WrappedComponent, this.addExtraProps(selector.props));
}
};
return Connect;
}(preact.Component);
Connect.WrappedComponent = WrappedComponent;
Connect.displayName = displayName;
Connect.childContextTypes = childContextTypes;
Connect.contextTypes = contextTypes;
{
Connect.prototype.componentWillUpdate = function componentWillUpdate() {
// We are hot reloading!
if (this.version !== version) {
this.version = version;
this.initSelector();
if (this.subscription) this.subscription.tryUnsubscribe();
this.initSubscription();
if (shouldHandleStateChanges) this.subscription.trySubscribe();
}
};
}
return index(Connect, WrappedComponent);
};
}
var hasOwn = Object.prototype.hasOwnProperty;
function shallowEqual(a, b) {
if (a === b) return true;
var countA = 0;
var countB = 0;
for (var key in a) {
if (hasOwn.call(a, key) && a[key] !== b[key]) return false;
countA++;
}
for (var _key in b) {
if (hasOwn.call(b, _key)) countB++;
}
return countA === countB;
}
/* Built-in method references for those with the same name as other `lodash` methods. */
var nativeGetPrototype = Object.getPrototypeOf;
/**
* Creates a unary function that invokes `func` with its argument transformed.
* Gets the `[[Prototype]]` of `value`.
*
* @private
* @param {Function} func The function to wrap.
* @param {Function} transform The argument transform.
* @returns {Function} Returns the new function.
* @param {*} value The value to query.
* @returns {null|Object} Returns the `[[Prototype]]`.
*/
function overArg(func, transform) {
return function (arg) {
return func(transform(arg));
};
function getPrototype(value) {
return nativeGetPrototype(Object(value));
}
/** Built-in value references. */
var getPrototype = overArg(Object.getPrototypeOf, Object);
/**

@@ -246,3 +703,3 @@ * Checks if `value` is a host object in IE < 9.

function isObjectLike(value) {
return !!value && typeof value == 'object';
return !!value && (typeof value === 'undefined' ? 'undefined' : _typeof(value)) == 'object';
}

@@ -254,6 +711,6 @@

/** Used for built-in method references. */
var funcProto = Function.prototype;
var objectProto = Object.prototype;
/** Used to resolve the decompiled source of functions. */
var funcToString = funcProto.toString;
var funcToString = Function.prototype.toString;

@@ -268,3 +725,3 @@ /** Used to check objects for own properties. */

* Used to resolve the
* [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
* [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
* of values.

@@ -283,3 +740,4 @@ */

* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
* @returns {boolean} Returns `true` if `value` is a plain object,
* else `false`.
* @example

@@ -304,435 +762,376 @@ *

function isPlainObject(value) {
if (!isObjectLike(value) || objectToString.call(value) != objectTag || isHostObject(value)) {
return false;
}
var proto = getPrototype(value);
if (proto === null) {
return true;
}
var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
return typeof Ctor == 'function' && Ctor instanceof Ctor && funcToString.call(Ctor) == objectCtorString;
if (!isObjectLike(value) || objectToString.call(value) != objectTag || isHostObject(value)) {
return false;
}
var proto = getPrototype(value);
if (proto === null) {
return true;
}
var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
return typeof Ctor == 'function' && Ctor instanceof Ctor && funcToString.call(Ctor) == objectCtorString;
}
function interopDefault(ex) {
return ex && typeof ex === 'object' && 'default' in ex ? ex['default'] : ex;
function verifyPlainObject(value, displayName, methodName) {
if (!isPlainObject(value)) {
warning(methodName + '() in ' + displayName + ' must return a plain object. Instead received ' + value + '.');
}
}
function createCommonjsModule(fn, module) {
return module = { exports: {} }, fn(module, module.exports), module.exports;
function wrapMapToPropsConstant(getConstant) {
return function initConstantSelector(dispatch, options) {
var constant = getConstant(dispatch, options);
function constantSelector() {
return constant;
}
constantSelector.dependsOnOwnProps = false;
return constantSelector;
};
}
var index = createCommonjsModule(function (module) {
/**
* Copyright 2015, Yahoo! Inc.
* Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms.
*/
'use strict';
// dependsOnOwnProps is used by createMapToPropsProxy to determine whether to pass props as args
// to the mapToProps function being wrapped. It is also used by makePurePropsSelector to determine
// whether mapToProps needs to be invoked when props have changed.
//
// A length of one signals that mapToProps does not depend on props from the parent component.
// A length of zero is assumed to mean mapToProps is getting args via arguments or ...args and
// therefore not reporting its length accurately..
function getDependsOnOwnProps(mapToProps) {
return mapToProps.dependsOnOwnProps !== null && mapToProps.dependsOnOwnProps !== undefined ? Boolean(mapToProps.dependsOnOwnProps) : mapToProps.length !== 1;
}
var REACT_STATICS = {
childContextTypes: true,
contextTypes: true,
defaultProps: true,
displayName: true,
getDefaultProps: true,
mixins: true,
propTypes: true,
type: true
};
// Used by whenMapStateToPropsIsFunction and whenMapDispatchToPropsIsFunction,
// this function wraps mapToProps in a proxy function which does several things:
//
// * Detects whether the mapToProps function being called depends on props, which
// is used by selectorFactory to decide if it should reinvoke on props changes.
//
// * On first call, handles mapToProps if returns another function, and treats that
// new function as the true mapToProps for subsequent calls.
//
// * On first call, verifies the first result is a plain object, in order to warn
// the developer that their mapToProps function is not returning a valid result.
//
function wrapMapToPropsFunc(mapToProps, methodName) {
return function initProxySelector(dispatch, _ref) {
var displayName = _ref.displayName;
var KNOWN_STATICS = {
name: true,
length: true,
prototype: true,
caller: true,
arguments: true,
arity: true
var proxy = function mapToPropsProxy(stateOrDispatch, ownProps) {
return proxy.dependsOnOwnProps ? proxy.mapToProps(stateOrDispatch, ownProps) : proxy.mapToProps(stateOrDispatch);
};
var isGetOwnPropertySymbolsAvailable = typeof Object.getOwnPropertySymbols === 'function';
proxy.dependsOnOwnProps = getDependsOnOwnProps(mapToProps);
module.exports = function hoistNonReactStatics(targetComponent, sourceComponent, customStatics) {
if (typeof sourceComponent !== 'string') {
// don't hoist over string (html) components
var keys = Object.getOwnPropertyNames(sourceComponent);
proxy.mapToProps = function detectFactoryAndVerify(stateOrDispatch, ownProps) {
proxy.mapToProps = mapToProps;
var props = proxy(stateOrDispatch, ownProps);
/* istanbul ignore else */
if (isGetOwnPropertySymbolsAvailable) {
keys = keys.concat(Object.getOwnPropertySymbols(sourceComponent));
}
if (typeof props === 'function') {
proxy.mapToProps = props;
proxy.dependsOnOwnProps = getDependsOnOwnProps(props);
props = proxy(stateOrDispatch, ownProps);
}
for (var i = 0; i < keys.length; ++i) {
if (!REACT_STATICS[keys[i]] && !KNOWN_STATICS[keys[i]] && (!customStatics || !customStatics[keys[i]])) {
try {
targetComponent[keys[i]] = sourceComponent[keys[i]];
} catch (error) {}
}
}
}
verifyPlainObject(props, displayName, methodName);
return targetComponent;
return props;
};
});
var hoistStatics = interopDefault(index);
return proxy;
};
}
function invariant () {}
function whenMapDispatchToPropsIsFunction(mapDispatchToProps) {
return typeof mapDispatchToProps === 'function' ? wrapMapToPropsFunc(mapDispatchToProps, 'mapDispatchToProps') : undefined;
}
var defaultMapStateToProps = function (state) {
return {};
}; // eslint-disable-line no-unused-vars
var defaultMapDispatchToProps = function (dispatch) {
return { dispatch: dispatch };
};
var defaultMergeProps = function (stateProps, dispatchProps, parentProps) {
return _extends({}, parentProps, stateProps, dispatchProps);
};
function whenMapDispatchToPropsIsMissing(mapDispatchToProps) {
return !mapDispatchToProps ? wrapMapToPropsConstant(function (dispatch) {
return { dispatch: dispatch };
}) : undefined;
}
function getDisplayName(WrappedComponent) {
return WrappedComponent.displayName || WrappedComponent.name || 'Component';
function whenMapDispatchToPropsIsObject(mapDispatchToProps) {
return mapDispatchToProps && (typeof mapDispatchToProps === 'undefined' ? 'undefined' : _typeof(mapDispatchToProps)) === 'object' ? wrapMapToPropsConstant(function (dispatch) {
return redux.bindActionCreators(mapDispatchToProps, dispatch);
}) : undefined;
}
var errorObject = { value: null };
function tryCatch(fn, ctx) {
try {
return fn.apply(ctx);
} catch (e) {
errorObject.value = e;
return errorObject;
}
var defaultMapDispatchToPropsFactories = [whenMapDispatchToPropsIsFunction, whenMapDispatchToPropsIsMissing, whenMapDispatchToPropsIsObject];
function whenMapStateToPropsIsFunction(mapStateToProps) {
return typeof mapStateToProps === 'function' ? wrapMapToPropsFunc(mapStateToProps, 'mapStateToProps') : undefined;
}
// Helps track hot reloading.
var nextVersion = 0;
function whenMapStateToPropsIsMissing(mapStateToProps) {
return !mapStateToProps ? wrapMapToPropsConstant(function () {
return {};
}) : undefined;
}
function connect(mapStateToProps, mapDispatchToProps, mergeProps) {
var options = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3];
var defaultMapStateToPropsFactories = [whenMapStateToPropsIsFunction, whenMapStateToPropsIsMissing];
var shouldSubscribe = Boolean(mapStateToProps);
var mapState = mapStateToProps || defaultMapStateToProps;
function defaultMergeProps(stateProps, dispatchProps, ownProps) {
return _extends({}, ownProps, stateProps, dispatchProps);
}
var mapDispatch = void 0;
if (typeof mapDispatchToProps === 'function') {
mapDispatch = mapDispatchToProps;
} else if (!mapDispatchToProps) {
mapDispatch = defaultMapDispatchToProps;
} else {
mapDispatch = wrapActionCreators(mapDispatchToProps);
}
function wrapMergePropsFunc(mergeProps) {
return function initMergePropsProxy(dispatch, _ref) {
var displayName = _ref.displayName;
var pure = _ref.pure;
var areMergedPropsEqual = _ref.areMergedPropsEqual;
var finalMergeProps = mergeProps || defaultMergeProps;
var _options$pure = options.pure;
var pure = _options$pure === undefined ? true : _options$pure;
var _options$withRef = options.withRef;
var withRef = _options$withRef === undefined ? false : _options$withRef;
var hasRunOnce = false;
var mergedProps = void 0;
var checkMergedEquals = pure && finalMergeProps !== defaultMergeProps;
return function mergePropsProxy(stateProps, dispatchProps, ownProps) {
var nextMergedProps = mergeProps(stateProps, dispatchProps, ownProps);
// Helps track hot reloading.
var version = nextVersion++;
if (hasRunOnce) {
if (!pure || !areMergedPropsEqual(nextMergedProps, mergedProps)) mergedProps = nextMergedProps;
} else {
hasRunOnce = true;
mergedProps = nextMergedProps;
return function wrapWithConnect(WrappedComponent) {
var connectDisplayName = 'Connect(' + getDisplayName(WrappedComponent) + ')';
function checkStateShape(props, methodName) {
if (!isPlainObject(props)) {
warning(methodName + '() in ' + connectDisplayName + ' must return a plain object. ' + ('Instead received ' + props + '.'));
verifyPlainObject(mergedProps, displayName, 'mergeProps');
}
}
function computeMergedProps(stateProps, dispatchProps, parentProps) {
var mergedProps = finalMergeProps(stateProps, dispatchProps, parentProps);
if (true) {
checkStateShape(mergedProps, 'mergeProps');
}
return mergedProps;
}
};
};
}
var Connect = function (_Component) {
inherits(Connect, _Component);
function whenMergePropsIsFunction(mergeProps) {
return typeof mergeProps === 'function' ? wrapMergePropsFunc(mergeProps) : undefined;
}
Connect.prototype.shouldComponentUpdate = function shouldComponentUpdate() {
return !pure || this.haveOwnPropsChanged || this.hasStoreStateChanged;
};
function whenMergePropsIsOmitted(mergeProps) {
return !mergeProps ? function () {
return defaultMergeProps;
} : undefined;
}
function Connect(props, context) {
classCallCheck(this, Connect);
var defaultMergePropsFactories = [whenMergePropsIsFunction, whenMergePropsIsOmitted];
var _this = possibleConstructorReturn(this, _Component.call(this, props, context));
function verify(selector, methodName, displayName) {
if (!selector) {
throw new Error('Unexpected value for ' + methodName + ' in ' + displayName + '.');
} else if (methodName === 'mapStateToProps' || methodName === 'mapDispatchToProps') {
if (!selector.hasOwnProperty('dependsOnOwnProps')) {
warning('The selector for ' + methodName + ' of ' + displayName + ' did not specify a value for dependsOnOwnProps.');
}
}
}
_this.version = version;
_this.store = props.store || context.store;
function verifySubselectors(mapStateToProps, mapDispatchToProps, mergeProps, displayName) {
verify(mapStateToProps, 'mapStateToProps', displayName);
verify(mapDispatchToProps, 'mapDispatchToProps', displayName);
verify(mergeProps, 'mergeProps', displayName);
}
invariant(_this.store, 'Could not find "store" in either the context or ' + ('props of "' + connectDisplayName + '". ') + 'Either wrap the root component in a <Provider>, ' + ('or explicitly pass "store" as a prop to "' + connectDisplayName + '".'));
function impureFinalPropsSelectorFactory(mapStateToProps, mapDispatchToProps, mergeProps, dispatch) {
return function impureFinalPropsSelector(state, ownProps) {
return mergeProps(mapStateToProps(state, ownProps), mapDispatchToProps(dispatch, ownProps), ownProps);
};
}
var storeState = _this.store.getState();
_this.state = { storeState: storeState };
_this.clearCache();
return _this;
}
function pureFinalPropsSelectorFactory(mapStateToProps, mapDispatchToProps, mergeProps, dispatch, _ref) {
var areStatesEqual = _ref.areStatesEqual;
var areOwnPropsEqual = _ref.areOwnPropsEqual;
var areStatePropsEqual = _ref.areStatePropsEqual;
Connect.prototype.computeStateProps = function computeStateProps(store, props) {
if (!this.finalMapStateToProps) {
return this.configureFinalMapState(store, props);
}
var hasRunAtLeastOnce = false;
var state = void 0;
var ownProps = void 0;
var stateProps = void 0;
var dispatchProps = void 0;
var mergedProps = void 0;
var state = store.getState();
var stateProps = this.doStatePropsDependOnOwnProps ? this.finalMapStateToProps(state, props) : this.finalMapStateToProps(state);
function handleFirstCall(firstState, firstOwnProps) {
state = firstState;
ownProps = firstOwnProps;
stateProps = mapStateToProps(state, ownProps);
dispatchProps = mapDispatchToProps(dispatch, ownProps);
mergedProps = mergeProps(stateProps, dispatchProps, ownProps);
hasRunAtLeastOnce = true;
return mergedProps;
}
if (true) {
checkStateShape(stateProps, 'mapStateToProps');
}
return stateProps;
};
function handleNewPropsAndNewState() {
stateProps = mapStateToProps(state, ownProps);
Connect.prototype.configureFinalMapState = function configureFinalMapState(store, props) {
var mappedState = mapState(store.getState(), props);
var isFactory = typeof mappedState === 'function';
if (mapDispatchToProps.dependsOnOwnProps) dispatchProps = mapDispatchToProps(dispatch, ownProps);
this.finalMapStateToProps = isFactory ? mappedState : mapState;
this.doStatePropsDependOnOwnProps = this.finalMapStateToProps.length !== 1;
mergedProps = mergeProps(stateProps, dispatchProps, ownProps);
return mergedProps;
}
if (isFactory) {
return this.computeStateProps(store, props);
}
function handleNewProps() {
if (mapStateToProps.dependsOnOwnProps) stateProps = mapStateToProps(state, ownProps);
if (true) {
checkStateShape(mappedState, 'mapStateToProps');
}
return mappedState;
};
if (mapDispatchToProps.dependsOnOwnProps) dispatchProps = mapDispatchToProps(dispatch, ownProps);
Connect.prototype.computeDispatchProps = function computeDispatchProps(store, props) {
if (!this.finalMapDispatchToProps) {
return this.configureFinalMapDispatch(store, props);
}
mergedProps = mergeProps(stateProps, dispatchProps, ownProps);
return mergedProps;
}
var dispatch = store.dispatch;
function handleNewState() {
var nextStateProps = mapStateToProps(state, ownProps);
var statePropsChanged = !areStatePropsEqual(nextStateProps, stateProps);
stateProps = nextStateProps;
var dispatchProps = this.doDispatchPropsDependOnOwnProps ? this.finalMapDispatchToProps(dispatch, props) : this.finalMapDispatchToProps(dispatch);
if (statePropsChanged) mergedProps = mergeProps(stateProps, dispatchProps, ownProps);
if (true) {
checkStateShape(dispatchProps, 'mapDispatchToProps');
}
return dispatchProps;
};
return mergedProps;
}
Connect.prototype.configureFinalMapDispatch = function configureFinalMapDispatch(store, props) {
var mappedDispatch = mapDispatch(store.dispatch, props);
var isFactory = typeof mappedDispatch === 'function';
function handleSubsequentCalls(nextState, nextOwnProps) {
var propsChanged = !areOwnPropsEqual(nextOwnProps, ownProps);
var stateChanged = !areStatesEqual(nextState, state);
state = nextState;
ownProps = nextOwnProps;
this.finalMapDispatchToProps = isFactory ? mappedDispatch : mapDispatch;
this.doDispatchPropsDependOnOwnProps = this.finalMapDispatchToProps.length !== 1;
if (propsChanged && stateChanged) return handleNewPropsAndNewState();
if (propsChanged) return handleNewProps();
if (stateChanged) return handleNewState();
return mergedProps;
}
if (isFactory) {
return this.computeDispatchProps(store, props);
}
return function pureFinalPropsSelector(nextState, nextOwnProps) {
return hasRunAtLeastOnce ? handleSubsequentCalls(nextState, nextOwnProps) : handleFirstCall(nextState, nextOwnProps);
};
}
if (true) {
checkStateShape(mappedDispatch, 'mapDispatchToProps');
}
return mappedDispatch;
};
// TODO: Add more comments
Connect.prototype.updateStatePropsIfNeeded = function updateStatePropsIfNeeded() {
var nextStateProps = this.computeStateProps(this.store, this.props);
if (this.stateProps && shallowEqual(nextStateProps, this.stateProps)) {
return false;
}
// If pure is true, the selector returned by selectorFactory will memoize its results,
// allowing connectAdvanced's shouldComponentUpdate to return false if final
// props have not changed. If false, the selector will always return a new
// object and shouldComponentUpdate will always return true.
this.stateProps = nextStateProps;
return true;
};
function finalPropsSelectorFactory(dispatch, _ref2) {
var initMapStateToProps = _ref2.initMapStateToProps;
var initMapDispatchToProps = _ref2.initMapDispatchToProps;
var initMergeProps = _ref2.initMergeProps;
var options = objectWithoutProperties(_ref2, ['initMapStateToProps', 'initMapDispatchToProps', 'initMergeProps']);
Connect.prototype.updateDispatchPropsIfNeeded = function updateDispatchPropsIfNeeded() {
var nextDispatchProps = this.computeDispatchProps(this.store, this.props);
if (this.dispatchProps && shallowEqual(nextDispatchProps, this.dispatchProps)) {
return false;
}
var mapStateToProps = initMapStateToProps(dispatch, options);
var mapDispatchToProps = initMapDispatchToProps(dispatch, options);
var mergeProps = initMergeProps(dispatch, options);
this.dispatchProps = nextDispatchProps;
return true;
};
{
verifySubselectors(mapStateToProps, mapDispatchToProps, mergeProps, options.displayName);
}
Connect.prototype.updateMergedPropsIfNeeded = function updateMergedPropsIfNeeded() {
var nextMergedProps = computeMergedProps(this.stateProps, this.dispatchProps, this.props);
if (this.mergedProps && checkMergedEquals && shallowEqual(nextMergedProps, this.mergedProps)) {
return false;
}
var selectorFactory = options.pure ? pureFinalPropsSelectorFactory : impureFinalPropsSelectorFactory;
this.mergedProps = nextMergedProps;
return true;
};
return selectorFactory(mapStateToProps, mapDispatchToProps, mergeProps, dispatch, options);
}
Connect.prototype.isSubscribed = function isSubscribed() {
return typeof this.unsubscribe === 'function';
};
/*
connect is a facade over connectAdvanced. It turns its args into a compatible
selectorFactory, which has the signature:
Connect.prototype.trySubscribe = function trySubscribe() {
if (shouldSubscribe && !this.unsubscribe) {
this.unsubscribe = this.store.subscribe(this.handleChange.bind(this));
this.handleChange();
}
};
(dispatch, options) => (nextState, nextOwnProps) => nextFinalProps
connect passes its args to connectAdvanced as options, which will in turn pass them to
selectorFactory each time a Connect component instance is instantiated or hot reloaded.
Connect.prototype.tryUnsubscribe = function tryUnsubscribe() {
if (this.unsubscribe) {
this.unsubscribe();
this.unsubscribe = null;
}
};
selectorFactory returns a final props selector from its mapStateToProps,
mapStateToPropsFactories, mapDispatchToProps, mapDispatchToPropsFactories, mergeProps,
mergePropsFactories, and pure args.
Connect.prototype.componentDidMount = function componentDidMount() {
this.trySubscribe();
};
The resulting final props selector is called by the Connect component instance whenever
it receives new props or store state.
*/
Connect.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
if (!pure || !shallowEqual(nextProps, this.props)) {
this.haveOwnPropsChanged = true;
}
};
function match(arg, factories, name) {
for (var i = factories.length - 1; i >= 0; i--) {
var result = factories[i](arg);
if (result) return result;
}
Connect.prototype.componentWillUnmount = function componentWillUnmount() {
this.tryUnsubscribe();
this.clearCache();
};
return function (dispatch, options) {
throw new Error('Invalid value of type ' + (typeof arg === 'undefined' ? 'undefined' : _typeof(arg)) + ' for ' + name + ' argument when connecting component ' + options.wrappedComponentName + '.');
};
}
Connect.prototype.clearCache = function clearCache() {
this.dispatchProps = null;
this.stateProps = null;
this.mergedProps = null;
this.haveOwnPropsChanged = true;
this.hasStoreStateChanged = true;
this.haveStatePropsBeenPrecalculated = false;
this.statePropsPrecalculationError = null;
this.renderedElement = null;
this.finalMapDispatchToProps = null;
this.finalMapStateToProps = null;
};
function strictEqual(a, b) {
return a === b;
}
Connect.prototype.handleChange = function handleChange() {
if (!this.unsubscribe) {
return;
}
// createConnect with default args builds the 'official' connect behavior. Calling it with
// different options opens up some testing and extensibility scenarios
function createConnect() {
var _ref = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
var storeState = this.store.getState();
var prevStoreState = this.state.storeState;
if (pure && prevStoreState === storeState) {
return;
}
var _ref$connectHOC = _ref.connectHOC;
var connectHOC = _ref$connectHOC === undefined ? connectAdvanced : _ref$connectHOC;
var _ref$mapStateToPropsF = _ref.mapStateToPropsFactories;
var mapStateToPropsFactories = _ref$mapStateToPropsF === undefined ? defaultMapStateToPropsFactories : _ref$mapStateToPropsF;
var _ref$mapDispatchToPro = _ref.mapDispatchToPropsFactories;
var mapDispatchToPropsFactories = _ref$mapDispatchToPro === undefined ? defaultMapDispatchToPropsFactories : _ref$mapDispatchToPro;
var _ref$mergePropsFactor = _ref.mergePropsFactories;
var mergePropsFactories = _ref$mergePropsFactor === undefined ? defaultMergePropsFactories : _ref$mergePropsFactor;
var _ref$selectorFactory = _ref.selectorFactory;
var selectorFactory = _ref$selectorFactory === undefined ? finalPropsSelectorFactory : _ref$selectorFactory;
if (pure && !this.doStatePropsDependOnOwnProps) {
var haveStatePropsChanged = tryCatch(this.updateStatePropsIfNeeded, this);
if (!haveStatePropsChanged) {
return;
}
if (haveStatePropsChanged === errorObject) {
this.statePropsPrecalculationError = errorObject.value;
}
this.haveStatePropsBeenPrecalculated = true;
}
return function connect(mapStateToProps, mapDispatchToProps, mergeProps) {
var _ref2 = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3];
this.hasStoreStateChanged = true;
this.setState({ storeState: storeState });
};
var _ref2$pure = _ref2.pure;
var pure = _ref2$pure === undefined ? true : _ref2$pure;
var _ref2$areStatesEqual = _ref2.areStatesEqual;
var areStatesEqual = _ref2$areStatesEqual === undefined ? strictEqual : _ref2$areStatesEqual;
var _ref2$areOwnPropsEqua = _ref2.areOwnPropsEqual;
var areOwnPropsEqual = _ref2$areOwnPropsEqua === undefined ? shallowEqual : _ref2$areOwnPropsEqua;
var _ref2$areStatePropsEq = _ref2.areStatePropsEqual;
var areStatePropsEqual = _ref2$areStatePropsEq === undefined ? shallowEqual : _ref2$areStatePropsEq;
var _ref2$areMergedPropsE = _ref2.areMergedPropsEqual;
var areMergedPropsEqual = _ref2$areMergedPropsE === undefined ? shallowEqual : _ref2$areMergedPropsE;
var extraOptions = objectWithoutProperties(_ref2, ['pure', 'areStatesEqual', 'areOwnPropsEqual', 'areStatePropsEqual', 'areMergedPropsEqual']);
Connect.prototype.getWrappedInstance = function getWrappedInstance() {
invariant(withRef, 'To access the wrapped instance, you need to specify ' + '{ withRef: true } as the fourth argument of the connect() call.');
var initMapStateToProps = match(mapStateToProps, mapStateToPropsFactories, 'mapStateToProps');
var initMapDispatchToProps = match(mapDispatchToProps, mapDispatchToPropsFactories, 'mapDispatchToProps');
var initMergeProps = match(mergeProps, mergePropsFactories, 'mergeProps');
return this.refs.wrappedInstance;
};
return connectHOC(selectorFactory, _extends({
// used in error messages
methodName: 'connect',
Connect.prototype.render = function render() {
var haveOwnPropsChanged = this.haveOwnPropsChanged;
var hasStoreStateChanged = this.hasStoreStateChanged;
var haveStatePropsBeenPrecalculated = this.haveStatePropsBeenPrecalculated;
var statePropsPrecalculationError = this.statePropsPrecalculationError;
var renderedElement = this.renderedElement;
// used to compute Connect's displayName from the wrapped component's displayName.
getDisplayName: function getDisplayName(name) {
return 'Connect(' + name + ')';
},
// if mapStateToProps is falsy, the Connect component doesn't subscribe to store state changes
shouldHandleStateChanges: Boolean(mapStateToProps),
this.haveOwnPropsChanged = false;
this.hasStoreStateChanged = false;
this.haveStatePropsBeenPrecalculated = false;
this.statePropsPrecalculationError = null;
// passed through to selectorFactory
initMapStateToProps: initMapStateToProps,
initMapDispatchToProps: initMapDispatchToProps,
initMergeProps: initMergeProps,
pure: pure,
areStatesEqual: areStatesEqual,
areOwnPropsEqual: areOwnPropsEqual,
areStatePropsEqual: areStatePropsEqual,
areMergedPropsEqual: areMergedPropsEqual
if (statePropsPrecalculationError) {
throw statePropsPrecalculationError;
}
var shouldUpdateStateProps = true;
var shouldUpdateDispatchProps = true;
if (pure && renderedElement) {
shouldUpdateStateProps = hasStoreStateChanged || haveOwnPropsChanged && this.doStatePropsDependOnOwnProps;
shouldUpdateDispatchProps = haveOwnPropsChanged && this.doDispatchPropsDependOnOwnProps;
}
var haveStatePropsChanged = false;
var haveDispatchPropsChanged = false;
if (haveStatePropsBeenPrecalculated) {
haveStatePropsChanged = true;
} else if (shouldUpdateStateProps) {
haveStatePropsChanged = this.updateStatePropsIfNeeded();
}
if (shouldUpdateDispatchProps) {
haveDispatchPropsChanged = this.updateDispatchPropsIfNeeded();
}
var haveMergedPropsChanged = true;
if (haveStatePropsChanged || haveDispatchPropsChanged || haveOwnPropsChanged) {
haveMergedPropsChanged = this.updateMergedPropsIfNeeded();
} else {
haveMergedPropsChanged = false;
}
if (!haveMergedPropsChanged && renderedElement) {
return renderedElement;
}
if (withRef) {
this.renderedElement = preact.h(WrappedComponent, _extends({}, this.mergedProps, {
ref: 'wrappedInstance'
}));
} else {
this.renderedElement = preact.h(WrappedComponent, this.mergedProps);
}
return this.renderedElement;
};
return Connect;
}(preact.Component);
Connect.displayName = connectDisplayName;
Connect.WrappedComponent = WrappedComponent;
Connect.contextTypes = {
store: storeShape
};
if (true) {
Connect.prototype.componentWillUpdate = function componentWillUpdate() {
if (this.version === version) {
return;
}
// We are hot reloading!
this.version = version;
this.trySubscribe();
this.clearCache();
};
}
return hoistStatics(Connect, WrappedComponent);
}, extraOptions));
};
}
var connect$1 = createConnect();
var lib = {
var lib$1 = {
Provider: Provider,
connect: connect
connect: connect$1,
connectAdvanced: connectAdvanced
};
return lib;
return lib$1;
})));
//# sourceMappingURL=preact-redux.js.map

@@ -1,2 +0,2 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("preact"),require("redux")):"function"==typeof define&&define.amd?define(["preact","redux"],e):t.preactRedux=e(t.preact,t.redux)}(this,function(t,e){function r(){}function n(t,e){if(t===e)return!0;var r=Object.keys(t);if(r.length!==Object.keys(e).length)return!1;for(var n=Object.prototype.hasOwnProperty,o=0;o<r.length;o++)if(!n.call(e,r[o])||t[r[o]]!==e[r[o]])return!1;return!0}function o(t){return function(r){return e.bindActionCreators(t,r)}}function s(t,e){return function(r){return t(e(r))}}function i(t){return t&&"object"==typeof t&&"default"in t?t.default:t}function p(t,e){return e={exports:{}},t(e,e.exports),e.exports}function a(t){return t.displayName||t.name||"Component"}function u(t,e){try{return t.apply(e)}catch(t){return D.value=t,D}}function c(e,r,s){var i=arguments.length<=3||void 0===arguments[3]?{}:arguments[3],p=!!e,c=e||m,h=void 0;h="function"==typeof r?r:r?o(r):C;var f=s||w,b=i.pure,g=void 0===b||b,v=i.withRef,S=void 0!==v&&v,j=g&&f!==w,T=M++;return function(e){function r(t,e,r){return f(t,e,r)}var o="Connect("+a(e)+")",s=function(o){function s(t,e){var r=y(this,o.call(this,t,e));return r.version=T,r.store=t.store||e.store,r.state={storeState:r.store.getState()},r.clearCache(),r}return P(s,o),s.prototype.shouldComponentUpdate=function(){return!g||this.haveOwnPropsChanged||this.hasStoreStateChanged},s.prototype.computeStateProps=function(t,e){if(!this.finalMapStateToProps)return this.configureFinalMapState(t,e);var r=t.getState();return this.doStatePropsDependOnOwnProps?this.finalMapStateToProps(r,e):this.finalMapStateToProps(r)},s.prototype.configureFinalMapState=function(t,e){var r=c(t.getState(),e),n="function"==typeof r;return this.finalMapStateToProps=n?r:c,this.doStatePropsDependOnOwnProps=1!==this.finalMapStateToProps.length,n?this.computeStateProps(t,e):r},s.prototype.computeDispatchProps=function(t,e){if(!this.finalMapDispatchToProps)return this.configureFinalMapDispatch(t,e);var r=t.dispatch;return this.doDispatchPropsDependOnOwnProps?this.finalMapDispatchToProps(r,e):this.finalMapDispatchToProps(r)},s.prototype.configureFinalMapDispatch=function(t,e){var r=h(t.dispatch,e),n="function"==typeof r;return this.finalMapDispatchToProps=n?r:h,this.doDispatchPropsDependOnOwnProps=1!==this.finalMapDispatchToProps.length,n?this.computeDispatchProps(t,e):r},s.prototype.updateStatePropsIfNeeded=function(){var t=this.computeStateProps(this.store,this.props);return(!this.stateProps||!n(t,this.stateProps))&&(this.stateProps=t,!0)},s.prototype.updateDispatchPropsIfNeeded=function(){var t=this.computeDispatchProps(this.store,this.props);return(!this.dispatchProps||!n(t,this.dispatchProps))&&(this.dispatchProps=t,!0)},s.prototype.updateMergedPropsIfNeeded=function(){var t=r(this.stateProps,this.dispatchProps,this.props);return!(this.mergedProps&&j&&n(t,this.mergedProps))&&(this.mergedProps=t,!0)},s.prototype.isSubscribed=function(){return"function"==typeof this.unsubscribe},s.prototype.trySubscribe=function(){p&&!this.unsubscribe&&(this.unsubscribe=this.store.subscribe(this.handleChange.bind(this)),this.handleChange())},s.prototype.tryUnsubscribe=function(){this.unsubscribe&&(this.unsubscribe(),this.unsubscribe=null)},s.prototype.componentDidMount=function(){this.trySubscribe()},s.prototype.componentWillReceiveProps=function(t){g&&n(t,this.props)||(this.haveOwnPropsChanged=!0)},s.prototype.componentWillUnmount=function(){this.tryUnsubscribe(),this.clearCache()},s.prototype.clearCache=function(){this.dispatchProps=null,this.stateProps=null,this.mergedProps=null,this.haveOwnPropsChanged=!0,this.hasStoreStateChanged=!0,this.haveStatePropsBeenPrecalculated=!1,this.statePropsPrecalculationError=null,this.renderedElement=null,this.finalMapDispatchToProps=null,this.finalMapStateToProps=null},s.prototype.handleChange=function(){if(this.unsubscribe){var t=this.store.getState(),e=this.state.storeState;if(!g||e!==t){if(g&&!this.doStatePropsDependOnOwnProps){var r=u(this.updateStatePropsIfNeeded,this);if(!r)return;r===D&&(this.statePropsPrecalculationError=D.value),this.haveStatePropsBeenPrecalculated=!0}this.hasStoreStateChanged=!0,this.setState({storeState:t})}}},s.prototype.getWrappedInstance=function(){return this.refs.wrappedInstance},s.prototype.render=function(){var r=this.haveOwnPropsChanged,n=this.hasStoreStateChanged,o=this.haveStatePropsBeenPrecalculated,s=this.statePropsPrecalculationError,i=this.renderedElement;if(this.haveOwnPropsChanged=!1,this.hasStoreStateChanged=!1,this.haveStatePropsBeenPrecalculated=!1,this.statePropsPrecalculationError=null,s)throw s;var p=!0,a=!0;g&&i&&(p=n||r&&this.doStatePropsDependOnOwnProps,a=r&&this.doDispatchPropsDependOnOwnProps);var u=!1,c=!1;o?u=!0:p&&(u=this.updateStatePropsIfNeeded()),a&&(c=this.updateDispatchPropsIfNeeded());var h=!0;return h=!!(u||c||r)&&this.updateMergedPropsIfNeeded(),!h&&i?i:this.renderedElement=S?t.h(e,d({},this.mergedProps,{ref:"wrappedInstance"})):t.h(e,this.mergedProps)},s}(t.Component);return s.displayName=o,s.WrappedComponent=e,s.contextTypes={store:l},O(s,e)}}var h={only:function(t){return t&&t[0]||null}};r.isRequired=r;var f={element:r,func:r,shape:function(){return r}},l=f.shape({subscribe:f.func.isRequired,dispatch:f.func.isRequired,getState:f.func.isRequired}),d=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},P=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},y=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e},b=function(t){function e(e,r){var n=y(this,t.call(this,e,r));return n.store=e.store,n}return P(e,t),e.prototype.getChildContext=function(){return{store:this.store}},e.prototype.render=function(){return h.only(this.props.children)},e}(t.Component);b.childContextTypes={store:l.isRequired};var g=(s(Object.getPrototypeOf,Object),Function.prototype),v=(Object.prototype,g.toString),S=(v.call(Object),p(function(t){"use strict";var e={childContextTypes:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDefaultProps:!0,mixins:!0,propTypes:!0,type:!0},r={name:!0,length:!0,prototype:!0,caller:!0,arguments:!0,arity:!0},n="function"==typeof Object.getOwnPropertySymbols;t.exports=function(t,o,s){if("string"!=typeof o){var i=Object.getOwnPropertyNames(o);n&&(i=i.concat(Object.getOwnPropertySymbols(o)));for(var p=0;p<i.length;++p)if(!(e[i[p]]||r[i[p]]||s&&s[i[p]]))try{t[i[p]]=o[i[p]]}catch(t){}}return t}})),O=i(S),m=function(){return{}},C=function(t){return{dispatch:t}},w=function(t,e,r){return d({},r,t,e)},D={value:null},M=0;return{Provider:b,connect:c}});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("preact"),require("redux")):"function"==typeof define&&define.amd?define(["preact","redux"],e):t.preactRedux=e(t.preact,t.redux)}(this,function(t,e){function n(){}function r(){var t=[],e=[];return{clear:function(){e=D,t=D},notify:function(){for(var n=t=e,r=0;r<n.length;r++)n[r]()},subscribe:function(n){var r=!0;return e===t&&(e=t.slice()),e.push(n),function(){r&&t!==D&&(r=!1,e===t&&(e=t.slice()),e.splice(e.indexOf(n),1))}}}}function o(e){var n,r,o=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],i=o.getDisplayName,s=void 0===i?function(t){return"ConnectAdvanced("+t+")"}:i,u=o.methodName,p=void 0===u?"connectAdvanced":u,a=o.renderCountProp,c=void 0===a?void 0:a,d=o.shouldHandleStateChanges,f=void 0===d||d,l=o.storeKey,h=void 0===l?"store":l,y=o.withRef,b=void 0!==y&&y,v=x(o,["getDisplayName","methodName","renderCountProp","shouldHandleStateChanges","storeKey","withRef"]),m=h+"Subscription",P=_++,S=(n={},n[h]=R,n[m]=T.instanceOf(U),n),O=(r={},r[m]=T.instanceOf(U),r);return function(n){var r=n.displayName||n.name||"Component",o=s(r),i=E({},v,{getDisplayName:s,methodName:p,renderCountProp:c,shouldHandleStateChanges:f,storeKey:h,withRef:b,displayName:o,wrappedComponentName:r,WrappedComponent:n}),u=function(r){function o(t,e){var n=j(this,r.call(this,t,e));return n.version=P,n.state={},n.renderCount=0,n.store=n.props[h]||n.context[h],n.parentSub=t[m]||e[m],n.setWrappedInstance=n.setWrappedInstance.bind(n),n.getState=n.store.getState.bind(n.store),n.initSelector(),n.initSubscription(),n}return N(o,r),o.prototype.getChildContext=function(){var t;return t={},t[m]=this.subscription||this.parentSub,t},o.prototype.componentDidMount=function(){f&&(this.subscription.trySubscribe(),this.selector.run(this.props),this.selector.shouldComponentUpdate&&this.forceUpdate())},o.prototype.componentWillReceiveProps=function(t){this.selector.run(t)},o.prototype.shouldComponentUpdate=function(){return this.selector.shouldComponentUpdate},o.prototype.componentWillUnmount=function(){this.subscription&&this.subscription.tryUnsubscribe(),this.subscription=null,this.store=null,this.parentSub=null,this.selector.run=function(){}},o.prototype.getWrappedInstance=function(){return this.wrappedInstance},o.prototype.setWrappedInstance=function(t){this.wrappedInstance=t},o.prototype.initSelector=function(){var t=this.store.dispatch,n=this.getState,r=e(t,i),o=this.selector={shouldComponentUpdate:!0,props:r(n(),this.props),run:function(t){try{var e=r(n(),t);(o.error||e!==o.props)&&(o.shouldComponentUpdate=!0,o.props=e,o.error=null)}catch(t){o.shouldComponentUpdate=!0,o.error=t}}}},o.prototype.initSubscription=function(){var t=this;f&&!function(){var e=t.subscription=new U(t.store,t.parentSub),n={};e.onStateChange=function(){this.selector.run(this.props),this.selector.shouldComponentUpdate?(this.componentDidUpdate=function(){this.componentDidUpdate=void 0,e.notifyNestedSubs()},this.setState(n)):e.notifyNestedSubs()}.bind(t)}()},o.prototype.isSubscribed=function(){return!!this.subscription&&this.subscription.isSubscribed()},o.prototype.addExtraProps=function(t){if(!b&&!c)return t;var e=E({},t);return b&&(e.ref=this.setWrappedInstance),c&&(e[c]=this.renderCount++),e},o.prototype.render=function(){var e=this.selector;if(e.shouldComponentUpdate=!1,e.error)throw e.error;return t.h(n,this.addExtraProps(e.props))},o}(t.Component);return u.WrappedComponent=n,u.displayName=o,u.childContextTypes=O,u.contextTypes=S,A(u,n)}}function i(t,e){if(t===e)return!0;var n=0,r=0;for(var o in t){if(K.call(t,o)&&t[o]!==e[o])return!1;n++}for(var i in e)K.call(e,i)&&r++;return n===r}function s(t){return function(e,n){function r(){return o}var o=t(e,n);return r.dependsOnOwnProps=!1,r}}function u(t){return null!==t.dependsOnOwnProps&&void 0!==t.dependsOnOwnProps?!!t.dependsOnOwnProps:1!==t.length}function p(t){return function(e,n){var r=function(t,e){return r.dependsOnOwnProps?r.mapToProps(t,e):r.mapToProps(t)};return r.dependsOnOwnProps=u(t),r.mapToProps=function(e,n){r.mapToProps=t;var o=r(e,n);return"function"==typeof o&&(r.mapToProps=o,r.dependsOnOwnProps=u(o),o=r(e,n)),o},r}}function a(t){return"function"==typeof t?p(t,"mapDispatchToProps"):void 0}function c(t){return t?void 0:s(function(t){return{dispatch:t}})}function d(t){return t&&"object"===(void 0===t?"undefined":q(t))?s(function(n){return e.bindActionCreators(t,n)}):void 0}function f(t){return"function"==typeof t?p(t,"mapStateToProps"):void 0}function l(t){return t?void 0:s(function(){return{}})}function h(t,e,n){return E({},n,t,e)}function y(t){return function(e,n){var r=n.pure,o=n.areMergedPropsEqual,i=!1,s=void 0;return function(e,n,u){var p=t(e,n,u);return i?r&&o(p,s)||(s=p):(i=!0,s=p),s}}}function b(t){return"function"==typeof t?y(t):void 0}function v(t){return t?void 0:function(){return h}}function m(t,e,n,r){return function(o,i){return n(t(o,i),e(r,i),i)}}function P(t,e,n,r,o){function i(o,i){return h=o,y=i,b=t(h,y),v=e(r,y),m=n(b,v,y),l=!0,m}function s(){return b=t(h,y),e.dependsOnOwnProps&&(v=e(r,y)),m=n(b,v,y)}function u(){return t.dependsOnOwnProps&&(b=t(h,y)),e.dependsOnOwnProps&&(v=e(r,y)),m=n(b,v,y)}function p(){var e=t(h,y),r=!f(e,b);return b=e,r&&(m=n(b,v,y)),m}function a(t,e){var n=!d(e,y),r=!c(t,h);return h=t,y=e,n&&r?s():n?u():r?p():m}var c=o.areStatesEqual,d=o.areOwnPropsEqual,f=o.areStatePropsEqual,l=!1,h=void 0,y=void 0,b=void 0,v=void 0,m=void 0;return function(t,e){return l?a(t,e):i(t,e)}}function S(t,e){var n=e.initMapStateToProps,r=e.initMapDispatchToProps,o=e.initMergeProps,i=x(e,["initMapStateToProps","initMapDispatchToProps","initMergeProps"]),s=n(t,i),u=r(t,i),p=o(t,i);return(i.pure?P:m)(s,u,p,t,i)}function O(t,e,n){for(var r=e.length-1;r>=0;r--){var o=e[r](t);if(o)return o}return function(e,r){throw Error("Invalid value of type "+(void 0===t?"undefined":q(t))+" for "+n+" argument when connecting component "+r.wrappedComponentName+".")}}function g(t,e){return t===e}function C(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e=t.connectHOC,n=void 0===e?o:e,r=t.mapStateToPropsFactories,s=void 0===r?B:r,u=t.mapDispatchToPropsFactories,p=void 0===u?z:u,a=t.mergePropsFactories,c=void 0===a?G:a,d=t.selectorFactory,f=void 0===d?S:d;return function(t,e,r){var o=arguments.length<=3||void 0===arguments[3]?{}:arguments[3],u=o.pure,a=void 0===u||u,d=o.areStatesEqual,l=void 0===d?g:d,h=o.areOwnPropsEqual,y=void 0===h?i:h,b=o.areStatePropsEqual,v=void 0===b?i:b,m=o.areMergedPropsEqual,P=void 0===m?i:m,S=x(o,["pure","areStatesEqual","areOwnPropsEqual","areStatePropsEqual","areMergedPropsEqual"]),C=O(t,s,"mapStateToProps"),w=O(e,p,"mapDispatchToProps"),T=O(r,c,"mergeProps");return n(f,E({methodName:"connect",getDisplayName:function(t){return"Connect("+t+")"},shouldHandleStateChanges:!!t,initMapStateToProps:C,initMapDispatchToProps:w,initMergeProps:T,pure:a,areStatesEqual:l,areOwnPropsEqual:y,areStatePropsEqual:v,areMergedPropsEqual:P},S))}}var w={only:function(t){return t&&t[0]||null}};n.isRequired=n;var T={element:n,func:n,shape:function(){return n},instanceOf:function(){return n}},q="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},E=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},N=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},x=function(t,e){var n={};for(var r in t)e.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r]);return n},j=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e},D=null,M={notify:function(){}},U=function(){function t(t,e){this.store=t,this.parentSub=e,this.unsubscribe=null,this.listeners=M}return t.prototype.addNestedSub=function(t){return this.trySubscribe(),this.listeners.subscribe(t)},t.prototype.notifyNestedSubs=function(){this.listeners.notify()},t.prototype.isSubscribed=function(){return!!this.unsubscribe},t.prototype.trySubscribe=function(){this.unsubscribe||(this.unsubscribe=this.parentSub?this.parentSub.addNestedSub(this.onStateChange):this.store.subscribe(this.onStateChange),this.listeners=r())},t.prototype.tryUnsubscribe=function(){this.unsubscribe&&(this.unsubscribe(),this.unsubscribe=null,this.listeners.clear(),this.listeners=M)},t}(),R=T.shape({subscribe:T.func.isRequired,dispatch:T.func.isRequired,getState:T.func.isRequired}),W=function(t){function e(e,n){var r=j(this,t.call(this,e,n));return r.store=e.store,r}return N(e,t),e.prototype.getChildContext=function(){return{store:this.store,storeSubscription:null}},e.prototype.render=function(){return w.only(this.props.children)},e}(t.Component);W.childContextTypes={store:R.isRequired,storeSubscription:T.instanceOf(U)},W.displayName="Provider";var I={childContextTypes:!0,contextTypes:!0,defaultProps:!0,displayName:!0,getDefaultProps:!0,mixins:!0,propTypes:!0,type:!0},F={name:!0,length:!0,prototype:!0,caller:!0,arguments:!0,arity:!0},H="function"==typeof Object.getOwnPropertySymbols,A=function(t,e,n){if("string"!=typeof e){var r=Object.getOwnPropertyNames(e);H&&(r=r.concat(Object.getOwnPropertySymbols(e)));for(var o=0;o<r.length;++o)if(!(I[r[o]]||F[r[o]]||n&&n[r[o]]))try{t[r[o]]=e[r[o]]}catch(t){}}return t},_=0,K=Object.prototype.hasOwnProperty,k=(Object.getPrototypeOf,Object.prototype,Function.prototype.toString),z=(k.call(Object),[a,c,d]),B=[f,l],G=[b,v];return{Provider:W,connect:C(),connectAdvanced:o}});
//# sourceMappingURL=preact-redux.min.js.map
{
"name": "preact-redux",
"amdName": "preactRedux",
"version": "1.2.0",
"version": "2.0.0",
"description": "Wraps react-redux up for Preact, without preact-compat",
"main": "dist/preact-redux.js",
"jsnext:main": "dist/preact-redux.esm.js",
"src:main": "src/index.js",

@@ -12,3 +13,3 @@ "minified:main": "dist/preact-redux.min.js",

"build": "NODE_ENV=production npm-run-all clean transpile minify size",
"transpile": "rollup -c rollup.config.js -m ${npm_package_main}.map -f umd -n $npm_package_amdName $npm_package_src_main -o $npm_package_main",
"transpile": "rollup -c rollup.config.js -m ${npm_package_main}.map -f umd -n $npm_package_amdName $npm_package_src_main",
"minify": "uglifyjs $npm_package_main --define NODE_ENV=production --pure-funcs classCallCheck Object.defineProperty Object.freeze invariant warning -c unsafe,collapse_vars,evaluate,screw_ie8,loops,keep_fargs=false,pure_getters,unused,dead_code -m -o $npm_package_minified_main -p relative --in-source-map ${npm_package_main}.map --source-map ${npm_package_minified_main}.map",

@@ -44,5 +45,6 @@ "size": "size=$(gzip-size $npm_package_minified_main) && echo \"gzip size: $size / $(pretty-bytes $size)\"",

"babel-core": "^6.14.0",
"babel-eslint": "^6.0.4",
"babel-eslint": "^6.1.2",
"babel-loader": "^6.2.5",
"babel-plugin-transform-class-properties": "^6.9.1",
"babel-plugin-external-helpers": "^6.8.0",
"babel-plugin-transform-class-properties": "^6.11.5",
"babel-plugin-transform-es2015-classes": "^6.14.0",

@@ -52,7 +54,5 @@ "babel-plugin-transform-node-env-inline": "^6.8.0",

"babel-plugin-transform-react-jsx": "^6.8.0",
"babel-plugin-transform-react-remove-prop-types": "^0.2.7",
"babel-plugin-transform-react-remove-prop-types": "^0.2.9",
"babel-preset-es2015": "^6.14.0",
"babel-preset-es2015-minimal": "^2.0.0",
"babel-preset-es2015-minimal-rollup": "^2.0.0",
"babel-preset-react": "^6.5.0",
"babel-preset-react": "^6.11.1",
"babel-preset-stage-0": "^6.5.0",

@@ -66,20 +66,20 @@ "chai": "^3.5.0",

"karma-chai-sinon": "^0.1.5",
"karma-mocha": "^1.0.1",
"karma-mocha-reporter": "^2.0.3",
"karma-phantomjs-launcher": "^1.0.0",
"karma-mocha": "^1.1.1",
"karma-mocha-reporter": "^2.2.0",
"karma-phantomjs-launcher": "^1.0.2",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^1.7.0",
"karma-webpack": "^1.8.0",
"mkdirp": "^0.5.1",
"mocha": "^3.0.2",
"npm-run-all": "^3.0.0",
"phantomjs-prebuilt": "^2.1.7",
"preact": "^5.7.0",
"pretty-bytes-cli": "^1.0.0",
"react-redux": "^4.4.5",
"redux": "^3.5.2",
"rimraf": "^2.5.1",
"rollup": "^0.34.10",
"phantomjs-prebuilt": "^2.1.12",
"preact": "^6.0.2",
"pretty-bytes-cli": "^2.0.0",
"react-redux": "^5.0.0",
"redux": "^3.6.0",
"rimraf": "^2.5.4",
"rollup": "^0.36.0",
"rollup-plugin-alias": "^1.2.0",
"rollup-plugin-babel": "^2.4.0",
"rollup-plugin-commonjs": "^3.3.1",
"rollup-plugin-babel": "^2.6.1",
"rollup-plugin-commonjs": "^5.0.4",
"rollup-plugin-es3": "^1.0.3",

@@ -89,3 +89,3 @@ "rollup-plugin-memory": "^2.0.0",

"rollup-plugin-replace": "^1.1.1",
"sinon": "^1.17.4",
"sinon": "^1.17.6",
"sinon-chai": "^2.8.0",

@@ -92,0 +92,0 @@ "uglify-js": "^2.7.3",

@@ -10,5 +10,8 @@ import fs from 'fs';

var babelRc = JSON.parse(fs.readFileSync('.babelrc','utf8'));
const babelRc = JSON.parse(fs.readFileSync('.babelrc','utf8'));
const packageJson = require('./package.json');
var external = [
babelRc.plugins.push('external-helpers');
const external = [
'redux',

@@ -22,2 +25,19 @@ 'preact'

useStrict: false,
globals: {
preact: 'preact',
redux: 'redux'
},
targets: [
{
dest: packageJson['main'],
format: 'umd',
moduleName: 'preactRedux',
sourceMap: true
},
{
dest: packageJson['jsnext:main'],
format: 'es',
sourceMap: true
}
],
plugins: [

@@ -55,3 +75,8 @@ memory({

babelrc: false,
presets: ['es2015-minimal-rollup'].concat(babelRc.presets.slice(1)),
presets: [
['es2015', {
loose: true,
modules: false
}]
].concat(babelRc.presets.slice(1)),
plugins: babelRc.plugins

@@ -58,0 +83,0 @@ }),

@@ -15,3 +15,4 @@ export { Component, h as createElement } from 'preact';

func: proptype,
shape: () => proptype
shape: () => proptype,
instanceOf: ()=> proptype
};

@@ -1,1 +0,1 @@

export { Provider, connect } from 'react-redux';
export { Provider, connect, connectAdvanced } from 'react-redux';
import { createStore } from 'redux';
import { Provider, connect } from '../';
import { Provider, connect, connectAdvanced } from '../';
import { h, render, options } from 'preact';
import Redux from '../dist/preact-redux.esm.js';
// disable async rendering entirely to make tests simpler

@@ -92,2 +94,100 @@ options.debounceRendering = f => f();

});
describe('connectAdvanced()', () => {
it('should connectAdvanced component to store', () => {
let initialState = {
a: 'a',
b: 'b'
};
let reducer = (state=initialState, action) => {
switch (action.type) {
case 'A': return { ...state, a: action.data };
case 'B': return { ...state, b: action.data };
default: return state;
}
};
let store = createStore(reducer);
let Child = sinon.stub().returns(<div />);
let spies = {};
function shallowDiffers (a, b) {
for (let i in a) if (!(i in b)) return true;
for (let i in b) if (a[i] !== b[i]) return true;
return false;
}
let ConnectedChild = connectAdvanced((dispatch) => {
/**
* from https://github.com/reactjs/react-redux/blob/master/docs/api.md
* If a consecutive call to selector returns the same object (===) as its previous call,
* the component will not be re-rendered.
* It's the responsibility of selector to return that previous object when appropriate.
*/
let result = {};
const onA = spies.onA = sinon.spy(data => dispatch({type: 'A', data}));
const onB = spies.onB = sinon.spy(data => dispatch({type: 'B', data}));
return ({a, b}, {c}) => {
const nextResult = {
a,
b,
c,
onA,
onB
};
if (shallowDiffers(result, nextResult)) {
result = nextResult;
}
return result;
};
})(Child);
render((
<Provider store={store}>
<ConnectedChild c="c" />
</Provider>
), document.createElement('div'));
expect(Child).to.have.been.calledOnce.and.calledWithMatch({
a: 'a',
b: 'b',
c: 'c',
onA: spies.onA,
onB: spies.onB
});
Child.reset();
spies.onA('aaa');
expect(Child).to.have.been.calledOnce.and.calledWithMatch({
a: 'aaa',
b: 'b',
c: 'c',
onA: spies.onA,
onB: spies.onB
});
Child.reset();
spies.onB('bbb');
expect(Child).to.have.been.calledOnce.and.calledWithMatch({
a: 'aaa',
b: 'bbb',
c: 'c',
onA: spies.onA,
onB: spies.onB
});
});
});
describe('jsnext:main', () => {
it('should export the correct interface', () => {
expect(Redux.Provider).to.be.a('function');
expect(Redux.connect).to.be.a('function');
expect(Redux.connectAdvanced).to.be.a('function');
});
});
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet