Comparing version 0.0.1 to 0.0.2-alpha.0
{ | ||
"name": "realar", | ||
"version": "0.0.1", | ||
"description": "My beloved React micro frontends", | ||
"version": "0.0.2-alpha.0", | ||
"description": "Next generation frontends", | ||
"repository": { | ||
@@ -13,17 +13,14 @@ "url": "https://github.com/betula/realar" | ||
"scripts": { | ||
"bootstrap": "npm run lerna:bootstrap", | ||
"build": "npx rollup -c", | ||
"clean": "npx rimraf ./compiled && npx rimraf ./coverage", | ||
"dev": "npx rollup -cw", | ||
"publish": "npm run lerna:publish", | ||
"test": "npx jest --coverage", | ||
"lerna:reset": "npm run lerna:clean && npm run lerna:bootstrap", | ||
"lerna:ci": "npx lerna bootstrap --no-ci", | ||
"lerna:bootstrap": "npx lerna bootstrap --no-ci && npm run build && npm run test", | ||
"lerna:clean": "npx lerna run clean && npx lerna clean --yes", | ||
"lerna:publish": "npm run clean && npm run build && npm run test && npx lerna publish", | ||
"lerna:build": "npx lerna run build", | ||
"lerna:test": "npx lerna run test" | ||
"bootstrap": "npx lerna bootstrap --no-ci", | ||
"clean": "npm run test:clean && npm run dev:clean && lerna clean --yes", | ||
"publish": "npm run test && lerna publish", | ||
"start": "npm run bootstrap && npm run dev", | ||
"test": "cross-env REALAR_DEV=true jest --coverage", | ||
"test:clean": "jest --clearCache && rimraf coverage", | ||
"reset": "npm run clean && npm run bootstrap", | ||
"dev": "cross-env REALAR_DEV=true NODE_ENV=development parcel ./dev/index.html", | ||
"dev:build": "cross-env REALAR_DEV=true parcel build ./dev/index.html", | ||
"dev:clean": "rimraf dist .cache" | ||
}, | ||
"author": "Slava Bereza <mail@betula.co> (http://betula.co)", | ||
"author": "Slava Birch <mail@betula.co> (http://betula.co)", | ||
"keywords": [ | ||
@@ -36,12 +33,11 @@ "state", | ||
"react hooks", | ||
"micro frontends" | ||
"micro frontends", | ||
"next" | ||
], | ||
"source": "./lib/index.js", | ||
"main": "./compiled/index.js", | ||
"module": "./compiled/index.esm.js", | ||
"types": "./lib.d.ts", | ||
"sideEffects": false, | ||
"module": "./lib/index.js", | ||
"types": "./lib/index.d.ts", | ||
"files": [ | ||
"/compiled", | ||
"/lib.d.ts" | ||
"/lib", | ||
"/babel", | ||
"/jest" | ||
], | ||
@@ -55,15 +51,20 @@ "peerDependencies": { | ||
"@babel/preset-react": "7.10.1", | ||
"@rollup/plugin-babel": "5.0.4", | ||
"enzyme": "3.11.0", | ||
"enzyme-adapter-react-16": "1.15.2", | ||
"babel-jest": "26.1.0", | ||
"cross-env": "7.0.2", | ||
"jest": "26.1.0", | ||
"lerna": "3.22.1", | ||
"parcel-bundler": "1.12.4", | ||
"react": "16.13.1", | ||
"react-dom": "16.13.1", | ||
"rollup": "2.18.0" | ||
"react-test-renderer": "16.13.1", | ||
"rimraf": "3.0.2" | ||
}, | ||
"browserslist": [ | ||
"last 2 Chrome versions" | ||
], | ||
"sideEffects": false, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"gitHead": "8c770585e1caf77dec4fd7522be0b82b7f3f1716" | ||
"gitHead": "5a863575bd8884c5e24c5aca646e0300a8cddc7c" | ||
} |
206
README.md
# Realar | ||
My beloved React micro frontends :heart_eyes: | ||
[![npm version](https://img.shields.io/npm/v/realar?style=flat-square)](https://www.npmjs.com/package/realar) [![npm bundle size](https://img.shields.io/bundlephobia/minzip/realar?style=flat-square)](https://bundlephobia.com/result?p=realar) [![build status](https://img.shields.io/github/workflow/status/betula/realar/Tests?style=flat-square)](https://github.com/betula/realar/actions?workflow=Tests) [![code coverage](https://img.shields.io/coveralls/github/betula/realar?style=flat-square)](https://coveralls.io/github/betula/realar) | ||
[![npm version](https://img.shields.io/npm/v/realar?style=flat-square)](https://www.npmjs.com/package/realar) [![npm bundle size](https://badgen.net/bundlephobia/minzip/realar@0.0.1?style=flat-square)](https://bundlephobia.com/result?p=realar@0.0.1) [![build status](https://img.shields.io/github/workflow/status/betula/realar/Tests?style=flat-square)](https://github.com/betula/realar/actions?workflow=Tests) [![code coverage](https://img.shields.io/coveralls/github/betula/realar?style=flat-square)](https://coveralls.io/github/betula/realar) | ||
### Installation | ||
Perfect usage :+1: [on codesandbox](https://codesandbox.io/s/black-wood-t4533) | ||
```bash | ||
npm i --save realar | ||
# or | ||
yarn add realar | ||
``` | ||
### Usage | ||
Perfect usage :+1: | ||
```javascript | ||
@@ -42,3 +50,3 @@ import React from "react"; | ||
``` | ||
Crazy usage :stuck_out_tongue_winking_eye: [on codesandbox](https://codesandbox.io/s/ecstatic-field-q1due) | ||
Crazy usage :stuck_out_tongue_winking_eye: | ||
@@ -48,18 +56,55 @@ ```javascript | ||
import { | ||
action, | ||
call, | ||
changed, | ||
service, | ||
Service, | ||
signal, | ||
unit, | ||
useService, | ||
changed, | ||
service, | ||
action, | ||
inst, | ||
chan, | ||
useUnit, | ||
Zone, | ||
Service | ||
Zone | ||
} from "realar"; | ||
const MaxBoost = action(); | ||
const GetUser = chan(); | ||
const log = action(); | ||
const x10 = action(); | ||
const GetUser = call(); | ||
const counter = signal(-1); | ||
const backend_proc = signal(0); | ||
const Config = unit({ | ||
const logger = unit({ | ||
lines: [], | ||
get text() { | ||
return this.lines.join("\n"); | ||
}, | ||
[log](...args) { | ||
this.lines = [...this.lines, args.join(" ")]; | ||
} | ||
}); | ||
const backend = unit({ | ||
proc: 0, | ||
async [GetUser](id) { | ||
backend_proc(++this.proc); | ||
const res = await new Promise(r => setTimeout(() => r("John Doe " + id), 1000)); | ||
backend_proc(--this.proc); | ||
return res; | ||
} | ||
}); | ||
const user = unit({ | ||
name: "not loaded", | ||
id: 0, | ||
proc: 0, | ||
get loading() { | ||
return this.proc > 0; | ||
}, | ||
async load() { | ||
this.proc++; | ||
this.name = await GetUser(++this.id); | ||
this.proc--; | ||
} | ||
}); | ||
const stepper = unit({ | ||
step: 1, | ||
@@ -69,4 +114,4 @@ inc() { | ||
}, | ||
[MaxBoost]() { | ||
console.log("x10 speed!", this.step); | ||
[x10]() { | ||
log("step:", this.step, "->", this.step * 10); | ||
this.step *= 10; | ||
@@ -76,16 +121,18 @@ } | ||
const Ticker = unit({ | ||
config: service(Config), | ||
om: inst(Config), | ||
const ticker = unit({ | ||
user: user(), | ||
backend_proc: 0, | ||
stepper: service(stepper), | ||
after: 0, | ||
current: 0, | ||
get step() { | ||
return this.stepper.step; | ||
}, | ||
get next() { | ||
return this.current + this.step; | ||
}, | ||
get step() { | ||
return this.config.step; | ||
}, | ||
tick() { | ||
this.current += this.step; | ||
}, | ||
save: () => counter(this.current), | ||
construct() {}, | ||
@@ -95,25 +142,12 @@ destruct() {}, | ||
this.after = this.next + this.step; | ||
if (changed(this.after > 4)) console.log("Fire!"); | ||
if (changed(this.after > 10)) { | ||
MaxBoost(); | ||
if (changed(this.after > 5)) { | ||
log("if after > 5"); | ||
x10(); | ||
} | ||
} | ||
}); | ||
const BackendFF = unit({ | ||
async [GetUser](id) { | ||
return await new Promise(r => setTimeout(() => r("John Doe " + id), 1000)); | ||
} | ||
}); | ||
const User = unit({ | ||
user: "not loaded", | ||
concurrent: 0, | ||
get loading() { | ||
return this.concurrent > 0; | ||
}, | ||
async load() { | ||
this.concurrent++; | ||
this.user = await GetUser(1); | ||
this.concurrent--; | ||
[counter](val) { | ||
this.current = val; | ||
}, | ||
[backend_proc](val) { | ||
this.backend_proc = val; | ||
} | ||
@@ -123,35 +157,66 @@ }); | ||
function App() { | ||
const { current, next, tick, step } = useService(Ticker); | ||
const { | ||
after, | ||
config: { inc }, | ||
om: { step: om_step } | ||
} = useService(Ticker); | ||
const { user, load, loading } = useUnit(User); | ||
const { current, next, after, tick, user, save, backend_proc } = useUnit(ticker); | ||
const { step, inc } = useService(stepper); | ||
const { load, loading, name } = user; | ||
return ( | ||
<div> | ||
<h1>Realar ticker</h1> | ||
<p>Current: {current}</p> | ||
<p> | ||
Current: {current} | ||
<button onClick={tick}>next</button> | ||
<button onClick={save}>save</button> | ||
</p> | ||
<p>Next: {next}</p> | ||
<p>After: {after}</p> | ||
<button onClick={tick}>tick</button> | ||
<p>Step: {step}</p> | ||
<button onClick={inc}>inc</button> | ||
<p>Om: {om_step}</p> | ||
<p>User: {loading ? "loading..." : user}</p> | ||
<button onClick={load}>load</button> | ||
<Service unit={BackendFF} root /> | ||
<p> | ||
Step: {step} | ||
<button onClick={inc}>inc</button> | ||
</p> | ||
<p>User: {loading ? "loading..." : name}</p> | ||
<p>Backend: {backend_proc ? "loading..." : "idle"}</p> | ||
<p><button onClick={load}>load</button></p> | ||
</div> | ||
); | ||
) | ||
} | ||
export default function Root() { | ||
function Logger() { | ||
const { text } = useService(logger); | ||
return ( | ||
<textarea value={text} readOnly /> | ||
) | ||
} | ||
const whirl = unit({ | ||
cols: [1], | ||
map: fn => this.cols.map(fn), | ||
shift() { | ||
this.cols = this.cols.slice(1); | ||
}, | ||
push() { | ||
this.cols = [...this.cols, (this.cols.pop() || 0) + 1]; | ||
} | ||
}); | ||
function Whirl({ children }) { | ||
const { map, shift, push } = useUnit(whirl); | ||
return ( | ||
<> | ||
<Zone> | ||
<button onClick={shift}>-</button> | ||
{map(key => ( | ||
<Zone key={key}> | ||
{children} | ||
</Zone> | ||
))} | ||
<button onClick={push}>+</button> | ||
</> | ||
) | ||
} | ||
export function Root() { | ||
return ( | ||
<> | ||
<Whirl> | ||
<App /> | ||
</Zone> | ||
<Zone> | ||
<App /> | ||
</Zone> | ||
</Whirl> | ||
<Logger /> | ||
<Service unit={backend}/> | ||
</> | ||
@@ -162,8 +227,9 @@ ); | ||
### Install | ||
Try this example on your computer | ||
```bash | ||
npm i --save realar | ||
# or | ||
yarn add realar | ||
git clone git@github.com:betula/realar.git | ||
cd realar | ||
npm run start | ||
# Open http://localhost:1234 in your browser | ||
``` |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
38429
24
1199
229
12
6