Skip to content

Commit

Permalink
feat: provi/ssr added
Browse files Browse the repository at this point in the history
  • Loading branch information
betula committed Dec 1, 2023
1 parent 8e90e45 commit 7c7e3dd
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 6,987 deletions.
5 changes: 3 additions & 2 deletions client/src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { factory } from 'provi';

const { provide, destroy } = factory();
const { provide, destroy, set_async_hooks } = factory();

export {
provide,
destroy
destroy,
set_async_hooks
}
3,489 changes: 0 additions & 3,489 deletions client/yarn.lock

This file was deleted.

3 changes: 2 additions & 1 deletion index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import * as client from './client/src'
import * as server from './server/src'

import asyncHooks from 'node:async_hooks';
const { provide, destroy, isolate } = factory(asyncHooks)
const { provide, destroy, set_async_hooks } = factory(asyncHooks) as any;
const isolate = set_async_hooks(asyncHooks);

test('function service', () => {
let c = 0
Expand Down
14 changes: 12 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@
"client/package.json",
"server/dist",
"server/src",
"server/package.json"
"server/package.json",
"ssr/dist",
"ssr/src",
"ssr/package.json"
],
"scripts": {
"test": "jest",
"build": "yarn clean && microbundle build --raw --target node --generateTypes false && microbundle build --raw --target web --cwd client --generateTypes false && microbundle build --raw --target node --cwd server --generateTypes false",
"build": "yarn clean && microbundle build --raw --target node --generateTypes false && microbundle build --raw --target web --cwd client --generateTypes false && microbundle build --raw --target node --cwd server --generateTypes false && microbundle build --raw --target node --cwd ssr --generateTypes false",
"dev": "microbundle watch --raw --format cjs",
"clean": "rm -rf client/dist server/dist dist"
},
Expand Down Expand Up @@ -73,6 +76,13 @@
"import": "./client/dist/client.mjs",
"require": "./client/dist/client.js"
},
"./ssr": {
"types": "./ssr/src/index.d.ts",
"browser": "./ssr/dist/ssr.module.js",
"umd": "./ssr/dist/ssr.umd.js",
"import": "./ssr/dist/ssr.mjs",
"require": "./ssr/dist/ssr.js"
},
"./server": {
"types": "./server/src/index.d.ts",
"browser": "./server/dist/server.module.js",
Expand Down
3,489 changes: 0 additions & 3,489 deletions server/yarn.lock

This file was deleted.

13 changes: 9 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import { unsubscriber, collect, run } from 'unsubscriber';

const
factory = (async_hooks) => {
factory = () => {
let
zone_id = 0, // root zone
hook
hook,
async_hooks

const
zone_index = new Map(),
zone_parent_index = new Map(),

zones = new Map(),

isolate = async_hooks && (async (fn) => {
set_async_hooks = (m) => {
async_hooks = m;
return isolate;
},

isolate = (async (fn) => {
if (!hook) {
hook = async_hooks.createHook({
init(async_id, _type, trigger_async_id) {
Expand Down Expand Up @@ -102,7 +107,7 @@ const
return {
provide,
destroy,
isolate
set_async_hooks
}
}

Expand Down
25 changes: 25 additions & 0 deletions ssr/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "provi-ssr",
"version": "2.0.0",
"description": "SSR for Service Provider for client side",
"private": true,
"license": "MIT",
"types": "src/index.d.ts",
"main": "dist/ssr.js",
"module": "dist/ssr.module.js",
"umd:main": "dist/ssr.umd.js",
"source": "src/index.js",
"peerDependencies": {
"provi": "2.x.x"
},
"author": "Slava Bereza <mail@betula.co> (http://betula.co)",
"exports": {
".": {
"types": "./src/index.d.ts",
"browser": "./dist/ssr.module.js",
"umd": "./dist/ssr.umd.js",
"import": "./dist/ssr.mjs",
"require": "./dist/ssr.js"
}
}
}
1 change: 1 addition & 0 deletions ssr/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const isolate: import("provi").Isolate;
8 changes: 8 additions & 0 deletions ssr/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { set_async_hooks } from 'provi/client';
import asyncHooks from 'async_hooks';

const isolate = set_async_hooks(asyncHooks);

export {
isolate
}

0 comments on commit 7c7e3dd

Please sign in to comment.