-
Notifications
You must be signed in to change notification settings - Fork 1
/
usage-tweenState.js
57 lines (49 loc) · 1.67 KB
/
usage-tweenState.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// import the component library as usual
var { Component, tweenState } = require("../dist/index.min.js")
Component.tweenState = tweenState
// ------------------------------------------------
// USAGE: Defining components
// ------------------------------------------------
// Define our app state
var state = {
ignore: "me",
count: 199,
foo: 1,
dontTween: "this property",
bar: {
zzz: 100
}
}
// Define a stateful main component
var App = new Component(state)
// return the state itself (pure headless, data-only component)
App.view = props => props
//
// ------------------------------------------------
// Tween (animate) from one state to the next
//
console.log("App.state\n", App.state)
console.log("")
// give the state to tween to, with some tween options as the (optional) 2nd param
App.tweenState(
// 1st param - object - the new state values to tween to...
// pass in only the properties that you want to tween!
{ count: 200, foo: 10, bar: { zzz: 999 } },
// 2nd param - object - the tween settings
{
delay: 0,
duration: 1000,
ease: "linear",
paused: false,
// called on first frame:
onStart: tweenProps => console.log("Start tween:"),
// called on every frame:
onUpdate: tweenProps => console.log(tweenProps.values),
// called on last frame:
onComplete: tweenProps => console.log("\nApp.state:\n", App.state),
// called on every frame, choose to set state or not (return true or false)
shouldSetState: tweenProps => tweenProps.frame % 2 > 0, // for example, this will set state only on odd frame numbers
// called only on the frames where the state was updated:
onSetState: tweenProps => tweenProps
}
)