Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[web] Added support for callID #547

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/core/AnimatedCallFunc.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import AnimatedNode from './AnimatedNode';
import AnimatedNode, { getCallID, setCallID } from './AnimatedNode';
import { adapt } from './AnimatedBlock';
import { val } from '../val';
import invariant from 'fbjs/lib/invariant';

class AnimatedCallFunc extends AnimatedNode {
_previousCallID;
_what;
_args;
_params;
Expand Down Expand Up @@ -39,15 +40,19 @@ class AnimatedCallFunc extends AnimatedNode {
}

beginContext() {
this._previousCallID = getCallID();
setCallID(getCallID() + '/' + this.__nodeID);

this._params.forEach((param, index) => {
param.beginContext(this._args[index]);
param.beginContext(this._args[index], this._previousCallID);
});
}

endContext() {
this._params.forEach((param, index) => {
param.endContext();
});
setCallID(this._previousCallID);
EvanBacon marked this conversation as resolved.
Show resolved Hide resolved
}

__onEvaluate() {
Expand Down
38 changes: 25 additions & 13 deletions src/core/AnimatedNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ const UPDATED_NODES = [];

let loopID = 1;
let propUpdatesEnqueued = null;
let nodeCount = 0;
let callID = "";

export function getCallID() {
return callID;
}

export function setCallID(nextCallID) {
callID = nextCallID;
}

function sanitizeConfig(config) {
if (Platform.OS === 'web') {
Expand Down Expand Up @@ -52,9 +62,14 @@ function runPropUpdates() {
loopID += 1;
}

let nodeCount = 0;

export default class AnimatedNode {

/* { [loop: string]: int } */
EvanBacon marked this conversation as resolved.
Show resolved Hide resolved
__nodeID;
__lastLoopID = { "": -1 };
__memoizedValue = { "": null };
__children = [];

constructor(nodeConfig, inputNodes) {
this.__nodeID = ++nodeCount;
this.__nodeConfig = sanitizeConfig(nodeConfig);
Expand Down Expand Up @@ -91,26 +106,23 @@ export default class AnimatedNode {
this.__nativeTearDown();
}

__lastLoopID = 0;
__memoizedValue = null;

__children = [];

__getValue() {
if (this.__lastLoopID < loopID) {
this.__lastLoopID = loopID;
return (this.__memoizedValue = this.__onEvaluate());
if (!(callID in this.__lastLoopID) || this.__lastLoopID[callID] < loopID) {
this.__lastLoopID[callID] = loopID;
const result = this.__onEvaluate();
this.__memoizedValue[callID] = result;
return result;
}
return this.__memoizedValue;
return this.__memoizedValue[callID];
}

__forceUpdateCache(newValue) {
this.__memoizedValue = newValue;
this.__memoizedValue[callID] = newValue;
this.__markUpdated();
}

__dangerouslyRescheduleEvaluate() {
this.__lastLoopID = 0;
this.__lastLoopID[callID] = -1;
this.__markUpdated();
}

Expand Down
25 changes: 19 additions & 6 deletions src/core/AnimatedParam.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import invariant from 'fbjs/lib/invariant';
import AnimatedNode from './AnimatedNode';
import AnimatedNode, { getCallID, setCallID } from './AnimatedNode';
import AnimatedClock from './AnimatedClock';
import { val } from '../val';

export class AnimatedParam extends AnimatedNode {
argsStack = [];

_prevCallID;

constructor() {
super({ type: 'param' }, []);
this.__attach();
}

beginContext(ref) {
beginContext(ref, prevCallID) {
this._prevCallID = prevCallID;
this.argsStack.push(ref);
}

Expand All @@ -28,15 +30,22 @@ export class AnimatedParam extends AnimatedNode {
setValue(value) {
const top = this._getTopNode();
if (top.setValue) {
const callID = getCallID();
setCallID(this._prevCallID);
top.setValue(value);
setCallID(callID);
} else {
throw new Error(`param: setValue(${value}) failed because the top element has no known method for updating it's current value.`)
}
}

__onEvaluate() {
const callID = getCallID();
setCallID(this._prevCallID);
const top = this._getTopNode();
return val(top);
const value = val(top);
setCallID(callID);
return value;
}

start() {
Expand All @@ -59,11 +68,15 @@ export class AnimatedParam extends AnimatedNode {

isRunning() {
const node = this._getTopNode();

if (node instanceof AnimatedParam) {
return node.isRunning()
}
invariant(
node instanceof AnimatedClock || node instanceof AnimatedParam,
node instanceof AnimatedClock,
`param: top node should be of type AnimatedClock but got ${node}`
);
return node.isRunning()
return node.isStarted();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/AnimatedValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class AnimatedValue extends InternalAnimatedValue {
}

toString() {
return `AnimatedValue, id: ${super.__nodeID}`;
return `AnimatedValue, id: ${this.__nodeID}`;
EvanBacon marked this conversation as resolved.
Show resolved Hide resolved
}

interpolate(config) {
Expand Down