Giter Site home page Giter Site logo

Comments (9)

srikrsna avatar srikrsna commented on September 25, 2024 1

Hey! You can use toPlainMessage function in @bufbuild/protobuf to covert them to plain objects that are serializable. #505 has more context.

from connect-es.

paul-sachs avatar paul-sachs commented on September 25, 2024 1

Looking over the details on the react docs site, this still looks fairly experimental so it makes sense to me that this would still be handled in user-land, with a solution something like what you've got above (just modified to support exporting all methods):

// server-client.ts
'use server'

export const client = createPromiseClient(...);

// some-component.tsx
import { client } from "./server-client";

...
client.a(...);

This doesn't export individual methods but it does export the client with those methods, which should provide similar functionality.

I suppose you could build a buf plugin to create a client that exports ALL the methods but I would guess it wouldn't be worth the effort.

from connect-es.

paul-sachs avatar paul-sachs commented on September 25, 2024 1

So spent some time learning about RSC, and put together an example of using nextjs and server actions along with connect. Hopefully that can at least provide an idea. Also, being a total newbie to RSC, we can build on that with better practices.

from connect-es.

alissa-tung avatar alissa-tung commented on September 25, 2024

Hey! You can use toPlainMessage function in @bufbuild/protobuf to covert them to plain objects that are serializable. #505 has more context.

Thank you

from connect-es.

alissa-tung avatar alissa-tung commented on September 25, 2024

Now the issue just contains how to export all the methods in a file with top level 'use server' 🤔

from connect-es.

srikrsna avatar srikrsna commented on September 25, 2024

Now the issue just contains how to export all the methods in a file with top level 'use server' 🤔

I don't quite follow, can you elaborate?

from connect-es.

alissa-tung avatar alissa-tung commented on September 25, 2024

Now the issue just contains how to export all the methods in a file with top level 'use server' 🤔

I don't quite follow, can you elaborate?

Yes.

In .proto

service AnyhowService {
    rpc A() returns ();
    rpc B() ...
}

then

const xs : PromiseClient<AnyhowService>
xs.A({})
xs.B({})

those call is not server actions, one should

'use server'

const client = createPromiseClient...

export A = client.A
export B = client.B

then the exported functions are finally server actions

from connect-es.

alissa-tung avatar alissa-tung commented on September 25, 2024

Looking over the details on the react docs site, this still looks fairly experimental so it makes sense to me that this would still be handled in user-land, with a solution something like what you've got above (just modified to support exporting all methods):

// server-client.ts
'use server'

export const client = createPromiseClient(...);

// some-component.tsx
import { client } from "./server-client";

...
client.a(...);

This doesn't export individual methods but it does export the client with those methods, which should provide similar functionality.

I suppose you could build a buf plugin to create a client that exports ALL the methods but I would guess it wouldn't be worth the effort.

thank you, but top level can only export async functions. In this case client is an object

anyway, keeps manually write the exports for every function is not very bad, since the server actions needs auth

from connect-es.

paul-sachs avatar paul-sachs commented on September 25, 2024

Hmm I see. Clearly RSC is more complicated than I thought. In that case, I definitely think a dedicated buf plugin or userland code would be the better approach. This would also be necessary if the entities that need to be returned should be plain objects instead of class objects as well. A plugin would also be easier to update as the RSC paradigm evolves without having to consider how it changes the core client.

from connect-es.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.