innet

CANT inc. application build ecosystem.

Usage no npm install needed!

<script type="module">
  import innet from 'https://cdn.skypack.dev/innet';
</script>

README


innet logo by Mikhail Lysikov

innet

CANT inc. application build ecosystem.


Abstract

The main mission is simplifying and standardizing of application development.

innet includes all the best features of famous libraries and frameworks. innet looks like all you've seen but at the same time it's completely different. innet is an ecosystem for JavaScript, but the same time it's just a function. This is a ready-mode solution, at last, going to be. innet provides you any tools you need to build any JavaScript application:

  • API Server
  • Web Site
  • Browser Plugin
  • Native Application

JSX Everywhere

JSX provides the best experience of compositing and here you can take maximum of that. innet includes JSX by default. Check @innet/jsx to get more.

YOU CAN USE JSX ON THE SERVER SIDE!

Split By Plugins

Include only that code you need, whole functional split by plugins you can connect. From refs, portals, context, life cycle, state management on frontend side to router, components, proxy, async, html on server side and more.

YOU CAN USE THE SAME PLUGINS ON BOTH SIDES!

Components

The component approach is a powerful technology innet supports. You can reuse a piece of an application, and that's awesome.

YOU CAN USE THE SAME COMPONENTS ON BOTH SIDES!

There are a lot of features you can see below, welcome!

stars watchers

Install

npm

npm i innet

yarn

yarn add innet

Or you can include the script into the head.

<!-- Target (innet) -->
<script defer src="https://unpkg.com/innet/innet.min.js"></script>

Usage

You can start learning of innet from @innet/dom, for the front-end side, or @innet/server for the back-end.

innet is a function which expects 2 required arguments. The first one is an application and the second one is a handler of the application. Like you can say what to do and how.

import innet from 'innet'

import app from './app' // what to do
import handler from './handler' // how to do

innet(app, handler)

app can be any type, but handler should be a Handler instance. You can create the handler with createHandler function.

import { createHandler } from 'innet'

export default createHandler([])

By default, the handler does nothing, but you can set any functionality by plugins.

const sum = () => ([a, b]) => a + b
// sum is a plugin

const plugins = [
  sum,
]

const handler = createHandler(plugins)

innet([1, 2], handler)
// returns 3

Plugins

A plugin is a function which runs during a handler creation and returns PluginHandler.

For example, here is a logger plugin.

import { PluginHandler } from 'innet'

function logger (): PluginHandler {
  console.log('logger: initialisation')
  
  return (app, next) => {
    console.log('logger: app', app)
    
    return next()
  }
}

PluginHandler is a function with the first argument equals a peace of application, the second is a next plugin runner and the last one is a handler.

As another example, let's look at the plugin of async which allows promises handling.

import innet, { PluginHandler } from 'innet'

function async (): PluginHandler {
  return (app, next, handler) => {
    if (app instanceof Promise) {
      // if the application is a promise then we wait for the promise and handle it's result
      return app.then(data => innet(data, handler))
    }

    // if not then run next plugins
    return next()
  }
}

Let's try those plugins

const app = new Promise(resolve => resolve('test'))

const handler = createHandler([
  logger,
  async,
])
// > 'logger: initialisation'

const result = innet(app, handler)
// > 'logger: app', Promise

await result
// > 'logger: app', 'test'

The order of the plugins is important.

const app = new Promise(resolve => resolve('test'))

const handler = createHandler([
  async, // change order
  logger,
])
// > 'logger: initialisation'

const result = innet(app, handler)
// nothing happens

await result
// > 'logger: app', 'test'

Extend a handler

You can extend a handler with createHandler, just provide the previous handler to the second argument.

const handler1 = createHandler([
  async,
  sum,
])

const handler2 = createHandler([
  logger,
], handler1)

Check out @innet/utils, there you can find the most general plugins and utils.

Issues

If you find a bug or have a suggestion, please file an issue on GitHub.

issues