unional / async-fp Goto Github PK
View Code? Open in Web Editor NEWAsynchronous Functional Programming Utilities
Asynchronous Functional Programming Utilities
// instead of
const gizmo = define({
async create() {}
})
// allows
const gizmo = define({
create() {}
})
The complicated thing is correctly inferring the types.
From justland/just-web#22
Besides define.require()
and define.optional()
,
we can have define.readonly.require()
and define.readonly.optional()
(or something similar),
to indicate the gizmo
only need read only access to the dependency.
const x = define({
static: define.require<define.InferDeps<typeof y>>(),
async create(ctx) {
return incubate(ctx).with(y).create()
}
})
or
const x = define({
static: define.depsOf<typeof y>(),
async create(ctx) {
return incubate(ctx).with(y).create()
}
})
Some code calls get()
and pass the context to another code.
That other code call extend()
to add more stuff.
This doesn't work as the get()
call is cached.
Instead of adding features to gizmo with .with(gizmo)
,
add the ability to compose multiple created gizmos together.
This is useful to compose gizmo from other teams during runtime.
export async function activate({ context }: { context: AuthGizmo }) {
const gizmo = await incubate().compose(context).with(featureGizmo).create()
}
Currently, doing FP on array is very clumsy:
Pseudo code:
async function inc(x: number) {
return x + 1
}
const numbers = range(0, 10)
const result = await Promise.all(numbers.map(async n => {
const next = await inc(n)
return { n, next }
}))
const result2 = result.filter(({n, next}) => (n+next)%3)
There should be a way to make it easier.
It doesn't work due to microsoft/TypeScript#53792
Similar to @just-web/app
createApp().extend()
When using .merge()
twice.
const loader = (gizmos: Gizmo[], result: AnyRecord) => (identifier: string) => Promise<AnyRecord>
incubator().with(...).create(loader)
Only when there are dynamic dependencies.
UPDATE:
to work with #186:
incubator().with(...).create((gizmo, ctx) => {
ctx.setDynamicLoader(...)
return () => clean up
}
or
// only set once and remove from the chain
incubator().loader().with(...).create()
const ioc = container()
ioc.register(gizmo, strategy)
There are multiple strategy options: singleton
, per-branch
, per-container
, always-create
incubator()
uses always-create
for simplicity.
Could change if per-branch
is needed
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
@typescript-eslint/eslint-plugin
, @typescript-eslint/parser
).github/workflows/pull-request.yml
.github/workflows/release.yml
package.json
@changesets/cli ^2.26.0
@commitlint/cli ^19.0.0
@commitlint/config-conventional ^19.0.0
@types/jest ^29.0.0
@typescript-eslint/eslint-plugin ^6.0.0
@typescript-eslint/parser ^6.0.0
eslint ^8.22.0
eslint-config-prettier ^9.0.0
eslint-plugin-harmony ^7.1.2
husky ^9.0.0
pinst ^3.0.0
rimraf ^5.0.0
turbo ^1.4.3
typescript 5.1.6
pnpm 8.15.5
packages/async-context/package.json
iso-error ^6.0.2
type-plus ^7.0.1
@repobuddy/jest ^3.2.0
@repobuddy/typescript ^2.0.0
@size-limit/preset-small-lib ^9.0.0
@types/setimmediate ^1.0.2
assertron ^11.0.1
cross-env ^7.0.3
depcheck ^1.4.3
jest ^29.5.0
jest-esm-transformer-2 ^1.0.0
jest-watch-suspend ^1.1.2
jest-watch-toggle-config-2 ^2.1.0
jest-watch-typeahead ^2.2.2
npm-run-all2 ^6.0.0
repobuddy ^1.0.2
rimraf ^5.0.0
setimmediate ^1.0.5
size-limit ^9.0.0
ts-jest ^29.1.0
node >= 14.16
packages/async-fp/package.json
@repobuddy/jest ^3.2.0
@repobuddy/typescript ^2.0.0
@size-limit/preset-small-lib ^9.0.0
assertron ^11.0.1
cross-env ^7.0.3
depcheck ^1.4.3
jest ^29.5.0
jest-esm-transformer-2 ^1.0.0
jest-watch-suspend ^1.1.2
jest-watch-toggle-config-2 ^2.1.0
jest-watch-typeahead ^2.2.2
npm-run-all2 ^6.0.0
repobuddy ^1.0.2
rimraf ^5.0.0
size-limit ^9.0.0
ts-jest ^29.1.0
type-plus ^7.0.1
node >= 14.16
packages/gizmo/package.json
type-plus ^7.0.1
@repobuddy/jest ^3.2.0
@repobuddy/typescript ^2.0.0
@size-limit/preset-small-lib ^9.0.0
assertron ^11.0.1
cross-env ^7.0.3
depcheck ^1.4.3
jest ^29.5.0
jest-esm-transformer-2 ^1.0.0
jest-watch-suspend ^1.1.2
jest-watch-toggle-config-2 ^2.1.0
jest-watch-typeahead ^2.2.2
npm-run-all2 ^6.0.0
repobuddy ^1.0.2
rimraf ^5.0.0
size-limit ^9.0.0
ts-jest ^29.1.0
node >= 14.16
const incubator = incubate().with()...
const gizmo = await incubator.create(async (gizmo) => {
/** do startup work before the instance is returned **/
})
What is the async nature? During build (.extend()
)? or during .start()
?
createApp().start()
allows plugin to do some async work to get ready.
While the .extend()
call adding interface synchronously.
Is that needed?
Can we just extend and wait for start to happen before getting the resulting extended object?
That lost the type checking during .extend()
. Should that be missed? Or there is a way to internally track the type using something like PromiseValue<T>
to get the expected Trait
and keep going?
15.13.15
to 15.13.16
.π¨ View failing branch.
This version is covered by your current version range and after updating it in your project the build failed.
semantic-release is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
The new version differs by 3 commits.
4ed6213
style: fix prettier style
8051294
fix(package): update env-ci to version 4.0.0
95a0456
chore(package): update ava to version 2.0.0
See the full diff
There is a collection of frequently asked questions. If those donβt help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot π΄
const gizmo = define({
async create() {
return [{}, () => () => 'clean up']
}
})
How to trigger? This will be breaking change:
const [app, cleanup] = await incubate().with(...).create()
cleanup()
One solution is to use symbol:
const app = await incubate().with(...).create()
await cleanup(app)
async function cleanup(app) {
app[destructorSymbol]()
}
or use the same pattern:
const app = await incubate().with(...).create(() => () => clean up)
This design conflict with #161.
Need to find to way to make both of them work.
from just-web:
const i = incubate(logGizmo()) // i !== MissingDependency<'name' | 'id'>
Using incubate(ctx).with(...).create()
to extends gizmo is not optimal:
const subGizmo = define({
static: define.require<A & B & C>(),
async create(ctx) {
return incubate(ctx).with(d).with(e).create()
}
})
This overrides whatever sub gizmo of A
/B
/C
used by the app. e.g.:
const gizmoA = define({
async create() {
return {
a: { x() {} }
}
}
}
const subA = define({
async create() {
const { a } = await incubate().with(gizmoA).create()
return {
a: {
...a,
y() {}
}
}
}
})
const gizmo = incubate().with(subA).with(gizmoB).with(gizmoC).with(subGizmo).create()
// gizmo got the base `gizmoA` prop because the subGizmo overrides the `subA`
gizmo.a.x() // exist
gizmo.a.y() // does not exist
The correct way is:
const subGizmo = define({
static: define.require<A & B & C>(),
async create(ctx) {
const { d, e } = await incubate(ctx).with(d).with(e).create()
return { d, e }
}
})
which is tedious.
Add an extends()
function or similar to:
const subGizmo = define({
static: define.require<A & B & C>(),
async create(ctx) {
return extends(ctx).with(d).with(e).create() // returns only { d, e }
}
})
or maybe:
const subGizmo = define({
static: define.require<A & B & C>(),
async create(ctx) {
return incubate(ctx).with(d).with(e).createSubGizmo() // returns only { d, e }
}
})
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.