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

Replace val() with getters/setters #15

Closed
3 tasks
clabe45 opened this issue Jul 18, 2019 · 7 comments
Closed
3 tasks

Replace val() with getters/setters #15

clabe45 opened this issue Jul 18, 2019 · 7 comments
Labels
help wanted Extra attention is needed priority:high type:bug Something isn't working

Comments

@clabe45
Copy link
Collaborator

clabe45 commented Jul 18, 2019

util.val is used to sample a property, using keyframes, functions, or just returning a single value.

Since the syntax is gross, let's replace it with setters and getters, which use a similar util.val function (to prevent repeated code). Besides that, and the fact that each value should be cached per frame (I will make this a new issue), the details are left open for now.

As a side benefit, properties like layer.width and layer.height can default to the movie's width/height right in the getter, or perform similar behavior (instead of doing it manually with every query). More importantly, caching eliminates the bug of multiple different values from function properties per frame.


@clabe45 clabe45 added type:bug Something isn't working help wanted Extra attention is needed labels Aug 14, 2019
@alejolale
Copy link

Hi !
I'm interested in this work ! could you explain more clear this work ?

Thanks for your answer

@clabe45
Copy link
Collaborator Author

clabe45 commented Oct 3, 2019

Absolutely! Because properties can be keyframes, functions, or just simple values; we need a way to get the current value of a property for a frame. Right now, the util function val(property, element, time) does this, but I think there is a way to make the syntax nicer (and more friendly to usage from the user).

The task is to write a getter and setter for each public property (that's intended to be used externally). I'm thinking something like:

// for layers
set propName(value) {
    this._propName = value;
}

get propName() {
    return val(this._propName, this, this._movie.currentTime - this.startTime);
}

Doing this will solve another problem: There are some properties that require custom logic when accessing their values, like layer dimensions default to the movie's dimensions when they are undefined. Right now, this is handled by resizing the canvas to the current frame's values each frame. Then, the canvas's dimensions are read for the rest of the frame. It would be a lot better to put this logic in a getter, like:

// in layer.Base
get width() {
    return val(this._width, this, this._movie.currentTime - this.startTime);
}

I just created #20 which ideally should be done first, so you can use this.currentTime for movies and layers and this._target.currentTime for effects when you pass the time to val.

@clabe45
Copy link
Collaborator Author

clabe45 commented Oct 3, 2019

I updated the OP with a checklist. Just pick one and push it to a new feature branch for this issue, unless you're feeling ambitious. Or, you can start with one of the smaller good first issues, if you'd like.

@thefishgineer
Copy link

Any progress on this? I can help with this.

@clabe45
Copy link
Collaborator Author

clabe45 commented Nov 15, 2019

@alejolale Are you currently working on this issue?

@clabe45
Copy link
Collaborator Author

clabe45 commented Dec 5, 2019

@rc41186 I forget about this, yes you can work on it if you're still interested

@clabe45 clabe45 mentioned this issue Dec 6, 2019
@clabe45
Copy link
Collaborator Author

clabe45 commented Dec 24, 2019

I decided not to do this, because it would be very error-prone to have to implement setters and getters (that call val) for every public property in every class. Instead, I implemented property filters (0fca188) that process the results of val. You only need to implement property filters when custom logic needs to be applied to the instant value.

@clabe45 clabe45 closed this as completed Dec 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed priority:high type:bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants