AppFlow, how do Set Global, Assign and Set Storage work? Whats their purpose?

Still playing around with purely front end and AppFlows.

The challenge: I need a global storage, accessible from all pages with active binding, e.g. for storing state and updating on state changes (like current tab in navigation. In React, I would use a state, hook or provider.

So I played around with some steps in AppFlows and tried to understand what they are doing / how they work.

  1. what is Set Global doing, and where can I access it the data?
  2. With Assign, I can set local variables, I guess?
  3. Set Storage, I would expect setting a session / storage global? Where would it be (what Storage?), if it would work (it throws an error on the console ā€˜key needs to be a stringā€™)
  1. Set Global will set a global variable, the variable will be accessible from the whole page.
  2. Assign will set a local variable, you can use it within the flow. If you have a page flow you can also access it from the page after the flow has run.
  3. Set Storage is for setting a variable into the localStorage, this is useful for storing things like user preferences.

There is also a Set Session which is for setting a variable into the sessionStorage, this is useful to store a value that must persist between pages, it will be removed after the browser was closed.

1 Like

Thanks Patrick, looks like I was not completely wrong with my assumptions.

Still, some questions left:

How? Letā€™s start simple, I want to access a global from within the same flow, I canā€™t access it? Is the process to use a variable assign the global, work through the flow (e.g. manipulating the data) and then write it back to the global?

Attaching the flow to a page, I donā€™t have access to any of this variables (assuming that at least the Global should be somewhere?)

I actually canā€™t find getter for the set methods?

Also, Set Storage throws an error:
CleanShot 2023-02-23 at 10.12.10

Seems that the Storage and Sessions are buggy, they donā€™t generate the correct code. Working on a fix for that for the upcoming update.

To get access to the global variable you need to define the variable also on the root, this is to make it available in the picker.

image

Thanks, Patrick. That was defo a step forward. However, it seems not to work on content pages. I quickly added a local variable on the main index (the ā€œtemplateā€) and could access the global data (to check if it appears in the data picker), but not in content pages.

Let me quickly outline what I want to achive:

  1. A template page with the main navigation and tab-bar
  2. Content pages and sub pages for the main features.
  3. I need to share global data across all pages AND the template, e.g. for the active tab, becauseā€¦
  4. when clicking on tab in the nav bar, I can easily highlight the active tab, but when clicking on a link in a content page, I also want to be able to highlight the active tab.

See example: the tabs are correctly highlighted on my user interaction. But clicking on the Event, it opens a content page under casino / events, but I need to highlight the tab as-well.

The global variable should be available also on the content pages, Iā€™ve tested that. Do the content pages correctly reference the main page?

image

Yep, they have. And everything else seems to work for me.

Do I understand correctly that you have now installed 5.4.2 and that this issue is now resolved?

Nope, is there a 5.42? I only refered to the question if the head page was set correctly (and thus, finally, pages in subfolders work for me)

These issues have been fixed in Wappler 5.4.2.

@Teodor why have you unlisted the only post which is basically a documentation of the above defined flow components?

Okay, with the latest update many things make more sense now (for me :slight_smile: ) :

  • Params work now \o/
  • Set Session and Set Global write to the session- and local storage.
  • After updating all my content pages and setting the path again to the template, all content pages have acces to the objects defined in the main template page \o/
  • Still unsure about the globals, defined them, set them in a AppFlow, but when outputting on a page, the variable is empty?

But still not sure how to access the data?

1 Like

I will be waiting to see how you get this answered, too.

Are they not being set after you run the flow?

You can also test by setting the global variable using the console in devtools, the syntax is dmx.global.set(key, value).

I apologize, it works now. :see_no_evil:

While playing around after the update, for each global (inserted via data picker), Wappler was displaying [object Object], so I tried to access the valueā€¦ with no luck. But now, magically, the global is shown as expected.

1 Like

Everything works now as I would expect it. The last two updates have changed my mind about Wappler for frontend work fundamentally. At least for Bootstrap work. As a hard core Ionic user, I am not keen in using Framework7, but I will give it a try. One day :see_no_evil::joy:

1 Like

This indicates you are encouraged about using Wappler for frontend design?

Tbh, I never planned to use Wappler for anything else than a quick PoC, think of a bit of ā€œmore exciting wireframesā€. I was using a web site creation tool (RapidWeaver) for this for years now, utilizing Airtable or Google Sheets for the few usecases I had to add a bit of dynamic data.

I am mostly doing App development now (My dayjob is Product- and Portfoliomanager Mobile) and my regular tech stack is Ionic/react/Capacitor with VS Code for app development and front-end and Groovy/Java/Grails for API and Backend (with Bootstrap).

But Wappler seems to have quite some potential, so I decided to give it a go also for one or two real world projects (apps) next to the evaluation project I am doing right now.

I added Prepros (https://prepros.io) to the Wappler stack to get halfway decent SCSS and TypeScript support and code formating the way I like it.