All Projects → jamesbirtles → fpreact

jamesbirtles / fpreact

Licence: MIT license
fpreact provides an alternative api for creating preact components, heavily inspired by elm.

Programming Languages

typescript
32286 projects

Labels

Projects that are alternatives of or similar to fpreact

xoid
Framework-agnostic state management library designed for simplicity and scalability ⚛
Stars: ✭ 96 (+104.26%)
Mutual labels:  preact
maji
Maji is a framework to build great hybrid mobile apps.
Stars: ✭ 18 (-61.7%)
Mutual labels:  preact
preact-native
client native implement of preactjs(https://preactjs.com/)
Stars: ✭ 17 (-63.83%)
Mutual labels:  preact
preact-cli-plugin-typescript
Adds TypeScript support to preact-cli ⚡
Stars: ✭ 49 (+4.26%)
Mutual labels:  preact
moonwave
🌗 A small web application framework.
Stars: ✭ 14 (-70.21%)
Mutual labels:  preact
shopping-list-preact-pouchdb
Shopping List is an Offline First demo Progressive Web App built using Preact and PouchDB.
Stars: ✭ 18 (-61.7%)
Mutual labels:  preact
preact-css-transition-group
Apply CSS transitions when adding or removing Preact components/elements
Stars: ✭ 60 (+27.66%)
Mutual labels:  preact
tailwind-layouts
Collection of Tailwind Layouts
Stars: ✭ 53 (+12.77%)
Mutual labels:  preact
agrippa
The CLI for frontend component generation
Stars: ✭ 555 (+1080.85%)
Mutual labels:  preact
anonymous-web
💬 A PreactJS powered progressive web (chat) application (Not active)
Stars: ✭ 28 (-40.43%)
Mutual labels:  preact
ninetales
An experimental framework raising the performance bar
Stars: ✭ 27 (-42.55%)
Mutual labels:  preact
browser-extension
Browser Extension Template with ESbuild builds, support for React, Preact, Typescript, Tailwind, Manifest V3/V2 support and multi browser build including Chrome, Firefox, Safari, Edge, Brave.
Stars: ✭ 535 (+1038.3%)
Mutual labels:  preact
go-preact-starter
Starter for combining Go and Preact in any web project.
Stars: ✭ 19 (-59.57%)
Mutual labels:  preact
preact-wp
No description or website provided.
Stars: ✭ 12 (-74.47%)
Mutual labels:  preact
preact-cli-plugin-netlify
Preact cli plugin for generating h2push headers and redirects rules for netlify
Stars: ✭ 25 (-46.81%)
Mutual labels:  preact
preact-photon-electron-quick-start
Demo desktop app built with Electron using the Preact-Photon UI library
Stars: ✭ 32 (-31.91%)
Mutual labels:  preact
rainbow-explorer
🌈 A 20kb Preact & Redux based Progressive Web App that translates real life color to digital color.
Stars: ✭ 26 (-44.68%)
Mutual labels:  preact
preact-journal
14k offline-capable journaling PWA using preact, node, MySQL, and IndexedDB.
Stars: ✭ 33 (-29.79%)
Mutual labels:  preact
luck-or-hardwork
Simple web-app to provide illustration about a take on luck and hard work.
Stars: ✭ 29 (-38.3%)
Mutual labels:  preact
merkur
tiny extensible javascript library for front-end microservices
Stars: ✭ 45 (-4.26%)
Mutual labels:  preact

fpreact (Functional Preact)

fpreact provides an alternative api for creating preact components, heavily inspired by elm. The api includes redux style state management and lends itself to functional programming, avoiding the use of this

It has first class TypeScript support (it's written in it!), but also works great with regular JavaScript.

Install

npm i -S fpreact preact

Example

Find more in the examples folder.

TypeScript

import { h, render, component, Message } from 'fpreact';

enum Msg {
    UpdateName,
}

interface Model {
    name: string;
}

type Messages = Message<Msg.UpdateName, string>;

const Greet = component<Model, Messages>({
    update(model = { name: 'world' }, msg) {
        switch (msg.kind) {
            case Msg.UpdateName:
                return { ...model, name: msg.value };
        }

        return model;
    },

    view(model, dispatch) {
        return (
            <div>
                <h1>Hello, {model.name}</h1>
                <label>
                    <span>Name:</span>
                    <input value={model.name} onInput={dispatch(Msg.UpdateName)} />
                </label>
            </div>
        );
    },
});

render(<Greet />, document.body);

JavaScript (ES6 + JSX)

import { h, render, component } from 'fpreact';

const Msg = {
    // You don't have to use a number here.
    // You could just as easily use "UPDATE_NAME" or anything else if you desire,
    // just make sure each item has a unique value
    UpdateName: 0,
};

const Greet = component({
    update(model = { name: 'world' }, msg) {
        switch (msg.kind) {
            case Msg.UpdateName:
                return { ...model, name: msg.value };
        }

        return model;
    },

    view(model, dispatch) {
        return (
            <div>
                <h1>Hello, {model.name}</h1>
                <label>
                    <span>Name:</span>
                    <input value={model.name} onInput={dispatch(Msg.UpdateName)} />
                </label>
            </div>
        );
    },
});

render(<Greet />, document.body);

JavaScript (ES5)

'use strict';

var fpreact = require('fpreact');

var Msg = {
    UpdateName: 0,
};

var Greet = fpreact.component({
    update: function(model, msg) {
        if (model == null) {
            return { name: 'world' };
        }

        switch (msg.kind) {
            case Msg.UpdateName:
                return Object.assign({}, model, { name: msg.value });
        }

        return model;
    },

    view: function(model, dispatch) {
        return fpreact.h(
            'div',
            null,
            fpreact.h('h1', null, 'Hello, ', model.name),
            fpreact.h(
                'label',
                null,
                fpreact.h('span', null, 'Name:'),
                fpreact.h('input', { value: model.name, onInput: dispatch(Msg.UpdateName) }),
            ),
        );
    },
});

fpreact.render(fpreact.h(Greet, null), document.body);
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].