Skip to content

Commit

Permalink
fix: more renamings
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerlinsley committed Mar 1, 2023
1 parent c3e99c9 commit e1903df
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The `fetch$` function is used to create an isomorphic server-side RPC. It takes
```tsx
import { fetch$ } from '@tanstack/bling'

const serverFn = fetch$(async (payload) => {
const fetchFn = fetch$(async (payload) => {
// do something
return 'result'
})
Expand Down
4 changes: 2 additions & 2 deletions examples/astro-basic/src/app/root.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { fetch$, split$ } from '@tanstack/bling'
import { secret } from './secret.server$'

const serverFnHello = fetch$(() => console.log('Hello world'))
const fetchHello = fetch$(() => console.log('Hello world'))

function ServerHello() {
return <button onClick={() => serverFnHello()}>ServerFn Hello</button>
return <button onClick={() => fetchHello()}>ServerFn Hello</button>
}

const splitHello = split$(() => console.log('I am code split!'))
Expand Down
30 changes: 15 additions & 15 deletions packages/bling/src/compilers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ function transformServerFn$(
path: babel.NodePath<t.CallExpression>,
state: State,
) {
const serverFn = path.get('arguments')[0]
const serverFnOpts = path.get('arguments')[1]
const fetchFn = path.get('arguments')[0]
const fetchFnOpts = path.get('arguments')[1]
let program = path.findParent((p) => t.isProgram(p))
let statement = path.findParent((p) => {
const body = program!.get('body') as babel.NodePath<babel.types.Node>[]
Expand All @@ -235,7 +235,7 @@ function transformServerFn$(

const hash = hasher(nodePath.join(fName, String(serverIndex)))

serverFn.traverse({
fetchFn.traverse({
MemberExpression(path) {
let obj = path.get('object')
if (obj.node.type === 'Identifier' && obj.node.name === 'fetch$') {
Expand All @@ -245,27 +245,27 @@ function transformServerFn$(
},
})

if (serverFn.node.type === 'ArrowFunctionExpression') {
const body = serverFn.get('body') as babel.NodePath<babel.types.Node>
if (fetchFn.node.type === 'ArrowFunctionExpression') {
const body = fetchFn.get('body') as babel.NodePath<babel.types.Node>

if (body.node.type !== 'BlockStatement') {
const block = t.blockStatement([t.returnStatement(body.node as any)])
body.replaceWith(block)
}

serverFn.replaceWith(
fetchFn.replaceWith(
t.functionExpression(
t.identifier('$$serverHandler' + serverIndex),
serverFn.node.params,
serverFn.node.body as t.BlockStatement,
fetchFn.node.params,
fetchFn.node.body as t.BlockStatement,
false,
true,
),
)
}

if (serverFn.node.type === 'FunctionExpression') {
;(serverFn.get('body') as any).unshiftContainer(
if (fetchFn.node.type === 'FunctionExpression') {
;(fetchFn.get('body') as any).unshiftContainer(
'body',
t.variableDeclaration('const', [
t.variableDeclarator(t.identifier('$$ctx'), t.thisExpression()),
Expand All @@ -290,8 +290,8 @@ function transformServerFn$(
const $$server_module${serverIndex} = fetch$.createHandler(%%source%%, "${pathname}", %%options%%);
fetch$.registerHandler("${pathname}", $$server_module${serverIndex});
`)({
source: serverFn.node,
options: serverFnOpts?.node || t.identifier('undefined'),
source: fetchFn.node,
options: fetchFnOpts?.node || t.identifier('undefined'),
}),
)
} else {
Expand All @@ -310,11 +310,11 @@ function transformServerFn$(
)(
process.env.TEST_ENV === 'client'
? {
source: serverFn.node,
options: serverFnOpts?.node || t.identifier('undefined'),
source: fetchFn.node,
options: fetchFnOpts?.node || t.identifier('undefined'),
}
: {
options: serverFnOpts?.node || t.identifier('undefined'),
options: fetchFnOpts?.node || t.identifier('undefined'),
},
),
)
Expand Down

0 comments on commit e1903df

Please sign in to comment.