Skip to content
This repository was archived by the owner on Mar 13, 2018. It is now read-only.

Commit e3385da

Browse files
committed
Add wrap examples
1 parent 67607e7 commit e3385da

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

README.md

+17
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,23 @@ The intent is to wrap all the DOM objects that interact with the DOM tree. For t
8888

8989
There are bound to be cases where we haven't done the wrapping for you. In those cases you can use `wrap` to create a wrapper of a native object, or `unwrap` to get the underlying native object from a wrapper. These two functions are available on the `ShadowDOMPolyfill` object.
9090

91+
ex:
92+
93+
wrap(document).addEventListener(...)
94+
unwrap(div).firstChild instanceof HTMLElement
95+
96+
If you plan to work with elements that need to be wrapped over and over, try passing a wrapped version of the element into an immediately-invoked function expression.
97+
98+
(function(document) {
99+
100+
// Now a library like jQuery can add
101+
// listeners to the wrapped document
102+
$(document).on('click', function(e) {
103+
console.log('Clicked on', e.target);
104+
});
105+
106+
})(wrap(document));
107+
91108
#### Event Retargetting
92109

93110
An important aspect of the shadow DOM is that events are retargetted to never expose the shadow DOM to the light DOM. For example.

0 commit comments

Comments
 (0)