Skip to content

Commit

Permalink
refactor!: v1, add types, react 18 support (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyJasonBennett authored Sep 4, 2022
1 parent 497fbe9 commit 4efdf62
Show file tree
Hide file tree
Showing 18 changed files with 863 additions and 4,984 deletions.
11 changes: 11 additions & 0 deletions .github/dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions .github/light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: CI
on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
build-test-lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2

- name: Install dependencies
run: yarn install

- name: Check build health
run: yarn build

- name: Run tests
run: yarn test --silent
56 changes: 10 additions & 46 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,48 +1,12 @@
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/

# Dependency directories
node_modules/
jspm_packages/

# TypeScript cache
*.tsbuildinfo

# Optional eslint cache
.eslintcache

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# pnpm lock

pnpm-lock.yaml

node_modules
dist

# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"semi": false,
"trailingComma": "es5",
"trailingComma": "all",
"arrowParens": "always",
"singleQuote": true,
"tabWidth": 2,
"printWidth": 120
Expand Down
21 changes: 0 additions & 21 deletions .size-snapshot.json

This file was deleted.

21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020-2022 Poimandres

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[![Size](https://img.shields.io/bundlephobia/minzip/react-nil?label=gzip&style=flat&colorA=000000&colorB=000000)](https://bundlephobia.com/package/react-nil)
[![Version](https://img.shields.io/npm/v/react-nil?style=flat&colorA=000000&colorB=000000)](https://npmjs.com/package/react-nil)
[![Downloads](https://img.shields.io/npm/dt/react-nil.svg?style=flat&colorA=000000&colorB=000000)](https://npmjs.com/package/react-nil)
[![Twitter](https://img.shields.io/twitter/follow/pmndrs?label=%40pmndrs&style=flat&colorA=000000&colorB=000000&logo=twitter&logoColor=000000)](https://twitter.com/pmndrs)
[![Discord](https://img.shields.io/discord/740090768164651008?style=flat&colorA=000000&colorB=000000&label=discord&logo=discord&logoColor=000000)](https://discord.gg/poimandres)

<p align="left">
<a id="cover" href="#cover">
<picture>
<source media="(prefers-color-scheme: dark)" srcset=".github/dark.svg">
<img style="white-space:pre-wrap" alt="There are legitimate use cases for null components or logical components.&#10&#10A component has a lifecycle, local state, packs side-effects into useEffect, memoizes calculations in useMemo, orchestrates async ops with suspense, communicates via context, maintains fast response with concurrency. And of course — the entire React ecosystem is available." src=".github/light.svg">
</picture>
</a>
</p>

#### Nothing to see here ...

Quite so. This package allows you to bring React's high-level component abstraction to Node or wherever you need it. Why not manage your REST endpoints like routes on the client, users as components with mount/unmount lifecycles, self-contained separation of concern, and clean side effects? Suspense for requests, etc.

You can try a small demo here: https://codesandbox.io/s/react-nil-mvpry

#### How does it work?

```jsx
import * as React from 'react'
import { render } from 'react-nil'

function Foo() {
const [active, set] = React.useState(false)
React.useEffect(() => void setInterval(() => set((a) => !a), 1000), [])
console.log(active)

// This is a logical component without a view, it renders nothing,
// but it has a real lifecycle and is managed by React regardless.
return null
}

render(<Foo />)
```
14 changes: 0 additions & 14 deletions img/nil.svg

This file was deleted.

80 changes: 36 additions & 44 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,63 +1,55 @@
{
"name": "react-nil",
"version": "0.0.3",
"description": "react null renderer, a react custom renderer that renders nothing but logical components",
"main": "dist/index.cjs.js",
"module": "dist/index.js",
"sideEffects": false,
"scripts": {
"build": "rollup -c",
"prepublishOnly": "npm run build",
"test": "echo no tests yet"
},
"version": "1.0.0",
"description": "react nil, a react custom renderer that renders nothing but logical components",
"keywords": [
"react",
"null",
"nil",
"renderer",
"node"
],
"author": "Paul Henschel",
"author": "Paul Henschel (https://github.com/drcmda)",
"maintainers": [
"Gianmarco Simone (https://github.com/gsimone)",
"Stephen Corwin (https://github.com/stephencorwin)",
"Cody Bennett (https://github.com/codyjasonbennett)"
],
"homepage": "https://github.com/pmndrs/react-nil",
"repository": "https://github.com/pmndrs/react-nil",
"license": "MIT",
"files": [
"dist/*",
"src/*"
],
"types": "./dist/index.d.ts",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"exports": {
"types": "./dist/index.d.ts",
"require": "./dist/index.js",
"import": "./dist/index.mjs"
},
"sideEffects": false,
"devDependencies": {
"@ampproject/rollup-plugin-closure-compiler": "^0.26.0",
"@babel/core": "7.11.0",
"@babel/plugin-proposal-class-properties": "^7.10.4",
"@babel/plugin-transform-modules-commonjs": "7.10.4",
"@babel/plugin-transform-parameters": "7.10.5",
"@babel/plugin-transform-runtime": "7.11.0",
"@babel/plugin-transform-template-literals": "7.10.5",
"@babel/preset-env": "7.11.0",
"@babel/preset-react": "7.10.4",
"@babel/preset-typescript": "^7.10.4",
"@rollup/plugin-babel": "^5.2.0",
"@rollup/plugin-commonjs": "^15.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"husky": "^4.2.5",
"lint-staged": "^10.2.11",
"prettier": "^2.0.5",
"react": "^16.13.1",
"@types/node": "^18.7.14",
"@types/react": "^18.0.17",
"react": "^18.2.0",
"rimraf": "^3.0.2",
"rollup": "^2.26.10",
"rollup-plugin-size-snapshot": "^0.12.0",
"rollup-plugin-terser": "^7.0.2"
"suspend-react": "^0.0.8",
"typescript": "^4.7.4",
"vite": "^3.0.9",
"vitest": "^0.22.1"
},
"dependencies": {
"react-reconciler": "^0.25.1",
"scheduler": "^0.20.2"
"@types/react-reconciler": "^0.26.7",
"react-reconciler": "^0.27.0"
},
"peerDependencies": {
"react": ">=16"
"react": ">=18.0"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{js,jsx,ts,tsx}": [
"eslint --fix"
]
"scripts": {
"build": "rimraf dist && vite build && tsc",
"test": "vitest run"
}
}
32 changes: 0 additions & 32 deletions readme.md

This file was deleted.

58 changes: 0 additions & 58 deletions rollup.config.js

This file was deleted.

Loading

0 comments on commit 4efdf62

Please sign in to comment.