All Projects â†’ KidkArolis â†’ moonwave

KidkArolis / moonwave

Licence: other
🌗 A small web application framework.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to moonwave

Hydux
A light-weight type-safe Elm-like alternative for Redux ecosystem, inspired by hyperapp and Elmish
Stars: ✭ 216 (+1442.86%)
Mutual labels:  preact
hyperapp-example
hyperapp example
Stars: ✭ 14 (+0%)
Mutual labels:  preact
preact-wp
No description or website provided.
Stars: ✭ 12 (-14.29%)
Mutual labels:  preact
React
MOVED TO https://github.com/myitcv/x/blob/master/react/_doc/README.md
Stars: ✭ 234 (+1571.43%)
Mutual labels:  preact
blurhash-as
Blurhash implementation in AssemblyScript
Stars: ✭ 26 (+85.71%)
Mutual labels:  preact
preact-transitioning
Preact components for easily implementing basic CSS animations and transitions
Stars: ✭ 35 (+150%)
Mutual labels:  preact
Styled Loaders
Loaders Built with Preact and Styled Components
Stars: ✭ 212 (+1414.29%)
Mutual labels:  preact
PreactSimpleStarter
PWA Simple Starter with Preact, Preact-mdl and Webpack2 🔥🔥🔥
Stars: ✭ 65 (+364.29%)
Mutual labels:  preact
vitext
The Next.js like React framework for better User & Developer experience!
Stars: ✭ 376 (+2585.71%)
Mutual labels:  preact
xoid
Framework-agnostic state management library designed for simplicity and scalability âš›
Stars: ✭ 96 (+585.71%)
Mutual labels:  preact
Rex Tils
Type safe utils for redux actions, epics, effects, react/preact default props, various type guards and TypeScript utils, React util components
Stars: ✭ 245 (+1650%)
Mutual labels:  preact
preact-cli-sw-precache
Preact cli plugin for configuring sw-precache
Stars: ✭ 19 (+35.71%)
Mutual labels:  preact
preact-css-transition-group
Apply CSS transitions when adding or removing Preact components/elements
Stars: ✭ 60 (+328.57%)
Mutual labels:  preact
Facebook Political Ads
Monitoring Facebook Political Ads
Stars: ✭ 215 (+1435.71%)
Mutual labels:  preact
preact-cli-plugin-typescript
Adds TypeScript support to preact-cli âš¡
Stars: ✭ 49 (+250%)
Mutual labels:  preact
Preact Custom Element
Wrap your component up as a custom element
Stars: ✭ 212 (+1414.29%)
Mutual labels:  preact
preact-route-async
Easy asynchronous loading for your router components. For 440B.
Stars: ✭ 36 (+157.14%)
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 (+3721.43%)
Mutual labels:  preact
ninetales
An experimental framework raising the performance bar
Stars: ✭ 27 (+92.86%)
Mutual labels:  preact
preact-photon-electron-quick-start
Demo desktop app built with Electron using the Preact-Photon UI library
Stars: ✭ 32 (+128.57%)
Mutual labels:  preact

🌗 Moonwave

Moonwave is a small framework for building web applications with JavaScript.

Moonwave is 100 lines of code, because it combines an existing set of composable libraries.

Each of these libraries is independent and can be useful on their own. Moonwave is just one, simple way to combine the three for common cases.

If Moonwave doesn't quite fit your needs as your application grows, you can combine the three libraries, or others, in your own way and use Moonwave as a reference implementation.

Usage

yarn add moonwave

Example

const Preact = require('preact')
const { moonwave } = require('moonwave/preact')

// each route maps to a Preact component
const routes = [
  ['/', MainView]
]

// actions is how we update application state
const actions = {
  update: (get, split, title) => {
    split({ title })
  }
}

// evolve is a flexible hook for implementing custom
// action strategies, such as modularising or namespacing
// this implementation calls the actions we declared above
const evolve = (get, split, action) => {
  actions[action.type](get, split, action.payload)
}

// the preact component receives full application state
// and a `split` function for dispatching actions or updates
// use ConnectAtom component to map state/split to props
function MainView ({ state, split }) {
  return (
    <div>
      <h1>Title: {state.title}</h1>
      <input type='text' value={state.title} onInput={update} />
    </div>
  )

  function update (e) {
    split('update', e.target.value)
  }
}

// assemble all the pieces
moonwave()
  .state({ title: 'Default title' })
  .evolve(evolve)
  .routes(routes)
  .mount(document.body)

This example application uses preact and will compile to around 6KB. The individual components are around:

preact        3.5KB
tiny-atom     0.5KB
space-router  1.5KB
example-app   0.5KB
-------------------
              6.0KB

API

const app = moonwave(options)

Create an app. Available options are:

  • store.merge - custom state merge strategy, default implementation is (state, update) => Object.assign({}, state, update).
  • store.debug - a debug hook. Set to debug: require('moonwave/log') for console logger or debug: require('moonwave/devtools') for integration with Redux dev tools.
  • router.mode - one of history, hash, memory. Default is history.
  • router.interceptLinks - whether clicks on links are automatically handled by the router. Default is true.
  • router.qs - custom query string parser. Object of shape { parse, stringify }.

See tiny-atom docs for more information on the store. See space-router docs for more information on the router.

app.state()

Provide initial state.

app.state({})
app.state({ count: 0 })
app.state(Immutable.Map({})) // note: in this case, you'll need to provide a custom store.merge function

app.evolve()

Provide a function of signature (get, split, action) that will receive all actions that were split by the app.

Note: think of split as dispatch if you're familiar with that.

app.evolve((get, split, action) => {
  actions[action.type](get, split, action.payload)
})

app.evolve(async (get, split, action) => {
  switch (action.type) {
    case 'increment':
      split({ count: get().count + 1 })
      break
    case 'decrement':
      split({ count: get().count - 1 })
      break
    case 'fetch':
      split({ loading: true })
      const res = await axios.get('/data')
      split({ items: res.data, loading: false })
      break;
  }
})

app.actions()

Provide a map of actions. Can be used instead of the evolve for common cases.

app.actions({
  increment: (get, split, x) => {
    split({ count: get().count + x })
  },
  decrement: (get, split, x) => {
    split({ count: get().count - x })
  }
})

If both app.actions() and app.evolve() is used, the actions provided is passed as the 4th argument to the evolve function.

app.routes()

Provide an array of routes. An optional second argument can be used for a custom onTransition implementation.

// if you don't need routing
app.routes([
  ['*', SinglePage]
])

// common case
app.routes([
  ['/', Home],
  ['/Space', Space],
  ['/Ocean', Ocean]
])

// nested routes
app.routes([
  ['', Shell, [
    ['/inbox', Inbox],
    ['/account', Account, [
      ['password', Password]
    ]],
    ['*', NotFound]
  ]]
])

// async route loading
app.routes([
  ['/', { load: () => System.import('./pages/Index') }],
  ['/Space', { load: () => System.import('./pages/Space') }]
], async function onTransition (route, data) {
  await Promise.all(data.map(async d => {
    if (!d.Component) d.Component = await d.load()
  }))
  atom.split({ route })
})

To navigate around your application programmatically, you split an action like so:

function MyApp ({ split }) {
  return <form onSubmit={onSubmit}>...</form>

  function onSubmit () {
    const id = 1
    split('navigate', {
      // path
      path: `/space/${id}`,
      // query params
      query: { angle: 0 },
      // push vs replace the url
      replace: false
    })
  }
}

app.mount()

Mount the app to a DOM element. Initialise the store, router and render the app into DOM. Defaults to document.body

app.mount(document.getElementById('root'))

app.unmount()

Stop the router, unrender the app from DOM.

app.unmount()
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].