What's the best way to get primitive properties from child/parent?
See original GitHub issueIt seems like anything you want to pass over the postmessage, you just put in methods. But what if you want to pass over static properties, like 'max': 5000
. Obviously you could use a getter-ish method and slap it in methods, but I’m wondering if that’s really the best way, or if there could be some way to access properties immediately from the connection.promise
’s resonse? eg
connection.promise.then(child => console.log(child.max));
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (6 by maintainers)
Top Results From Across the Web
Most elegant way to save only primitive properties of a ...
I need to make a simple snapshot of it with only primitive properties. What's the most elegant way how to do it? Javascript...
Read more >How do primitive values get their properties? - 2ality
We'll look at: Getting property values; Invoking property values (a.k.a. method calls); Setting property values.
Read more >3.4.1.1 Constructor-based dependency injection - Spring
The Spring team generally advocates setter injection, because large numbers of constructor arguments can get unwieldy, especially when properties are optional.
Read more >How to add child list items to parent level list properties in C# ...
Go bottom up: C#. for each ( var child in children ){ var childParent = childParents.Single( cp => cp.id == child.id); childParent.Children.
Read more >Methods of primitives - The Modern JavaScript Tutorial
There are 7 primitive types: string , number , bigint , boolean , symbol , null and undefined . An object. Is capable...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You have to go through methods like you’re talking about. So in your child iframe you might have something like this:
And then from the parent:
I like the configuration use case, such as using
debug
to tell a child to operate in debug mode.IMHO the most common mistake with @gajewsk2’s proposal would be someone expects Penpal to create a proxy object instead of freezing the property.
A couple suggestions here:
Penpal.connectToParent(methods,metadata)
. Would help clarify the difference between the static frozen properties and the dynamic methods. Access viaparent._metadata.debug
.Object.freeze
to freeze the properties.** Aside **
For Parent->Child communication the fastest approach wouldn’t used PostMessage at all, it would use query params or hash params. That way if you were trying to get the Client to debug, it would happen immediately instead of only after the handshake is complete. I’m not suggesting we do this, just reminding about speediness of passing configuration details.