How to use a string as dependency

I can init a component with a dependecy, such as the router, and be certain it is available when I use it in the code of that component.

Is there a way to init the same component with a value, such as a String? Using a parameter requires mapping which is async.

Right now I have a situation where I have 5 pages in a PageControl, and they all require a string (person name). On Activated I want each of those pages to take that name and use it to change a navbar (so it says “About Jimmy”, “Jimmy’s pictures” etc). That seems like the clean / direct approach to me. I could add conditions on the Activated event AND the mapping to make sure I have the name in order to update the navbar, but that adds a bit more logic / code.

Hey!

Properties are great for that :slight_smile:

Here’s an example:

<App>
  <ClientPanel>
    <NameBox PersonName="Bob" />
  </ClientPanel>
  <Panel ux:Class="NameBox" >
    <string ux:Property="PersonName" />
    <Text>Hello, {Property PersonName}</Text>
  </Panel>
</App>

Hi Liam
I should have made it clear that I need these in Javascript. And there I need to use mapping is I want to access properties, which is async. meaning that when I call the handler for <Activated>, I may or may not have said property

@mircea: reading your original description, I get a feeling that this might be a job for a model.

All of your components that rely on a given string (name of a logged-in user?) being present should:

var user = require("modules/user");

Where modules/user.js is a stand-alone JS file that holds the state for your user:

var name = Observable("Jimmy");
var isAuthorised = Observable(true);
// ...
module.exports = {
    name: name,
    isAuthorised: isAuthorised
};

Your components then could simply refer to the exported variables and even call methods on that user object.

@Uldis
This sees like a solid and elegant solution. Thanks