mini-create-react-context
Advanced tools
Comparing version 0.3.0 to 0.3.2
@@ -1,31 +0,3 @@ | ||
'use strict';function _interopDefault(e){return(e&&(typeof e==='object')&&'default'in e)?e['default']:e}var React=require('react'),React__default=_interopDefault(React),PropTypes=_interopDefault(require('prop-types')),gud=_interopDefault(require('gud')),warning=_interopDefault(require('tiny-warning'));function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
'use strict';function _interopDefault(e){return(e&&(typeof e==='object')&&'default'in e)?e['default']:e}var React=require('react'),React__default=_interopDefault(React),_inheritsLoose=_interopDefault(require('@babel/runtime/helpers/inheritsLoose')),PropTypes=_interopDefault(require('prop-types')),gud=_interopDefault(require('gud')),warning=_interopDefault(require('tiny-warning'));var MAX_SIGNED_31_BIT_INT = 1073741823; | ||
return obj; | ||
} | ||
function _inheritsLoose(subClass, superClass) { | ||
subClass.prototype = Object.create(superClass.prototype); | ||
subClass.prototype.constructor = subClass; | ||
subClass.__proto__ = superClass; | ||
} | ||
function _assertThisInitialized(self) { | ||
if (self === void 0) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
return self; | ||
}var MAX_SIGNED_31_BIT_INT = 1073741823; // Inlined Object.is polyfill. | ||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is | ||
function objectIs(x, y) { | ||
@@ -67,3 +39,3 @@ if (x === y) { | ||
function createReactContext(defaultValue, calculateChangedBits) { | ||
var _defineProperty2, _defineProperty3; | ||
var _Provider$childContex, _Consumer$contextType; | ||
@@ -80,10 +52,4 @@ var contextProp = '__create-react-context-' + gud() + '__'; | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_this = _Component.call.apply(_Component, [this].concat(args)) || this; | ||
_defineProperty(_assertThisInitialized(_this), "emitter", createEventEmitter(_this.props.value)); | ||
_this = _Component.apply(this, arguments) || this; | ||
_this.emitter = createEventEmitter(_this.props.value); | ||
return _this; | ||
@@ -107,3 +73,3 @@ } | ||
if (objectIs(oldValue, newValue)) { | ||
changedBits = 0; // No change | ||
changedBits = 0; | ||
} else { | ||
@@ -132,3 +98,3 @@ changedBits = typeof calculateChangedBits === 'function' ? calculateChangedBits(oldValue, newValue) : MAX_SIGNED_31_BIT_INT; | ||
_defineProperty(Provider, "childContextTypes", (_defineProperty2 = {}, _defineProperty2[contextProp] = PropTypes.object.isRequired, _defineProperty2)); | ||
Provider.childContextTypes = (_Provider$childContex = {}, _Provider$childContex[contextProp] = PropTypes.object.isRequired, _Provider$childContex); | ||
@@ -143,15 +109,8 @@ var Consumer = | ||
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
_this2 = _Component2.call.apply(_Component2, [this].concat(args)) || this; | ||
_defineProperty(_assertThisInitialized(_this2), "observedBits", void 0); | ||
_defineProperty(_assertThisInitialized(_this2), "state", { | ||
_this2 = _Component2.apply(this, arguments) || this; | ||
_this2.state = { | ||
value: _this2.getValue() | ||
}); | ||
}; | ||
_defineProperty(_assertThisInitialized(_this2), "onUpdate", function (newValue, changedBits) { | ||
_this2.onUpdate = function (newValue, changedBits) { | ||
var observedBits = _this2.observedBits | 0; | ||
@@ -164,3 +123,3 @@ | ||
} | ||
}); | ||
}; | ||
@@ -174,4 +133,3 @@ return _this2; | ||
var observedBits = nextProps.observedBits; | ||
this.observedBits = observedBits === undefined || observedBits === null ? MAX_SIGNED_31_BIT_INT // Subscribe to all changes by default | ||
: observedBits; | ||
this.observedBits = observedBits === undefined || observedBits === null ? MAX_SIGNED_31_BIT_INT : observedBits; | ||
}; | ||
@@ -185,4 +143,3 @@ | ||
var observedBits = this.props.observedBits; | ||
this.observedBits = observedBits === undefined || observedBits === null ? MAX_SIGNED_31_BIT_INT // Subscribe to all changes by default | ||
: observedBits; | ||
this.observedBits = observedBits === undefined || observedBits === null ? MAX_SIGNED_31_BIT_INT : observedBits; | ||
}; | ||
@@ -211,4 +168,3 @@ | ||
_defineProperty(Consumer, "contextTypes", (_defineProperty3 = {}, _defineProperty3[contextProp] = PropTypes.object, _defineProperty3)); | ||
Consumer.contextTypes = (_Consumer$contextType = {}, _Consumer$contextType[contextProp] = PropTypes.object, _Consumer$contextType); | ||
return { | ||
@@ -215,0 +171,0 @@ Provider: Provider, |
@@ -1,1 +0,1 @@ | ||
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var React=require("react"),React__default=_interopDefault(React),PropTypes=_interopDefault(require("prop-types")),gud=_interopDefault(require("gud")),warning=_interopDefault(require("tiny-warning"));function _defineProperty(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function _inheritsLoose(e,t){e.prototype=Object.create(t.prototype),(e.prototype.constructor=e).__proto__=t}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}var MAX_SIGNED_31_BIT_INT=1073741823;function objectIs(e,t){return e===t?0!==e||1/e==1/t:e!=e&&t!=t}function createEventEmitter(n){var r=[];return{on:function(e){r.push(e)},off:function(t){r=r.filter(function(e){return e!==t})},get:function(){return n},set:function(e,t){n=e,r.forEach(function(e){return e(n,t)})}}}function onlyChild(e){return Array.isArray(e)?e[0]:e}function createReactContext(n,o){var e,t,r="__create-react-context-"+gud()+"__",i=function(i){function e(){for(var e,t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];return _defineProperty(_assertThisInitialized(e=i.call.apply(i,[this].concat(n))||this),"emitter",createEventEmitter(e.props.value)),e}_inheritsLoose(e,i);var t=e.prototype;return t.getChildContext=function(){var e;return(e={})[r]=this.emitter,e},t.componentWillReceiveProps=function(e){if(this.props.value!==e.value){var t,n=this.props.value,r=e.value;objectIs(n,r)?t=0:(t="function"==typeof o?o(n,r):MAX_SIGNED_31_BIT_INT,"production"!==process.env.NODE_ENV&&warning((t&MAX_SIGNED_31_BIT_INT)===t,"calculateChangedBits: Expected the return value to be a 31-bit integer. Instead received: "+t),0!==(t|=0)&&this.emitter.set(e.value,t))}},t.render=function(){return this.props.children},e}(React.Component);_defineProperty(i,"childContextTypes",((e={})[r]=PropTypes.object.isRequired,e));var a=function(i){function e(){for(var n,e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return _defineProperty(_assertThisInitialized(n=i.call.apply(i,[this].concat(t))||this),"observedBits",void 0),_defineProperty(_assertThisInitialized(n),"state",{value:n.getValue()}),_defineProperty(_assertThisInitialized(n),"onUpdate",function(e,t){0!=((0|n.observedBits)&t)&&n.setState({value:n.getValue()})}),n}_inheritsLoose(e,i);var t=e.prototype;return t.componentWillReceiveProps=function(e){var t=e.observedBits;this.observedBits=null==t?MAX_SIGNED_31_BIT_INT:t},t.componentDidMount=function(){this.context[r]&&this.context[r].on(this.onUpdate);var e=this.props.observedBits;this.observedBits=null==e?MAX_SIGNED_31_BIT_INT:e},t.componentWillUnmount=function(){this.context[r]&&this.context[r].off(this.onUpdate)},t.getValue=function(){return this.context[r]?this.context[r].get():n},t.render=function(){return onlyChild(this.props.children)(this.state.value)},e}(React.Component);return _defineProperty(a,"contextTypes",((t={})[r]=PropTypes.object,t)),{Provider:i,Consumer:a}}var index=React__default.createContext||createReactContext;module.exports=index; | ||
"use strict";function _interopDefault(t){return t&&"object"==typeof t&&"default"in t?t.default:t}var React=require("react"),React__default=_interopDefault(React),_inheritsLoose=_interopDefault(require("@babel/runtime/helpers/inheritsLoose")),PropTypes=_interopDefault(require("prop-types")),gud=_interopDefault(require("gud")),warning=_interopDefault(require("tiny-warning")),MAX_SIGNED_31_BIT_INT=1073741823;function objectIs(t,e){return t===e?0!==t||1/t==1/e:t!=t&&e!=e}function createEventEmitter(n){var r=[];return{on:function(t){r.push(t)},off:function(e){r=r.filter(function(t){return t!==e})},get:function(){return n},set:function(t,e){n=t,r.forEach(function(t){return t(n,e)})}}}function onlyChild(t){return Array.isArray(t)?t[0]:t}function createReactContext(r,o){var t,e,i="__create-react-context-"+gud()+"__",n=function(e){function t(){var t;return(t=e.apply(this,arguments)||this).emitter=createEventEmitter(t.props.value),t}_inheritsLoose(t,e);var n=t.prototype;return n.getChildContext=function(){var t;return(t={})[i]=this.emitter,t},n.componentWillReceiveProps=function(t){if(this.props.value!==t.value){var e,n=this.props.value,r=t.value;objectIs(n,r)?e=0:(e="function"==typeof o?o(n,r):MAX_SIGNED_31_BIT_INT,"production"!==process.env.NODE_ENV&&warning((e&MAX_SIGNED_31_BIT_INT)===e,"calculateChangedBits: Expected the return value to be a 31-bit integer. Instead received: "+e),0!==(e|=0)&&this.emitter.set(t.value,e))}},n.render=function(){return this.props.children},t}(React.Component);n.childContextTypes=((t={})[i]=PropTypes.object.isRequired,t);var u=function(t){function e(){var n;return(n=t.apply(this,arguments)||this).state={value:n.getValue()},n.onUpdate=function(t,e){0!=((0|n.observedBits)&e)&&n.setState({value:n.getValue()})},n}_inheritsLoose(e,t);var n=e.prototype;return n.componentWillReceiveProps=function(t){var e=t.observedBits;this.observedBits=null==e?MAX_SIGNED_31_BIT_INT:e},n.componentDidMount=function(){this.context[i]&&this.context[i].on(this.onUpdate);var t=this.props.observedBits;this.observedBits=null==t?MAX_SIGNED_31_BIT_INT:t},n.componentWillUnmount=function(){this.context[i]&&this.context[i].off(this.onUpdate)},n.getValue=function(){return this.context[i]?this.context[i].get():r},n.render=function(){return onlyChild(this.props.children)(this.state.value)},e}(React.Component);return u.contextTypes=((e={})[i]=PropTypes.object,e),{Provider:n,Consumer:u}}var index=React__default.createContext||createReactContext;module.exports=index; |
import React, { Component } from 'react'; | ||
import _inheritsLoose from '@babel/runtime/helpers/inheritsLoose'; | ||
import PropTypes from 'prop-types'; | ||
@@ -6,34 +7,4 @@ import gud from 'gud'; | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
var MAX_SIGNED_31_BIT_INT = 1073741823; | ||
return obj; | ||
} | ||
function _inheritsLoose(subClass, superClass) { | ||
subClass.prototype = Object.create(superClass.prototype); | ||
subClass.prototype.constructor = subClass; | ||
subClass.__proto__ = superClass; | ||
} | ||
function _assertThisInitialized(self) { | ||
if (self === void 0) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
return self; | ||
} | ||
var MAX_SIGNED_31_BIT_INT = 1073741823; // Inlined Object.is polyfill. | ||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is | ||
function objectIs(x, y) { | ||
@@ -75,3 +46,3 @@ if (x === y) { | ||
function createReactContext(defaultValue, calculateChangedBits) { | ||
var _defineProperty2, _defineProperty3; | ||
var _Provider$childContex, _Consumer$contextType; | ||
@@ -88,10 +59,4 @@ var contextProp = '__create-react-context-' + gud() + '__'; | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_this = _Component.call.apply(_Component, [this].concat(args)) || this; | ||
_defineProperty(_assertThisInitialized(_this), "emitter", createEventEmitter(_this.props.value)); | ||
_this = _Component.apply(this, arguments) || this; | ||
_this.emitter = createEventEmitter(_this.props.value); | ||
return _this; | ||
@@ -115,3 +80,3 @@ } | ||
if (objectIs(oldValue, newValue)) { | ||
changedBits = 0; // No change | ||
changedBits = 0; | ||
} else { | ||
@@ -140,3 +105,3 @@ changedBits = typeof calculateChangedBits === 'function' ? calculateChangedBits(oldValue, newValue) : MAX_SIGNED_31_BIT_INT; | ||
_defineProperty(Provider, "childContextTypes", (_defineProperty2 = {}, _defineProperty2[contextProp] = PropTypes.object.isRequired, _defineProperty2)); | ||
Provider.childContextTypes = (_Provider$childContex = {}, _Provider$childContex[contextProp] = PropTypes.object.isRequired, _Provider$childContex); | ||
@@ -151,15 +116,8 @@ var Consumer = | ||
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
_this2 = _Component2.call.apply(_Component2, [this].concat(args)) || this; | ||
_defineProperty(_assertThisInitialized(_this2), "observedBits", void 0); | ||
_defineProperty(_assertThisInitialized(_this2), "state", { | ||
_this2 = _Component2.apply(this, arguments) || this; | ||
_this2.state = { | ||
value: _this2.getValue() | ||
}); | ||
}; | ||
_defineProperty(_assertThisInitialized(_this2), "onUpdate", function (newValue, changedBits) { | ||
_this2.onUpdate = function (newValue, changedBits) { | ||
var observedBits = _this2.observedBits | 0; | ||
@@ -172,3 +130,3 @@ | ||
} | ||
}); | ||
}; | ||
@@ -182,4 +140,3 @@ return _this2; | ||
var observedBits = nextProps.observedBits; | ||
this.observedBits = observedBits === undefined || observedBits === null ? MAX_SIGNED_31_BIT_INT // Subscribe to all changes by default | ||
: observedBits; | ||
this.observedBits = observedBits === undefined || observedBits === null ? MAX_SIGNED_31_BIT_INT : observedBits; | ||
}; | ||
@@ -193,4 +150,3 @@ | ||
var observedBits = this.props.observedBits; | ||
this.observedBits = observedBits === undefined || observedBits === null ? MAX_SIGNED_31_BIT_INT // Subscribe to all changes by default | ||
: observedBits; | ||
this.observedBits = observedBits === undefined || observedBits === null ? MAX_SIGNED_31_BIT_INT : observedBits; | ||
}; | ||
@@ -219,4 +175,3 @@ | ||
_defineProperty(Consumer, "contextTypes", (_defineProperty3 = {}, _defineProperty3[contextProp] = PropTypes.object, _defineProperty3)); | ||
Consumer.contextTypes = (_Consumer$contextType = {}, _Consumer$contextType[contextProp] = PropTypes.object, _Consumer$contextType); | ||
return { | ||
@@ -223,0 +178,0 @@ Provider: Provider, |
@@ -17,4 +17,4 @@ import * as React from 'react'; | ||
value: T; | ||
children: React.ReactNode; | ||
observedBits: any, | ||
children?: React.ReactNode; | ||
observedBits?: any, | ||
}; | ||
@@ -21,0 +21,0 @@ |
{ | ||
"name": "mini-create-react-context", | ||
"version": "0.3.0", | ||
"version": "0.3.2", | ||
"description": "Smaller Polyfill for the proposed React context API", | ||
@@ -28,3 +28,4 @@ "main": "dist/cjs/index.js", | ||
"gud": "^1.0.0", | ||
"tiny-warning": "^1.0.2" | ||
"tiny-warning": "^1.0.2", | ||
"@babel/runtime": "^7.4.0" | ||
}, | ||
@@ -40,3 +41,2 @@ "peerDependencies": { | ||
"@babel/preset-env": "^7.4.3", | ||
"@babel/preset-flow": "^7.0.0", | ||
"@babel/preset-react": "^7.0.0", | ||
@@ -46,3 +46,4 @@ "@babel/preset-typescript": "^7.3.3", | ||
"@types/jest": "^24.0.11", | ||
"@types/react": "^16.8.12", | ||
"@types/react": "^16.8.13", | ||
"@wessberg/rollup-plugin-ts": "^1.1.46", | ||
"babel-jest": "^24.7.1", | ||
@@ -57,6 +58,5 @@ "enzyme": "^3.9.0", | ||
"react-dom": "^16.2.0", | ||
"rollup": "^1.9.0", | ||
"rollup-plugin-babel": "^4.3.2", | ||
"rollup": "^1.10.0", | ||
"rollup-plugin-commonjs": "^9.3.4", | ||
"rollup-plugin-node-resolve": "^4.1.0", | ||
"rollup-plugin-node-resolve": "^4.2.3", | ||
"rollup-plugin-uglify": "^6.0.2" | ||
@@ -69,2 +69,2 @@ }, | ||
} | ||
} | ||
} |
@@ -1,3 +0,15 @@ | ||
# mini-create-react-context | ||
# mini-create-react-context | ||
<p align="center"> | ||
<a href="https://packagephobia.now.sh/result?p=mini-create-react-context"> | ||
<img alt="npm install size" src="https://packagephobia.now.sh/badge?p=mini-create-react-context"> | ||
</a> | ||
<a href="https://bundlephobia.com/result?p=mini-create-react-context"> | ||
<img alt="npm bundle size" src="https://img.shields.io/bundlephobia/min/mini-create-react-context.svg?style=flat-square"> | ||
</a> | ||
<a href="https://www.npmjs.com/package/mini-create-react-context"> | ||
<img alt="npm" src="https://img.shields.io/npm/v/mini-create-react-context.svg?style=flat-square"> | ||
</a> | ||
</p> | ||
> (A smaller) Polyfill for the [proposed React context API](https://github.com/reactjs/rfcs/pull/2) | ||
@@ -8,3 +20,3 @@ | ||
```sh | ||
npm install create-react-context | ||
npm install mini-create-react-context | ||
``` | ||
@@ -36,3 +48,3 @@ | ||
import React, { type Node } from 'react'; | ||
import createReactContext, { type Context } from 'create-react-context'; | ||
import createReactContext, { type Context } from 'mini-create-react-context'; | ||
@@ -39,0 +51,0 @@ type Theme = 'light' | 'dark'; |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
23
118
0
18677
5
288
+ Added@babel/runtime@^7.4.0
+ Added@babel/runtime@7.24.5(transitive)
+ Addedregenerator-runtime@0.14.1(transitive)