developit / Preact Cycle
Licence: mit
โป๏ธ Minimal functional Virtual DOM rendering using Preact ๐ฒ
Stars: โญ 120
Programming Languages
javascript
180406 projects - #8 most used programming language
Labels
Projects that are alternatives of or similar to Preact Cycle
Nanocomponent Adapters
๐ - Convert a nanocomponent to a component for your favourite API or library (web components, (p)react, angular)
Stars: โญ 94 (-21.67%)
Mutual labels: preact
Preact Cli Ssr
A quick demo for adding SSR to a Preact CLI app
Stars: โญ 76 (-36.67%)
Mutual labels: preact
Offline Gallery
๐ A 16kb Preact & Redux based Progressive Web App that offers an offline gallery experience of external images.
Stars: โญ 90 (-25%)
Mutual labels: preact
Dataformsjs
๐ DataFormsJS ๐ A minimal JavaScript Framework and standalone React and Web Components for rapid development of high quality websites and single page applications.
Stars: โญ 95 (-20.83%)
Mutual labels: preact
Cloudflare Worker Preact Pwa
Cloudflare worker running a Preact Progressive Web App
Stars: โญ 57 (-52.5%)
Mutual labels: preact
Colors App
๐จ A PWA for copying values from popular color palettes. Supports HEX, RGB, and HSL formats.
Stars: โญ 90 (-25%)
Mutual labels: preact
Leo
Highly Extensible, Declarative Static Site Generator
Stars: โญ 100 (-16.67%)
Mutual labels: preact
Hueify
๐กSimple controller for your Philips Hue lights, based on web technologies.
Stars: โญ 84 (-30%)
Mutual labels: preact
Preact Todomvc
๐ฃ TodoMVC done in Preact. Under 6kb and fast.
Stars: โญ 88 (-26.67%)
Mutual labels: preact
Led Matrix Simulator
๐ฎ A simple HTML5 LED Matrix Simulator for fun
Stars: โญ 96 (-20%)
Mutual labels: preact
Chirrapp
Chirr App splits text into tweets and posts it as a thread
Stars: โญ 75 (-37.5%)
Mutual labels: preact
Razzle
โจ Create server-rendered universal JavaScript applications with no configuration
Stars: โญ 10,547 (+8689.17%)
Mutual labels: preact
Enzyme Adapter Preact Pure
Preact adapter for the Enzyme UI testing library
Stars: โญ 62 (-48.33%)
Mutual labels: preact
Jetpack
๐ Jetpack โ Webpack made more convenient.
Stars: โญ 1,326 (+1005%)
Mutual labels: preact
Preact Scroll Viewport
Preact Component that renders homogeneous children only when visible
Stars: โญ 118 (-1.67%)
Mutual labels: preact
Next Todos
200 lines realtime todos app powered by next.js, preact, jet, redux and now
Stars: โญ 117 (-2.5%)
Mutual labels: preact
preact-cycle
Minimal functional (-reactive) Virtual DOM rendering using Preact.
Simple Example
View this example on esnextb.in
import { render, h } from 'preact-cycle';
/** @jsx h */
const App = ({ value, mutation }) => (
<div>
<p>Value: { value }</p>
<button onClick={ mutation('value', v => v+1) }>Increment</button>
</div>
);
render(App, { value: 0 });
To-Do List Example
A simple example, where reducers are just pure functions.
Note that TOGGLE
mutates state in-place, which works fine but is discouraged.
import { render, h } from 'preact-cycle';
/** @jsx h */
const ADD = ({ text, todos, ...state }) => ({
todos: todos.concat({ text }),
text: '',
...state
});
const TOGGLE = (state, todo) => {
todo.done = !todo.done;
return state;
};
const REMOVE = ({ todos, ...state }, todo) => ({
todos: todos.filter( t => t!==todo ),
...state
});
const TodoList = ({ text, todos, mutate, mutation }) => (
<div>
<form onSubmit={mutation(ADD)} action="javascript:">
<input value={text} onInput={e => mutate('text', e.target.value)} />
<button action="submit">Add</button>
</form>
<ul>
{ todos.map( todo => (
<li onClick={mutation(TOGGLE, todo)}>
<input type="checkbox" checked={todo.done} readonly />
<p>{ todo.text }</p>
<a onClick={mutation(REMOVE, todo)}>โ</a>
</li>
))}
</ul>
</div>
);
render(TodoList, { todos: [] }, document.body);
Component-Based Example
Normal preact components still work great with preact-cycle. As of v0.4
, mutate()
and mutation()
are conveniently available as context properties, which means they are automatically passed down through the VDOM tree. For pure functional components, context is simply passed as a second argument.
A component-based variant of the previous To-Do List example follows, using pure functions and context.
import { h, render } from 'preact-cycle';
/** @jsx h */
/** initial data to populate the store */
const INITIAL_DATA = {
todos: [
{ text:'Type some text' },
{ text:'...then hit [enter]' },
{ text:'Now you\'re productive!' }
]
};
/** Appends a new todo item */
const ADD = ({ todos, text, ...state }) => ({
todos: todos.concat({ text }),
text: '',
...state
});
/** Remove the given todo item */
const REMOVE = ({ todos, ...state }, todo) => ({
todos: todos.filter(t => t!==todo),
...state
});
/** Toggles the given todo item as done */
const TOGGLE = (state, todo) => {
todo.done = !todo.done;
};
/** a simple helper to derive a mutated value from an event */
let fromEvent = (prev, e) => e.target.value;
/** The todo list app */
const App = ({ text, todos }) => (
<div id="app">
<Form text={text} />
<ul>{ todos.map( todo => (
<Item todo={todo} />
)) }</ul>
</div>
);
/** New todo entry form */
const Form = ({ text }, { mutation }) => (
<form onSubmit={mutation(ADD)} action="javascript:">
<input placeholder="New item..."
value={text}
onInput={mutation('text', fromEvent)} />
</form>
);
/** A single todo list item */
const Item = ({ todo }, { mutation }) => (
<li onClick={mutation(TOGGLE, todo)} class={{ done: todo.done }}>
<input type="checkbox" checked={todo.done} readonly />
<a onClick={mutation(REMOVE, todo)}>โ</a>
<p>{ todo.text }</p>
</li>
);
// Kick off the cycle!
render(App, INITIAL_DATA, document.body);
License
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected]