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

Update paint method call for FormComponent #52

Open
microshine opened this issue Mar 24, 2023 · 1 comment
Open

Update paint method call for FormComponent #52

microshine opened this issue Mar 24, 2023 · 1 comment

Comments

@microshine
Copy link
Contributor

Currently, the paint method in the FormComponent class is triggered every time a component field is changed. This behavior needs to be updated so that the paint method is called only once before saving the document. One possible solution is to track field changes in the component, iterate over all the components when the document is saved, and call paint only for those components that need it.

Proposed solution

class FormComponent {
  private _name: string;
  private _value: string;
  private _dirty: boolean = false;

  constructor(name: string, value: string) {
    this._name = name;
    this._value = value;
  }

  get name(): string {
    return this._name;
  }

  get value(): string {
    return this._value;
  }

  set value(v: string) {
    if (v !== this._value) {
      this._value = v;
      this.markDirty();
    }
  }

  private markDirty(): void {
    this._dirty = true;
  }

  public paintIfNeeded(): void {
    if (this._dirty) {
      this.paint();
      this._dirty = false;
    }
  }

  public paint(): void {
    console.log(`Painting ${this._name}`);
  }
}
@microshine
Copy link
Contributor Author

When implementing this task, it is necessary to take into account the lifespan of each component. Since each component is a wrapper around certain types of PDFDictionary, it may be necessary to cache these objects in order to provide access to the component fields and invoke the "paint" method when saving the document.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant