Repository: motion-canvas/motion-canvas
File: packages/core/src/scenes/TimeEvents.ts (TypeScript)

Code before:
    if (!this.lookup[name] || this.lookup[name].offset === offset) {
      return;
    }
    this.preserveTiming = preserve;
    this.lookup[name] = {
      ...this.lookup[name],
      targetTime: this.lookup[name].initialTime + offset,
      offset,
    };
    this.registeredEvents[name] = this.lookup[name];
    this.events.current = Object.values(this.registeredEvents);
    this.didEventsChange = true;
    this.scene.reload();
  }

  /**
   * Register a time event.
   *
   * @param name - The name of the event.
   *
   * @returns The absolute frame at which the event should occur.
   *
   * @internal
   */
  public register(name: string): number {
    if (!this.collisionLookup.has(name)) {
      this.collisionLookup.add(name);
    } else {
      this.scene.project.logger.error({
        message: `name "${name}" has already been used for another event name.`,
        stack: new Error().stack,
      });
      return 0;
    }

    const initialTime = this.scene.project.framesToSeconds(
      this.scene.project.frame - this.scene.firstFrame,
    );
    if (!this.lookup[name]) {
      this.didEventsChange = true;
      this.lookup[name] = {
        name,
        initialTime,
        targetTime: initialTime,
        offset: 0,
        stack: new Error().stack,
      };
    } else {
      let changed = false;
      const event = {...this.lookup[name]};


Review comment (suggestion):
This might be personal preference, but how about inverting this condition and instead returning early if the name has already been used? That would allow us to get rid of one level of indentation since we can get rid of the `else` branch.

```suggestion
    if (this.collisionLookup.has(name)) {
      this.scene.project.logger.error({
        message: `name "${name}" has already been used for another event name.`,
        stack: new Error().stack,
      });
      return 0;
    }
 
    this.collisionLookup.add(name);
 
 // rest...
```

Code after:
    if (!this.lookup[name] || this.lookup[name].offset === offset) {
      return;
    }
    this.preserveTiming = preserve;
    this.lookup[name] = {
      ...this.lookup[name],
      targetTime: this.lookup[name].initialTime + offset,
      offset,
    };
    this.registeredEvents[name] = this.lookup[name];
    this.events.current = Object.values(this.registeredEvents);
    this.didEventsChange = true;
    this.scene.reload();
  }

  /**
   * Register a time event.
   *
   * @param name - The name of the event.
   *
   * @returns The absolute frame at which the event should occur.
   *
   * @internal
   */
  public register(name: string): number {
    if (this.collisionLookup.has(name)) {
      this.scene.project.logger.error({
        message: `name "${name}" has already been used for another event name.`,
        stack: new Error().stack,
      });
      return 0;
    }

    this.collisionLookup.add(name);

    const initialTime = this.scene.project.framesToSeconds(
      this.scene.project.frame - this.scene.firstFrame,
    );
    if (!this.lookup[name]) {
      this.didEventsChange = true;
      this.lookup[name] = {
        name,
        initialTime,
        targetTime: initialTime,
        offset: 0,
        stack: new Error().stack,
      };
    } else {
      let changed = false;
      const event = {...this.lookup[name]};