How to use haunted - 10 common examples

To help you get started, we’ve selected a few haunted examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github geocine / web-components-hooks-demo / src / context / shop-context.js View on Github external
import { useContext, component, createContext } from "haunted";

// https://github.com/matthewp/haunted/issues/75
const createConsumer = Context =>
  component(
    function({ render }) {
      const context = useContext(Context);

      return render(context);
    },
    HTMLElement,
    { useShadowDOM: false }
  );

const ShopContext = createContext({
  products: [],
  cart: [],
  addProductToCart: () => {},
  removeProductFromCart: () => {}
});

ShopContext.Consumer = createConsumer(ShopContext);

customElements.define("shop-provider", ShopContext.Provider);
customElements.define("shop-consumer", ShopContext.Consumer);
github kjartanm / microfrontends / packages / login / src / index.js View on Github external
<h3>Log in or register an account!</h3>
                    
                    

                     update({customerid: '45645645'})}&gt;Log in
                    Register
                            
                `
            :html`<h2>(You are already logged in, go to the <a href="/pizzamenu">pizza menu</a> and order some pizzas :)</h2>`

        }
        
    `;
}
customElements.define('x-login', component(LoginFE, { useShadowDOM: false }));
github geocine / web-components-hooks-demo / src / context / shop-context.js View on Github external
const createConsumer = Context =>
  component(
    function({ render }) {
      const context = useContext(Context);

      return render(context);
    },
    HTMLElement,
    { useShadowDOM: false }
  );
github geocine / web-components-hooks-demo / src / context / GlobalState.js View on Github external
`;
};

export default GlobalState;

customElements.define("global-state", component(GlobalState));
github geocine / web-components-hooks-demo / src / components / MainNavigation.js View on Github external
Products
          
          <li>
            Cart (${cartItemNumber})
          </li>
        
      
    
  `;
};

export default MainNavigation;

customElements.define(
  "main-navigation",
  component(MainNavigation, HTMLElement, { useShadowDOM: false })
);
github geocine / web-components-hooks-demo / src / router.js View on Github external
.on(route.path, params => {
          if (!customElements.get(route.tag)) {
            customElements.define(
              route.tag,
              component(route.page, HTMLElement, { useShadowDOM: false })
            );
          }
          Router.inject(route.tag);
        })
        .resolve();
github open-wc / open-wc / packages / create / src / generators / app-haunted / templates / static / components / page-main / src / PageMain.js View on Github external
${logo}
    <h1>${title}</h1>
    <p>Edit <code>src/MyApp.js</code> and save to reload.</p>
    <a rel="noopener noreferrer" href="https://open-wc.org/developing/#examples" class="app-link">
      Code examples
    </a>
  `;
}

export const PageMain = component(PageMainElement);
github geocine / web-components-hooks-demo / src / components / RouterLink.js View on Github external
color: var(--color-active, black);
      }
    
    <a class="${active ?" href="${element.to}">
      
    </a>
  `;
};

RouterLink.observedAttributes = ["to"];

customElements.define("router-link", component(RouterLink));
github geocine / web-components-hooks-demo / src / context / shop-context.js View on Github external
function({ render }) {
      const context = useContext(Context);

      return render(context);
    },
    HTMLElement,
github kjartanm / microfrontends / packages / login / src / index.js View on Github external
function LoginFE() {
    const [customerid, setUserid] = useState(null);
    useEffect(() =&gt; {
        import('./kernel').then((Module) =&gt; {
            Module.onKernelKey('change:customerid', _customerid =&gt; {
                setUserid(_customerid);
            });
            setUserid(Module.getSharedKernel('customerid'));
        })
      }, []);    

    const update = (newState) =&gt; {
        import('./kernel').then((Module) =&gt; {
            Module.updateSharedKernel(newState);
        })
    }    
    return html`
    <section class="wc-module">
        </section>

haunted

Hooks for web components

BSD-2-Clause
Latest version published 3 years ago

Package Health Score

66 / 100
Full package analysis