@danielkalen/simplybind
Version:
Magically simple, framework-less one-way/two-way data binding for frontend/backend in ~5kb.
30 lines (29 loc) • 1.86 kB
text/coffeescript
###*
* There is a bug in webkit/blink engines in which native attributes/properties
* of DOM elements are not exposed on the element's prototype and instead is
* exposed directly on the element instance; when looking up the property descriptor
* of the element a data descriptor is returned instead of an accessor descriptor
* (i.e. descriptor with getter/setter) which means we are not able to define our
* own proxy getter/setters. This was fixed only in April 2015 in Chrome v43 and
* Safari v10. Although we won't be able to get notified when the objects get
* their values set, we would at least provide working functionality lacking update
* listeners. Since v1.14.0 HTMLInputElement::value bindings invoke the original
* getter and setter methods in Binding::setValue(), and since we want to avoid
* increasing the amount of logic present in Binding::setValue() for performance
* reasons, we patch those setters here. We clone the target element and check for
* the existence of the target property - if it exists then it indicates the target
* property is a native property (since only native properties are copied over in
* Element::cloneNode). This patching is only for native properties.
*
* https://bugs.webkit.org/show_bug.cgi?id=49739
* https://bugs.webkit.org/show_bug.cgi?id=75297
* https://bugs.chromium.org/p/chromium/issues/detail?id=43394
* https://bugs.chromium.org/p/chromium/issues/detail?id=431492
* https://bugs.chromium.org/p/chromium/issues/detail?id=13175
* https://developers.google.com/web/updates/2015/04/DOM-attributes-now-on-the-prototype-chain
###
if requiresDomDescriptorFix and _.isDom and _.property of object.cloneNode(false)
_.origDescriptor = shouldWriteLiveProp = false
_.isLiveProp = true
_.origGetter = ()-> _.object[_.property]
_.origSetter = (newValue)-> _.object[_.property] = newValue