npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@enbock/ts-jsx

v0.1.19

Published

An simple JSX rendering based on ShadowDOMv1.

Downloads

73

Readme

TypeScript - JSX

A simple JSX rendering for Clean Code architectures.

Motivation

In Clean Code we have "program-control-flow" separated from "view-rendering-flow".

My most favorit framework is React. But for the last years was React slightly "overdosed".
It has a lot of nice features, which I not need. What I need is just rendering into DOM.

So I started in early 2022 this absolute small JSX rendering into Shadow DOM v1.

Prolog

Thanks to Uncle Bob and Software craftsmanship to turn my latest projects into a hugh success by just following the principles.

Implementing new features, changing any feature in the project, react to ideas of our customers: All is possible, just in time, without to be scary any time and without risking the success of the project.

Pre-Release

After a year of testing and searching for edge-case I decide to do the first release.

As the code currently is, I'll name it "Chaos mansion"

Getting started

Installing library

npm install --save-dev typescript @enbock/ts-jsx

As next, we need a system, which allows to compress all the code together.
Webpack is here a nice way to do so:

npm install --save-dev webpack webpack-cli webpack-dev-server ts-loader style-loader css-loader html-webpack-plugin

Use the example webpack.config.js to get a simple project start.

And testing? I'd like to use Jest (with TypeScript ts-jest) and Testing-Library as well:

npm install --save-dev jest jest-mock-extended ts-jest @testing-library/dom @testing-library/jest-dom jest-environment-jsdom

Now we need to configure the TypeScript compiler to accept react-jsx with this tiny library:

{
  "compilerOptions": {
    "jsx": "react-jsx",
    "jsxImportSource": "@enbock/ts-jsx"
  }
}

Full example of tsconfig.js

Finally, we add some start scripts in our package.json:

{
  "scripts": {
    "start": "webpack serve --open --mode development --no-open --no-live-reload --no-hot --stats-error-details",
    "build": "webpack --mode production",
    "test": "jest"
  }
}

Full example of package.json

Step 1: The first page

Let's start with a "Hello World" page.

Notice: The follow examples can be found at the example project.

Intrinsic elements

We need to declare the JSX namespace for out project. A simple generic definition will work for the start:

File: src/global.d.ts

declare namespace JSX {
    type Element = any;

    interface IntrinsicElements {
        [tag: string]: Element;
    }
}

Main program

Now we can write out first main program.
To do so, we import the Shadow Renderer:

import ShadowRenderer from '@enbock/ts-jsx/ShadowRenderer';

Now, we create the rendering:

const node: HTMLElement = ShadowRenderer.render(<div>Hello World!</div>);

at least, we need to add it to the dom tree:

document.body.append(node);

Here you find the full example of the index.tsx.

Run npm start and open the local page http://localhost:3000/

Notice: The IntelliJ may report a missing React-Import. Just disable the warning:
Disable mit React import warning

Step 2: The first component

It will be time for our first component. We want to create a simple button which alerts a "Hello":

Place: src/HelloButton/
File: src/HelloButton/ShadowDom/HelloButton.tsx

To start, we are extending our view from the Shadow-Component:

import Component from '@enbock/ts-jsx/Component';

export declare class HelloButton extends Component {
}

Now we can use the use it in the index.tsx:

import ShadowRenderer from '@enbock/ts-jsx/ShadowRenderer';
import HelloButton from './HelloButton/ShadowDom/HelloButton';

const node: HTMLElement = ShadowRenderer.render(<HelloButton/>);
document.body.append(node);

Here we are! The first shadow component: first rendering

Next:

Create a button in the component

LICENSE

MIT