https://github.com/d8corp/innet
A JavaScript library for innet ecosystem
https://github.com/d8corp/innet
javascript library
Last synced: about 1 year ago
JSON representation
A JavaScript library for innet ecosystem
- Host: GitHub
- URL: https://github.com/d8corp/innet
- Owner: d8corp
- License: mit
- Created: 2020-12-28T14:48:56.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2023-06-30T22:16:06.000Z (about 3 years ago)
- Last Synced: 2025-03-18T18:54:11.096Z (over 1 year ago)
- Topics: javascript, library
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/innet
- Size: 8.91 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
innet
CANT inc. application build ecosystem.
## Abstract
The main mission is simplifying and standardizing 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 an out-of-the-box solution, at least, going to be.
`innet` provides you any tools you need to build any JavaScript application:
- [x] API Server
- [x] Web Site
- [ ] Browser Plugin
- [ ] Native Application
### JSX Everywhere
`JSX` provides you the maximum experience of aligning the code.
`innet` includes `JSX` by default.
Check [@innet/jsx](https://www.npmjs.com/package/@innet/jsx) to get more.
> **YOU CAN USE `JSX` ON THE SERVER SIDE!**
### Split By Plugins
Include only code you need, whole functional splits by plugins you can connect (disconnect) separately.
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 SAME PLUGINS ON BOTH SIDES!**
### Components
The component approach is a powerful technology, that `innet` supports.
You can reuse a piece of an application, and that's awesome.
> **YOU CAN USE SAME COMPONENTS ON BOTH SIDES!**
There are a lot of features you can see below, welcome!
[](https://github.com/d8corp/innet/stargazers)
[](https://github.com/d8corp/innet/watchers)
## Install
npm
```bash
npm i innet
```
yarn
```bash
yarn add innet
```
## Usage
> You can start learning of `innet` from [@innet/dom](https://www.npmjs.com/package/@innet/dom), for the front-end side,
> or [@innet/server](https://www.npmjs.com/package/@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**.
```typescript
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`.
You can create the handler with `createHandler` function.
```typescript
import { createHandler } from 'innet'
export default createHandler([])
```
By default, the handler does nothing, but you can set any functionality by plugins.
```typescript
const sum = () => ([a, b]) => {
console.log(a + b)
}
// sum is a plugin
const plugins = [
sum,
]
const handler = createHandler(plugins)
innet([1, 2], handler)
// 3
```
### Plugins
A plugin is a function which runs during a handler creation and returns `HandlerPlugin`.
For example, here is a logger plugin.
```typescript
import { HandlerPlugin, NEXT, useApp } from 'innet'
function logger(): HandlerPlugin {
console.log('logger: initialisation')
return () => {
console.log('logger: app', useApp())
return NEXT
}
}
```
`HandlerPlugin` is a function that can use 2 hooks: `useApp` and `useHandler`.
As another example, let's look at the plugin of `async` which allows promises handling.
```typescript
import innet, { HandlerPlugin, NEXT, useApp, useHandler } from 'innet'
function async(): HandlerPlugin {
return () => {
const app = useApp()
if (!(app instanceof Promise)) return NEXT
const handler = useHandler()
app.then(data => innet(data, handler))
}
}
```
Let's try those plugins
```typescript
const app = new Promise(resolve => resolve('test'))
const handler = createHandler([
logger,
async,
])
// > 'logger: initialisation'
innet(app, handler)
// > 'logger: app', Promise
await app
// > 'logger: app', 'test'
```
The order of the plugins is important.
```typescript
const app = new Promise(resolve => resolve('test'))
const handler = createHandler([
async, // change order
logger,
])
// > 'logger: initialisation'
innet(app, handler)
// nothing happens
await app
// > 'logger: app', 'test'
```
### Extend a handler
You can extend a handler with `createHandler`,
just provide the previous handler to the second argument.
```typescript
const handler1 = createHandler([
async,
sum,
])
const handler2 = createHandler([
logger,
], handler1)
```
Check out [@innet/utils](https://www.npmjs.com/package/@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](https://github.com/d8corp/innet/issues).
[](https://github.com/d8corp/innet/issues)