🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

react-web-component

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-web-component - npm Package Compare versions

Comparing version

to
1.0.4-alpha

2

package.json
{
"name": "react-web-component",
"version": "1.0.3-alpha",
"version": "1.0.4-alpha",
"description": "Create Web Components with React",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -7,8 +7,32 @@ const ReactDOM = require('react-dom');

/**
* todo fix jsdoc type of app and options
* todo fix jsdoc type of app
* @param {*} app
* @param {string} tagName
* @param {Object} [options]
*/
create: function(app, tagName, options) {
create: function(app, tagName) {
let appInstance;
const lifeCycleHooks = {
attachedCallback: 'webComponentAttached',
connectedCallback: 'webComponentConnected',
disconnectedCallback: 'webComponentDisconnected',
attributeChangedCallback: 'webComponentAttributeChanged',
adoptedCallback: 'webComponentAdopted'
};
function callConstructorHook(proto) {
if (appInstance['webComponentConstructed']) {
appInstance['webComponentConstructed'].apply(appInstance, [proto])
}
}
function callLifeCycleHook(hook, params) {
const instanceParams = params || [];
const instanceMethod = lifeCycleHooks[hook];
if (instanceMethod && appInstance[instanceMethod]) {
appInstance[instanceMethod].apply(appInstance, instanceParams)
}
}
const proto = Object.create(HTMLElement.prototype, {

@@ -20,10 +44,34 @@ attachedCallback: {

const styles = getStyleElementsFromReactWebComponentStyleLoader();
for (var i in styles) {
for (let i = 0; i < styles.length; i++) {
shadowRoot.appendChild(styles[i])
}
shadowRoot.appendChild(mountPoint);
ReactDOM.render(app, mountPoint);
ReactDOM.render(app, mountPoint, function () {
appInstance = this;
callConstructorHook(proto);
callLifeCycleHook('attachedCallback');
});
retargetEvents(shadowRoot);
},
},
connectedCallback: {
value: function() {
callLifeCycleHook('connectedCallback');
},
},
disconnectedCallback: {
value: function() {
callLifeCycleHook('disconnectedCallback');
},
},
attributeChangedCallback: {
value: function(attributeName, oldValue, newValue, namespace) {
callLifeCycleHook('attributeChangedCallback', [attributeName, oldValue, newValue, namespace]);
},
},
adoptedCallback: {
value: function(oldDocument, newDocument) {
callLifeCycleHook('adoptedCallback', [oldDocument, newDocument]);
},
},
});

@@ -30,0 +78,0 @@ document.registerElement(tagName, { prototype: proto });

Sorry, the diff of this file is not supported yet