Pricing Blog

Refresh APIs

  • elli4931-1386502674563989665

    Vizualinx

    1 month ago

    (please mind the way I wrote the question.. I tried my luck first with AI..)

    In nordcraft what would be the best way/system to reload APIs from one component to the other?

    For example I have an SPA, every page is technically a component inside the main page, and I also have all the main dialogs in the main page.
    Now for example when I want to create a new contact, the contact page is a component inside the main page, I have there a button, on click I pass on an event to the main page that would open the add contact dialog (popup modal). Now when I save the new contract I need to refresh the API with the list of contacts to be able to see the new contact straight away without the user having to manually refreshing the browser.

    Now what I am currently doing is, I have to do a hack.
    In the contacts component I have an attribute 'reload contacts' that is default to 0, then a do on attribute change- reload contacts API.
    Now when the user saves the new contact I increment a variable 'reload contacts api' which is linked to the attribute of the contact component. What happens then is because it updates the attribute, it will refresh the API.

    But this is very hacky and inefficient.
    I have a ton of these use cases and I need a better way to handle it.
    Any ideas of how to do this?
  • jaycmpb-1386506044737458218

    Jay Campbell

    1 month ago

    Not sure if I understand exactly what you have going on but it sounds like you should expose a workflow via context.
  • lucasg-1386520781999177920

    Lucas G

    1 month ago

    Yeah either have a workflow that fetches contacts that you can trigger throughout your app or could also just use a realtime connection if it's something that updates a lot
  • elli4931-1386700154815516682

    Vizualinx

    1 month ago

    Probably a silly question, but how would i refresh an api in a child component with a workflow on the main page?
  • lucasg-1386708076501008395

    Lucas G

    1 month ago

    Contexts
  • 128651941143117824-@Lucas G
    Contexts
    elli4931-1386712142278951023

    Vizualinx

    1 month ago

    Yeah but...
    Never mind, I'll figure it out.
  • lucasg-1386712373884354590

    Lucas G

    1 month ago

    Expose a workflow that makes the call and use that workflow on the success event of other calls/actions in your components
  • Or are you talking about the other way around?
  • lucasg-1386712750511882411

    Lucas G

    1 month ago

    If it’s the other way around then you have to use attribute change as you already mentioned
  • If it’s an API/data that multiple components use then perhaps you’ll benefit from moving it up the hierarchy
  • elli4931-1386713691587612733

    Vizualinx

    1 month ago

    Yes. It is the other way around. I didn't want to use the attribute approach, that's why I asked.
    But thanks!
  • lucasg-1386714115946446869

    Lucas G

    1 month ago

    The only other way would be to use a context and track it in the component but that would work in a similar manner to attribute change