dm4t2 / intl-number-input

Easy input of formatted numbers based on the ECMAScript Internationalization API (Intl.NumberFormat).
https://dm4t2.github.io/intl-number-input/
MIT License
12 stars 3 forks source link

Add ability to destroy/unbind/teardown #18

Closed eirikbacker closed 1 year ago

eirikbacker commented 1 year ago

Hi! Thanks for super work - so nice to se WebAPIs utilized in this way!

Situation: I'm working in a webpage, where elements appear and disappear based on state. Currently intl-number-input only binds events, but it has no destroy/unbind/teardown method, meaning there is no way to do garbage collection/free up memory.

Solution: Add a .destroy method removing the instance and all listeners. Example API:

const numberInput = new NumberInput({
  el: document.querySelector('input'),
  options: {
    // see API reference
  }
})

// set initial value
numberInput.setValue(1234)

// Remove listeners and other references so element can be garbage collected
numberInput.destroy()
dm4t2 commented 1 year ago

Hi, thanks for your feedback!

I will look into it 👍