question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Document Data Sharing from a Piral Instance

See original GitHub issue

New Feature Proposal

For more information, see the CONTRIBUTING guide.

Description

Currently we allow pilets to share data using the Piral API by calling setData and getData to store into some global key/value store. I’d like to see the ability to have some data set into this by the base piral instance on render.

Background

The use case for this is for sharing user information to pilets. Currently, we expect the instance to render only to authenticated users. We pull some user information (such as email) from an API when rendering the Menu component in order to generate portions of the menu. When we do so, we’d like to have the ability to make the user information available to all the other pilets.

Discussion

Biggest pro here is being able to boootstrap data from the main piral instance and have that piral instance manage the data for the other pilets. This is useful for any sort of global data that isn’t necessarily spawned/acquired by a specific pilet.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kpyfancommented, Dec 6, 2019

Thanks for the help! I’ll give it a shot and see if I run into any other issues.

0reactions
FlorianRapplcommented, Dec 12, 2019

If your component lives anyway in the app shell (sounds like it for the menu) then instead of passing in a prop “couple” it to the global state container.

const Menu = () => {
  const data = useGlobalState(m => m.data.foo);
  return <b>Current value: {data && data.value}</b>;
};

Instead of the logic operation you could also use data?.value if you already use the next gen / latest version of TypeScript.

Since this way you are “connected” to the global state container your component will re-render on change.

Hope that helps!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sharing From Piral - Piral - Documentation
A Piral instance can easily distribute information among the pilets in multiple ways. In this tutorial, we go over these ways.
Read more >
piral-io/community - Gitter
Question: What is the best way for multiple pilets to publish data while one pilet listens to it? I was trying to use...
Read more >
piral-urql - npm
Alternatively, expose a GraphQL library such as urql or apollo as a shared library. Documentation. The following functions are brought to the Pilet...
Read more >
Blog - Building a Netflix Clone with Piral - smapiot
Each team is autonomous, and has end-to-end – from the database to the ... The Piral instance will pull all registered pilets from...
Read more >
Piral Tutorials - (13) Sharing from Piral - YouTube
How to share information from the Piral instance.https://docs. piral.io/tutorials/13- sharing -from- piral.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found