Skip to content

Commit

Permalink
API: add destroy method
Browse files Browse the repository at this point in the history
  • Loading branch information
legomushroom committed Jan 18, 2017
1 parent dccb319 commit fa68a68
Show file tree
Hide file tree
Showing 14 changed files with 937 additions and 912 deletions.
1,649 changes: 805 additions & 844 deletions app/build/mojs-curve-editor.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions app/build/mojs-curve-editor.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/css/blocks/curve-editor.postcss.css.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"curve-editor":"_curve-editor_10g8s_3","curve-editor__left":"_curve-editor__left_10g8s_1","curve-editor__right":"_curve-editor__right_10g8s_133","curve-editor__resize-handle":"_curve-editor__resize-handle_10g8s_1","curve-editor__anchor-buttons":"_curve-editor__anchor-buttons_10g8s_128","curve-editor__mojs-logo":"_curve-editor__mojs-logo_10g8s_111","is-inactive":"_is-inactive_10g8s_110","is-minimized":"_is-minimized_10g8s_118","curve__svg-wrapper":"_curve__svg-wrapper_10g8s_137","is-hidden-on-min":"_is-hidden-on-min_10g8s_147"}
{"curve-editor":"_curve-editor_d81sj_3","curve-editor__left":"_curve-editor__left_d81sj_1","curve-editor__right":"_curve-editor__right_d81sj_138","curve-editor__resize-handle":"_curve-editor__resize-handle_d81sj_1","curve-editor__anchor-buttons":"_curve-editor__anchor-buttons_d81sj_133","curve-editor__mojs-logo":"_curve-editor__mojs-logo_d81sj_116","is-inactive":"_is-inactive_d81sj_115","is-minimized":"_is-minimized_d81sj_123","curve__svg-wrapper":"_curve__svg-wrapper_d81sj_142","is-hidden-on-min":"_is-hidden-on-min_d81sj_152"}
7 changes: 6 additions & 1 deletion app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@
name: 'some name',
// onChange(path) { console.log(path); },
// isHiddenOnMin: true
}).toggleSize();
});

// setTimeout( () => {
// curveEditor.destroy();
// }, 5000 );


</script>

Expand Down
30 changes: 28 additions & 2 deletions app/js/app.babel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class API {
}

_vars () {
this.revision = '1.5.0';
this.revision = '1.6.0';
this.store = initStore();

this._easings = [];
Expand All @@ -72,7 +72,7 @@ class API {
}

_renderApp () {
render(
this._rootEl = render(
<Provider store={this.store}>
<CurveEditor progressLines={this._progressLines}
options={this._props}
Expand Down Expand Up @@ -177,6 +177,11 @@ class API {
el.style.left = `${p*100}%`;
}

/****** Public API ******/

/* Function to get the easing function compiled from the curve.
@param {Object} Options.
*/
getEasing (o={}) {
// get the easing function regarding reverse options
const fun = (() => {
Expand All @@ -196,17 +201,38 @@ class API {
return fun;
}

/* Minimize the curve editor - save as clicking the `minimize` button.
*/
minimize() { this.store.dispatch({ type: 'SET_MINIMIZE', data: true }); }

/* Maximize the curve editor - save as clicking the `maximize` button.
*/
maximize() { this.store.dispatch({ type: 'SET_MINIMIZE', data: false }); }

/* Toggles between `maximize` and `minimize` states.
*/
toggleSize() {
const state = this.store.getState();
const {controls} = state;

controls.isMinimize ? this.maximize() : this.minimize();
}

/* Destroys the app and ensures the `componentWillUnmount` is called
on the each component in the Components Tree.
*/
destroy() {
// console.log(this._rootEl);
const NullComponent = () => { return null };
render(
<NullComponent />,
document.body,
this._rootEl
);
}



// highlight() { this.store.dispatch({ type: 'SET_HIGHLIGHT', data: true }); }
// dim() { this.store.dispatch({ type: 'SET_HIGHLIGHT', data: false }); }
// toggleHighlight() {
Expand Down
8 changes: 5 additions & 3 deletions app/js/tags/code-button.babel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ class CodeButton extends Component {
}
componentDidMount () {
const {store} = this.context;
const mc = propagating(new Hammer.Manager(this.base));
mc.add(new Hammer.Tap);
this._mc = propagating(new Hammer.Manager(this.base));
this._mc.add(new Hammer.Tap);

mc.on('tap', (e) => { store.dispatch({ type: 'CODE_TAP' }); });
this._mc.on('tap', (e) => { store.dispatch({ type: 'CODE_TAP' }); });
}

componentWillUnmount() { this._mc.off('tap'); }
}

export default CodeButton;
16 changes: 10 additions & 6 deletions app/js/tags/curve-editor.babel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ class CurveEditor extends Component {
componentDidMount () {
this._resetCounter = 0;

const {store} = this.context,
el = this.base.querySelector('#js-left-panel'),
mc = propagating(new Hammer.Manager(el));
const {store} = this.context;
const el = this.base.querySelector('#js-left-panel');
this._mc = propagating(new Hammer.Manager(el));

mc.add(new Hammer.Pan({ threshold: 0 }));
mc
this._mc.add(new Hammer.Pan({ threshold: 0 }));
this._mc
.on('pan', (e) => {
const x = e.deltaX, y = e.deltaY;
store.dispatch({ type: 'EDITOR_TRANSLATE', data: { x, y } });
Expand All @@ -89,6 +89,11 @@ class CurveEditor extends Component {
store.subscribe(this.forceUpdate.bind(this));
}

componentWillUnmount() {
this._mc.off('pan');
this._mc.off('panend');
}

_addKeyUp () { document.addEventListener('keyup', this._onKeyUp.bind(this)); }

_onKeyUp (e) {
Expand Down Expand Up @@ -149,7 +154,6 @@ class CurveEditor extends Component {
store.dispatch({ type: 'SET_ACTIVE', data: false });
}
}

}


Expand Down
27 changes: 16 additions & 11 deletions app/js/tags/curve.babel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,14 @@ class Curve extends Component {
componentDidMount () {
this._updateDomProgressLines();

const {store} = this.context,
el = this.base.querySelector('#js-segments'),
mc = propagating(new Hammer.Manager(el));

const {store} = this.context;
const el = this.base.querySelector('#js-segments');
this._mc = propagating(new Hammer.Manager(el));

// mc.add(new Hammer.Pan({ threshold: 0 }));
mc.add(new Hammer.Tap);
this._mc.add(new Hammer.Tap);

mc
this._mc
.on('tap', (e) => {
const {state} = this.props;
const ev = e.srcEvent;
Expand Down Expand Up @@ -216,13 +215,13 @@ class Curve extends Component {
e.stopPropagation();
});

const svg = this.base.querySelector('#js-svg'),
svgMc = propagating(new Hammer.Manager(this.base));
const svg = this.base.querySelector('#js-svg');
this._svgMc = propagating(new Hammer.Manager(this.base));

svgMc.add(new Hammer.Tap);
svgMc.add(new Hammer.Pan);
this._svgMc.add(new Hammer.Tap);
this._svgMc.add(new Hammer.Pan);

svgMc
this._svgMc
.on('tap', (e) => {
store.dispatch({ type: 'POINT_DESELECT_ALL' });
})
Expand All @@ -232,7 +231,13 @@ class Curve extends Component {
.on('panend', (e) => {
store.dispatch({ type: 'EDITOR_PAN_END', data: e.deltaY });
});
}

componentWillUnmount() {
this._mc.off('tap');
this._svgMc.off('tap');
this._svgMc.off('pan');
this._svgMc.off('panend');
}
}

Expand Down
17 changes: 11 additions & 6 deletions app/js/tags/icon-button.babel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,24 @@ class IconButton extends Component {
render () {
const p = this.props;
const check = (p.isCheck) ? CLASSES['is-checked'] : '';
return <div className={`${CLASSES['icon-button']} ${check}`}
title={ p.title || '' }
data-component={'icon-button'}>
<Icon shape={this.props.shape} />
</div>;
return (
<div className={`${CLASSES['icon-button']} ${check}`}
title={ p.title || '' }
data-component={'icon-button'}>
<Icon shape={this.props.shape} />
</div>
);
}

componentDidMount () {
if ( typeof this.props.onTap === 'function' ) {
var hammertime = new Hammer(this.base)
this._mc = new Hammer(this.base)
.on('tap', (e) => { this.props.onTap( e, this.props ) });
}
}

componentWillUnmount() {
if ( typeof this.props.onTap === 'function' ) { this._mc.off('tap'); } }
}

export default IconButton;
8 changes: 5 additions & 3 deletions app/js/tags/maximize-button.babel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ class MaximizeButton extends Component {
}
componentDidMount () {
const {store} = this.context;
const mc = propagating(new Hammer.Manager(this.base));
mc.add(new Hammer.Tap);
this._mc = propagating(new Hammer.Manager(this.base));
this._mc.add(new Hammer.Tap);

mc.on('tap', (e) => {
this._mc.on('tap', (e) => {
store.dispatch({ type: 'SET_MINIMIZE', data: false });
});
}

componentWillUnmount() { this._mc.off('tap'); }
}

export default MaximizeButton;
16 changes: 10 additions & 6 deletions app/js/tags/minimize-button.babel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,23 @@ import Hammer from 'hammerjs';
class MinimizeButton extends Component {
render () {
const {state} = this.props;
return <div data-component="minimize-button" title="minimize">
<IconButton shape="minimize" />
</div>;
return (
<div data-component="minimize-button" title="minimize">
<IconButton shape="minimize" />
</div>
);
}
componentDidMount () {
const {store} = this.context;
const mc = propagating(new Hammer.Manager(this.base));
mc.add(new Hammer.Tap);
this._mc = propagating(new Hammer.Manager(this.base));
this._mc.add(new Hammer.Tap);

mc.on('tap', (e) => {
this._mc.on('tap', (e) => {
store.dispatch({ type: 'SET_MINIMIZE', data: true });
});
}

componentWillUnmount() { this._mc.off('tap'); }
}

export default MinimizeButton;
40 changes: 23 additions & 17 deletions app/js/tags/point.babel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ class Point extends Component {

const littleHandles = this._getLittleHandles( );

return <div className={`${CLASSES['point']} ${selected} ${handles}`}
style={ this._getStyle(state) }
data-component="point">
return (
<div className={`${CLASSES['point']} ${selected} ${handles}`}
style={ this._getStyle(state) }
data-component="point">

<div className={ CLASSES['point__touch'] } id="js-point-touch" />
<div className={ CLASSES['point__touch'] } id="js-point-touch" />

{ littleHandles }
{ littleHandles }

</div>
</div>
);
}

_getStyle (state) {
Expand All @@ -52,13 +54,12 @@ class Point extends Component {
}

_createHandle (index, point) {
return <LittleHandle
index={index}
state={this.props.state}
parentIndex={this.props.index}
handle={point[`handle${index}`]}
type={point.type}
/>
return (
<LittleHandle index={index} state={this.props.state}
parentIndex={this.props.index}
handle={point[`handle${index}`]}
type={point.type} />
);
}

componentDidMount () {
Expand Down Expand Up @@ -103,12 +104,12 @@ class Point extends Component {
return roundTo( returnValue, 5*C.CURVE_PERCENT, 2*C.CURVE_PERCENT ) - point.y;
}

const el = this.base.querySelector('#js-point-touch'),
mc = propagating(new Hammer.Manager(el));
const el = this.base.querySelector('#js-point-touch');
this._mc = propagating(new Hammer.Manager(el));

mc.add(new Hammer.Pan({ threshold: 0 }));
this._mc.add(new Hammer.Pan({ threshold: 0 }));

mc
this._mc
.on('pan', (e) => {
const {point, index} = this.props;
store.dispatch({
Expand Down Expand Up @@ -138,6 +139,11 @@ class Point extends Component {
});
} );
}
componentWillUnmount() {
this._mc.off('tap');
this._mc.off('pan');
this._mc.off('panend');
}
}

export default Point;
15 changes: 10 additions & 5 deletions app/js/tags/resize-handle.babel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ class ResizeHandle extends Component {
}

componentDidMount () {
const {type} = this.props,
{store} = this.context,
mc = propagating(new Hammer.Manager(this.base));
const {type} = this.props;
const {store} = this.context;
this._mc = propagating(new Hammer.Manager(this.base));

mc.add(new Hammer.Pan({ threshold: 0 }));
mc
this._mc.add(new Hammer.Pan({ threshold: 0 }));
this._mc
.on('pan', (e) => {
store.dispatch({ type: 'EDITOR_RESIZE', data: {
...modDeltas(e.deltaX, e.deltaY, type, this.props.state)
Expand All @@ -40,6 +40,11 @@ class ResizeHandle extends Component {
e.stopPropagation();
});
}

componentWillUnmount() {
this._mc.off('pan');
this._mc.off('panend');
}
}

export default ResizeHandle;
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mojs-curve-editor",
"version": "1.5.0",
"version": "1.6.0",
"description": "mojs GUI for editing easing/property curves",
"keywords": [
"mojs",
Expand Down Expand Up @@ -31,7 +31,7 @@
"homepage": "https://github.com/legomushroom/mojs-curve-editor#readme",
"dependencies": {
"hammerjs": "^2.0.8",
"preact": "^5.6.0",
"preact": "^7.1.0",
"redux": "^3.5.2",
"redux-recycle": "^1.2.0",
"redux-undo": "^0.6.1"
Expand Down

0 comments on commit fa68a68

Please sign in to comment.