react-undoable
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -1,1 +0,1 @@ | ||
"use strict";var __extends=this&&this.__extends||function(){var n=function(t,e){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)};return function(t,e){function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}}(),__assign=this&&this.__assign||function(){return(__assign=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var a in e=arguments[r])Object.prototype.hasOwnProperty.call(e,a)&&(t[a]=e[a]);return t}).apply(this,arguments)};Object.defineProperty(exports,"__esModule",{value:!0});var React=require("react"),deepMerge=require("deepmerge"),Undoable=function(t){function e(){var i=null!==t&&t.apply(this,arguments)||this;return i.state={currentState:void 0,previousState:[],nextState:[]},i.undo=function(){var t=i.state,e=t.previousState,r=t.nextState,n=t.currentState;if(e.length){var a=e.slice(),o=a.pop(),u=n;return i.setState({currentState:o,nextState:r.concat([u]),previousState:a}),o}},i.redo=function(){var t=i.state,e=t.previousState,r=t.nextState,n=t.currentState;if(r.length){var a=r.slice(),o=a.pop(),u=n;return i.setState({currentState:o,nextState:a,previousState:e.concat([u])}),o}},i.pushState=function(t){var e=i.state,r=e.currentState,n=e.previousState,a=deepMerge(r||{},t);i.setState({currentState:a,nextState:[],previousState:n.concat([r])})},i.resetState=function(t){i.setState({currentState:t,nextState:[],previousState:[]})},i.updateState=function(e){var t=i.state,r=t.currentState,n=t.nextState,a=t.previousState,o=deepMerge(r||{},e);i.setState({currentState:o,previousState:a.map(function(t){return deepMerge(t,e)}),nextState:n.map(function(t){return deepMerge(t,e)})})},i}return __extends(e,t),e.getDerivedStateFromProps=function(t,e){return t.initialState&&void 0===e.currentState?{currentState:t.initialState}:null},e.prototype.render=function(){var t=this.props.children,e=__assign({},this.state,{undo:this.undo,redo:this.redo,pushState:this.pushState,resetState:this.resetState,updateState:this.updateState});return!!t&&t(e)},e}(React.Component);exports.default=Undoable; | ||
"use strict";var __extends=this&&this.__extends||function(){var a=function(t,e){return(a=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)};return function(t,e){function r(){this.constructor=t}a(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}}(),__assign=this&&this.__assign||function(){return(__assign=Object.assign||function(t){for(var e,r=1,a=arguments.length;r<a;r++)for(var n in e=arguments[r])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t}).apply(this,arguments)};Object.defineProperty(exports,"__esModule",{value:!0});var React=require("react"),deepMerge=require("deepmerge"),arrayMerge=function(t,e,r){return e},Undoable=function(t){function e(){var i=null!==t&&t.apply(this,arguments)||this;return i.state={currentState:void 0,previousState:[],nextState:[]},i.undo=function(){var t=i.state,e=t.previousState,r=t.nextState,a=t.currentState;if(e.length){var n=e.slice(),o=n.pop(),u=a;return i.setState({currentState:o,nextState:r.concat([u]),previousState:n}),o}},i.redo=function(){var t=i.state,e=t.previousState,r=t.nextState,a=t.currentState;if(r.length){var n=r.slice(),o=n.pop(),u=a;return i.setState({currentState:o,nextState:n,previousState:e.concat([u])}),o}},i.pushState=function(t){var e=i.state,r=e.currentState,a=e.previousState,n=deepMerge(r||{},t,{arrayMerge:arrayMerge});i.setState({currentState:n,nextState:[],previousState:a.concat([r])})},i.resetState=function(t){i.setState({currentState:t,nextState:[],previousState:[]})},i.updateState=function(e){var t=i.state,r=t.currentState,a=t.nextState,n=t.previousState,o=deepMerge(r||{},e,{arrayMerge:arrayMerge});i.setState({currentState:o,previousState:n.map(function(t){return deepMerge(t,e,{arrayMerge:arrayMerge})}),nextState:a.map(function(t){return deepMerge(t,e,{arrayMerge:arrayMerge})})})},i}return __extends(e,t),e.getDerivedStateFromProps=function(t,e){return t.initialState&&void 0===e.currentState?{currentState:t.initialState}:null},e.prototype.render=function(){var t=this.props.children,e=__assign({},this.state,{undo:this.undo,redo:this.redo,pushState:this.pushState,resetState:this.resetState,updateState:this.updateState});return!!t&&t(e)},e}(React.Component);exports.default=Undoable; |
{ | ||
"name": "react-undoable", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Easily undo/redo any state in React, no external dependencies", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -31,3 +31,3 @@ # react-undoable 🔄 | ||
```typescript | ||
import React, { PureComponent } from 'react' | ||
import * as React from 'react' | ||
import Undoable, { IUndoable } from 'react-undoable' | ||
@@ -64,3 +64,3 @@ import ReactDOM from 'react-dom' | ||
*/ | ||
class MyComponent extends PureComponent<IMyComponentProps> { | ||
class MyComponent extends React.Component<IMyComponentProps> { | ||
/** | ||
@@ -67,0 +67,0 @@ * Count up - This demonstrates pushing a complete state to the stack |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
191918