Skip to content

Methods & Utilities

George Treviranus edited this page Mar 25, 2022 · 6 revisions

Because not all technical designs in the wild can service every use-case, here are some methods to manually handle renders, type checking, and the like. They are a mix of class methods and functions exported by the package.

requestRender (instance method)

Manually schedules an asynchronous render.

To track the results of the manual render, you can set an internal property and check its value via onUpdate like so:

onUpdate() {
  if (this._renderRequested) {
    // Set tracker to false to prevent unrelated renders
    // from reaching this block by accident
    this._renderRequested = false
    doSomeOtherStuff()
  }
}

someCallbackMethod() {
  this.doSomeStuff()

  // Set tracker just before render is called
  this._renderRequested = true
  this.requestRender()
}

See more about lifecycle methods.

elementId (instance property)

This is an internal accessor that returns a unique identifier. E.g., 252u296xs51k7p6ph6v.

You can access the id using the bulba-id attribute on the host.

validateType(thisArg, propertyName, value, expectedType) (named export)

UPDATED: This was an instance method in versions 0.7.x and lower..

Compares your property type. Useful if you are doing computations or other manipulations involving a reflected property.

Use this method with caution for reflected properties. You run the risk of XSS vulnerabilities. Be sure to sanitize the value first.