Giter VIP home page Giter VIP logo

swrf's Introduction

S.W.R.F.

๐ŸŒŠ Speedy Web Reactive Framework ๐Ÿ–๏ธ

  • Pronouced as surf, /sษ™rf/
  • Truly reactive
  • We love functions
  • 90% tree-shakeable
  • All in one Ethernet frame

๐Ÿšง Under development, PRs are welcomed!

  • Unit + Integration Testing
  • Better docs
  • Optimize even more for size and speed (leaner code)
  • Finish SSR + Vite plugin @swrf/ssr
  • Server-side real-time refs
  • Smarter HMR without transforms
  • GitHub actions
  • Better README with badges
  • Test using webpack (now only vite is supported)

๐Ÿ„โ€โ™‚๏ธ Start Swrfing!

npm i @swrf/core
import { elements, attributes } from "@swrf/core";
const { button } = elements;
const { onclick } = attributes;
function counter() {
	const count = ref(0);
	const increment = () => count(count() + 1);
	return button(onclick(increment), "count=", count);
}
render();

Or using JSX with transpiler magic:

/* @jsx h */
import { h } from "@swrf/core";
function Counter() {
	const count = ref(0);
	const increment = () => count(count() + 1);
	return <button onclick={increment}>count={count}</button>;
}

Bundle Sizes

vite v3.2.3 building for production...
โœ“ 12 modules transformed.
dist/swrf.cjs.js   2.14 KiB / gzip: 1.02 KiB
dist/swrf.es.js   3.08 KiB / gzip: 1.18 KiB
dist/swrf.iife.js   2.09 KiB / gzip: 1.03 KiB
dist/swrf.umd.js   2.26 KiB / gzip: 1.11 KiB
vite v3.2.3 building for dev...
โœ“ 16 modules transformed.
dist/swrf.dev.es.js   3.50 KiB / gzip: 1.38 KiB

Overview

  • ref is base of this library
  • fx observes changes in refs called synchronously within it
import { ref, fx } from "@swrf/core";
const count = ref(0); // initial value of 0
fx(() => {
	console.log("count=", count()); // prints count=0
});
count(10); // prints count=10
count(count() + 1); // prints count=11
  • Get is a union type of the value or a function that returns the value

  • get gets the value from a Get

const count = ref(0); // this extends a Get, so...
console.log(get(count)); // prints 0
  • h is a mostly hyperscript compatible function that creates reactive elements
    • attributes are Get<Record<string, Get>>
      • style can be string | Record<string, Get<string>>
      • classList is Record<string, Get<boolean>>, if true include in list, otherwise, exclude
    • children are Get<Node>
import { h } from "@swrf/core";
const color = ref("red");
const div = h("div", { style: { color } }, "I am red");
  • map maps over Get<any[]> returning a Fragment and updates the children efficiently according to changes in the provided array

  • render is not 100% needed as h returns HTMLElement. However, it does enable some HMR features.

Hot Reload

This library has somewhat of a hot reload module feature, but it is limited.

  • Only refs are kept, everything else is reloaded
  • Rerenders even unaffected elements
  • Needs render-time deterministic components (no Math.random)

However, on the bright side:

  • No transpiler magic
  • No plugins, only need import.meta.hot.accept(() => {}) next to render.

Contribute

Please :)

  • Monorepo using npm
  • Tests
  • Thank you!

License

MIT. Wei (weisrc)

swrf's People

Contributors

weisrc avatar

Stargazers

stagas avatar Serhiy Fedurtsya avatar

Watchers

 avatar

swrf's Issues

Unable to iterate over elements to render list.

This is more of a question that a proper issue.
Is there a way to render out lists of elements?

I have tried the following:
image
With no result.

Thanks heaps!
Jayman.

EDIT: I didn't read the docs properly... I have found the map function to do what I wanted! Cheers, that is my fault. Closing the issue now.

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.