Giter Club home page Giter Club logo

refuse's Introduction

Refuse npm version

Refuse The name of refuse comes from its main action: fuse (join or blend) multiple components to form a single working app. Fun fact: it also means trash, or refers to the action of being not willing to do something in English)

Note: This library is a work-in-progress. Some features are not available yet. See Feature lists for more details.

Built with WeBuild From Vietnam with <3

Key points:

  • Same modern API as React.js
  • Full typescript support
  • No JSX
  • No build tool, no bundler, no transpiler required

Different from React:

  • No class component supported
  • No longer need to return single root element, so Fragment use cases now narrow down to key-ed diff only.
  • Ref works on component as well, and auto assign to the root element of the component.
    • If the component have multiple root, it will point to the DocumentFragment, which will be empty (and useless) after moving its child to the DOM. Read more
    • (Don't need to wrap component in forwardRef, just) use the second parameter of component to assign it to a specific element.
  • Component can return number[],string[],fuse[] or even string[][] to render multiple elements.
    • Component can return null,undefined,false to skip rendering.

About syntax:

  • Spread props: <div ...${props}> instead of <div {...props}>
  • HTML's quotes now optional: <div class=foo>
  • Shorthand for component end-tags: <${Foo}>bar<//>
  • Comment: <!-- comment -->

Syntax highlighting support:

  • Intellij IDEA (WebStorm,...): supported by default
  • VSCode: lit-html

Have you ever wondered how React.js works internally? Reading the source code of refuse is a good way to learn how it works.

Try it out now

Whac-a-mole with Refuse

Whac-a-mole with Refuse

With Vite

Without bundler

Getting started

npm i -S refusejs
import {useState, fuse,render} from "refusejs"
import type {RefuseComponent} from "refusejs"

interface Props {
  someThing: string
}

const Component: RefuseComponent<Props> = (props, ref) => {
	const [state, setState] = useState(0)

	useEffect(() => {
		const timer = setInterval(() => setState(state + 1), 1000)
		return () => clearInterval(timer)
	}, [])

	return fuse`
		<div class=foo ...${props} foo=${state}>
			${props.children}
			<${A}>Something...<//>
			<button onclick=${() => setState(state + 1)}>Click me</button>
			${state > 300 && fuse`<div>
				Yeah
			</div>`}
			<!-- some comment -->
		</div>
	`
}

render(Component, document.getElementById('root'))

Or

<script src="https://unpkg.com/refusejs@latest/dist/refuse.umd.js"></script>
<script>
	const {render, fuse} = Refuse;
	render(
		() => fuse`
			<div>
				<h1>Hello, world!</h1>
				<p>It's a beautiful day.</p>
			</div>
		`,
		document.getElementById('root2')
	);
</script>

or

<script type="module">
	import * as Refuse from 'https://unpkg.com/refusejs@latest/dist/refuse.modern.js'; // Support only modern browsers
	// import * as Refuse from 'https://unpkg.com/refusejs@latest/dist/refuse.module.js'; // Support all browsers

	Refuse.render(
		() => Refuse.fuse`
			<div>
				<h1>Hello, world!</h1>
				<p>It's a beautiful day.</p>
			</div>
		`,
		document.getElementById('root')
	);
</script>

Feature lists:

  • TypeScript
  • Jsx to HyperScript using htm
  • render
  • Custom components with props
  • Custom components with children
  • useState
  • Automatic state update batching
  • flushSync
  • useEffect with cleanup
  • Unmount components
  • Component Tree
  • Render: dirty mark, compare
  • Render: keys
  • Conditional rendering
  • DOM diffing/patching
  • useLayoutEffect
  • useMemo, useCallback, useRef
  • memo
  • Fragment
  • JSX Embedding Expression
  • DOM Ref
  • React.forwardRef
  • Render multiple Refuse instances
  • Error Boundary
  • Concurrent Mode, useTransition
  • useContext
  • useReducer
  • Test utils, write tests
  • Portal
  • Server-side rendering
  • Synthetic Event
  • Devtools, debugger, HMR - Hot reload
  • Router
  • useDeferredValue
  • Suspense
  • useImperativeHandle
  • useDebugValue
  • useId
  • useSyncExternalStore
  • Dynamic import, React.lazy
  • Production build
  • Profiler
  • Linter
  • Type checker on tagged template
  • useEvent

Development

Watch refuse package

npm i --lockfile-only
npm link
npm run dev

Run example1

cd demo/example1
npm i --lockfile-only
npm link refusejs
npm run dev

And follow instructions.

refuse's People

Contributors

huynhducduy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.