| import React from "react"; | ||
| import withState from "./withState"; | ||
| const IsActive = ({ state, children }) => { | ||
| const Comp = withState(state, () => children(true), () => children(false)); | ||
| return <Comp />; | ||
| }; | ||
| export default IsActive; |
+1
-1
| { | ||
| "name": "machinate", | ||
| "version": "1.1.0", | ||
| "version": "1.1.1", | ||
| "description": "practical state management", | ||
@@ -5,0 +5,0 @@ "main": "build/lib.js", |
@@ -15,2 +15,6 @@ import React from "react"; | ||
| if (props.configure) { | ||
| props.configure(machine); | ||
| } | ||
| machine.addListener("force-state", () => { | ||
@@ -48,3 +52,4 @@ this.forced = true; | ||
| scheme: PropTypes.object.isRequired, | ||
| initial: PropTypes.object.isRequired | ||
| initial: PropTypes.object.isRequired, | ||
| configure: PropTypes.func | ||
| }; | ||
@@ -51,0 +56,0 @@ |
@@ -53,5 +53,7 @@ import React, { Component } from "react"; | ||
| const { machine: { external } } = this.context; | ||
| const ifInactive = | ||
| (this.props.ifInactive && this.props.ifInactive()) || null; | ||
| const stateInfo = this.getActiveState(); | ||
| if (!stateInfo) return null; | ||
| if (!stateInfo) return ifInactive; | ||
@@ -58,0 +60,0 @@ return ( |
@@ -6,3 +6,3 @@ import React from "react"; | ||
| const withState = (stateName, Component) => { | ||
| const withState = (stateName, Component, ifInactive) => { | ||
| const C = props => { | ||
@@ -13,2 +13,3 @@ const { wrappedComponentRef, ...remainingProps } = props; | ||
| of={stateName} | ||
| ifInactive={ifInactive} | ||
| children={stateComponentProps => ( | ||
@@ -15,0 +16,0 @@ <Component |
+2
-0
@@ -7,2 +7,3 @@ import Machinate from "./components/Machinate"; | ||
| import Submachine from "./components/Submachine"; | ||
| import IsActive from "./components/IsActive"; | ||
@@ -16,2 +17,3 @@ import { isTransitionable, createMachine } from "./machine"; | ||
| Submachine, | ||
| IsActive, | ||
| isTransitionable, | ||
@@ -18,0 +20,0 @@ createMachine, |
+28
-3
@@ -184,3 +184,10 @@ import React from "react"; | ||
| const fullName = _componentFullName(comp); | ||
| return fullName === resolvedDomainName; | ||
| return ( | ||
| fullName === | ||
| resolvedDomainName /*&& | ||
| (comp.props.of !== schematicFromName || | ||
| comp.props.of === schematicToName || | ||
| (comp.props.ifInactive && comp.props.of === schematicFromName)) | ||
| */ | ||
| ); | ||
| }); | ||
@@ -291,2 +298,9 @@ comps.forEach(comp => comp.forceUpdate()); | ||
| const invariant = (condition, message) => { | ||
| if (!condition) { | ||
| console.error(message); | ||
| } | ||
| }; | ||
| const isFunction = v => typeof v === "function"; | ||
| const createdMachine = { | ||
@@ -310,4 +324,15 @@ getState, | ||
| external: fnArgs => (name, promise, fallback = () => {}) => | ||
| isTriggerBlacklisted(name) ? fallback(fnArgs) : promise(fnArgs), | ||
| external: fnArgs => | ||
| function(name, promise) { | ||
| const fallback = arguments.length === 3 ? arguments[2] : () => {}; | ||
| invariant( | ||
| !!promise && isFunction(promise), | ||
| `The argument provided to the external '${name}' must be a function.` | ||
| ); | ||
| invariant( | ||
| isFunction(fallback), | ||
| `The fallback provided to the external '${name}' must be a function. You may have accidentally triggered the fallback.` | ||
| ); | ||
| return isTriggerBlacklisted(name) ? fallback(fnArgs) : promise(fnArgs); | ||
| }, | ||
| setBlacklist: newBlacklist => { | ||
@@ -314,0 +339,0 @@ blacklist = newBlacklist; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
2327864
0.23%45
2.27%27060
0.3%187
1.08%