Skip to content

Instantly share code, notes, and snippets.

@menosprezzi
menosprezzi / component-behavior.ts
Last active August 17, 2019 18:41
Stencil's Component Behavior
import { ComponentInterface } from '@stencil/core';
import { extendMethod } from '../lang/extend-method';
/**
* Represents a Component that implements a Behavior Modification API.
*/
export interface ComponentBase extends ComponentInterface {
/**
* The main native nativeElement from the component.
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
function syncEvent(node, eventName, newEventHandler) {
const eventNameLc = eventName[0].toLowerCase() + eventName.substring(1);
const eventStore = node.__events || (node.__events = {});
const oldEventHandler = eventStore[eventNameLc];
// Remove old listener so they don't double up.
if (oldEventHandler) {