Re: [timingobject] Chaining timing objects (#13)

Yes, you're right. It's probably a bit too powerful.

1. But at least for this use case the usage of arbitrary JavaScript could be an advantage. I think it's possible to dynamically change the value by using a closure. Something like the following should work.

```js
const createSkew = (timingObject, value) => [
    new TimingObject(
        timingObject,
        {
            query: ({ position, ...vector }) => ({ position: position + value, ...vector }),
            update: ({ position, ...vector }) => ({ position: position - value, ...vector })
        })
    ),
    (newValue) => value = newValue
];

const [skew, changeSkew] = createSkew(to, 4);
// skew is a TimingObject with the applied change.
// changeSkew(2) can be used to change the value.
```

It could probably also be done in an object oriented style.

```js
class SkewedTimingObject extends TimingObject {
    constructor(timingObject, skew) {
        super(
            timingObject,
            {
                query: (vector) => this.query(vector),
                update: (vector) => this.update(vector)
            }
        );

        this.skew = skew;
    }

    query(vector) {
       return { position: position + this.skew, ...vector };
    }

    update(vector) {
       return { position: position - this.skew, ...vector };
    }
}

const skewedTimingObject = new SkewedTimingObject(to, 4);

skewedTimingObject.skew = 2;
```

2. The algorithm for [creating a new `TimingObject`](https://webtiming.github.io/timingobject/#create-a-new-timing-object) deals with range violations already. Maybe the same algorithm could be used here too.
> 8. If timing's [range](https://webtiming.github.io/timingobject/#dfn-range) does not [cover](https://webtiming.github.io/timingobject/#dfn-cover) the position of the [internal vector](https://webtiming.github.io/timingobject/#dfn-internal-vector):
>     1. Let timing's [internal vector](https://webtiming.github.io/timingobject/#dfn-internal-vector)'s position be [start position](https://webtiming.github.io/timingobject/#dfn-start-position) or [end position](https://webtiming.github.io/timingobject/#dfn-end-position), whichever is closest
>     2. Let timing's [internal vector](https://webtiming.github.io/timingobject/#dfn-internal-vector)'s velocity and acceleration be 0.0 if the direction of the motion would make the position leave the [range](https://webtiming.github.io/timingobject/#dfn-range) immediately.
>     3. [Set the internal timeout](https://webtiming.github.io/timingobject/#dfn-set-the-internal-timeout) of timing.

3. I'm not sure how that could be enforced. Maybe it's okay to allow people to do weird stuff.

-- 
GitHub Notification of comment by chrisguttandin
Please view or discuss this issue at https://github.com/webtiming/timingobject/issues/13#issuecomment-1465204347 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Sunday, 12 March 2023 13:46:01 UTC