How can I pass down a function that is found on the Server Component to the Client Component? - next.js

Need help, NEXTJS 13 'app Dir'
How can I pass a function that is found on the Server Component to the Client Component?
I have Button which is a Client component and Another Server Component that wraps it. when The Button is Clicked I want execute the function passed down from Server Component. I don't want to change the Server Component to Client Component because it has large audio files and Images I don't want to render those components on client.
if there's any approach you've used to accomplish this I love to know.
When I try to pass down function from Server Component to Client I get this error.
client.js?7422:691 Uncaught Error: Functions cannot be passed directly to Client Components because they're not serializable.
<... intent=... action={function} children=...>

Related

BizTalk - WMI script to publish the message to message Box

I am trying to publish a message to BizTalk message box using a WMI script . Basically, I am reading the message from non resumable instance. I need to publish this message back to message box instead of saving as file.
Is there a way to achieve this?
Actually, MQ would probably work for you. What you can do is 'encode' the properties and write them to the MSMQ Label property for example.
Then, you can use a custom Pipeline Component on the Receive Location that 'decodes' the MQ property and re-writes the message context properties.
I've done similar in the past and it works just fine.

In Meteor Methods this.connection is always undefined

I am trying to implement some methods for a DDP API, for use with a C# remote client.
Now, I want to be able to track the connection to implement some type of persistent session, to this end, id hope to be able to use the session id given by DDP on connection, example:
{
"msg": "connected",
"session": "CmnXKZ34aqSnEqscR"
}
After reading the documentation, I see that inside meteor methods, I can access the current connection using "this.connection", however, I always get an undefined "this.connection".
Was it removed? If so, how can i access it now?
PS: I dont want to login as a user and access this.userId, since the app I want to create should not login, but actually just get a document id and do work associated with that, including changes to other collections, but all, regarding ONLY this id, and I dont want to have to include this id every time I call a function, since, this could possibly lead security problems if anyone can just send any id. The app would ideally do a simple login, then associate token details with his "session".
Changing from:
() => { this.connection; }
to:
function() { this.connection; }
solves the problem from me. Based on a comment in the accepted answer.
The C# client on github has a few bugs with it as it doesn't follow the DDP spec exactly. When you send commands to it to connect and run a call, it usually sends the '.call' too soon.
The method does work if you do it this way with this.connection on the server side Meteor method.
You need to make sure you send the method calls after you know that you are actually connected. This is what works at least with Meteor 0.8.2
I was using a file named ".next.js" to force meteor to use the newest unsupported javascript spec using a package.
Somehow this messed it up. Changed back to default javascript and it now works.
Thank you :)
init.coffee
Meteor.startup ->
# client init
if Meteor.isClient
Meteor.call "init"
methods.coffee
Meteor.methods
init: ->
console.log #connection.httpHeaders.host
it's that easy...

How to detect when a crossdomain SWFLoader application is ready?

I have a lightweight loader application that is trying to load the main application (the target). The loader needs to detect when the main application has finished loading so it can call a method.
Where I'm running into trouble is that if the target is on a different domain, I get a 2121 error when I try to add an event listener to the loaded app: "SecurityError: Error #2121: Security sandbox violation: This may be worked around by calling Security.allowDomain".
I am calling Security.allowDomain("*") in the target during the preinitialize phase.
Here is the code that generates the exception, called when the SWFLoader dispatches the COMPLETE event:
var content:SystemManager = SystemManager(client.content);
content.addEventListener(FlexEvent.APPLICATION_COMPLETE, appReady);
In this "client" is an SWFLoader object in the loader.
What event can I listen for on a crossdomain SWFLoader object that will tell me it's application is ready for use?

Meteor: execute calls from client console "everywere"

Meteor is said to automagically (in most cases) figure out what code to run on the client and what code to run on the server so you could theoretically just write all your code in one .js file.
I would like to be able to write code in my browser console and have it executed pretty much as if I had put the code in a file on my server.
For example, in my browser console:
[20:08:19.397] Pages = new Meteor.Collection("pages");
[20:08:30.612] Pages.insert({name:"bro"});
[20:08:30.614] "sGmRrQfezZMXuPfW8"
[20:08:30.618] insert failed: Method not found
Meteor says "method not found" because I need to do new Meteor.Collection("pages"); on the server.
But is there a workaround for this, whether using the above-mentioned automagic or by explicitly saying in my browser console "run the following line of code on the server!"?
Well it doesn't "automagically" figure it out - you have to very explicitly do one of two things:
Separate the code into client and server directories.
Wrap the code in an isClient or an isServer section.
Otherwise, any code you write will execute in both environments. However, any code input by the user on the client will only be executed on the client. Meteor has been specifically designed to protect this boundary.
You can call a method on the server from the client, but again the server cannot be tricked into executing client-defined functions.
In your specific example, you can always define the collection only on the client like so:
Pages = new Meteor.Collection(null);
That will allow you do freely manipulate the collection data on the client, but it will not involve the server (nothing will be stored in the db).

configuring error messages in flex application

I'm trying to create a Flex based internet application with an EJB layer in the server. This layer provides the XML used by the flex application. It uses the Cairngorm architecture. Currently, on an error I call the handler function defined in all the command files. How can I centralize this?
My idea is to create a XML file that contains all the error messages and the types of error message eg:- Warning, Error etc. In the error handler, I will call the error handling function and pass a unique id which in turn will display the error message defined in the xml config file. Do I need to load this XML file in the Model layer of the application itself and store them as say global variables?
Please suggest me ideas on overriding the Alert box so that I can create Warning alert, Error alert etc.
Load the xml file when the app loads, and store the messages on a model. When you need to fire off an error message, you can fire the appropriate event, and you can have a command that pulls the right one from the model and displays it. Alert is definitely the way to go if you want to have a command open a window.
The better (but harder) option is to have a view that binds to a model, which model has a property like "hasError" and "errorMessage", so if hasError gets set to true, the view opens a custom popup.
TitleWindow is not good enough?

Resources