Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

stash/api/util/state seems to be missing state

Tim Slatcher May 21, 2015

I have some code that looks like:

window.exampleUtils = window.exampleUtils || {};

define('example/utils', ['stash/api/util/state'], function(state) {
    var project = state.getProject();
    var repository = state.getRepository();
    
    window.exampleUtils.isInterestingProject = project.name === 'interesting' && repository.name === 'yes';
    return window.exampleUtils ;
});

I'm essentially setting up some useful variables and state, but it appears that this gets run 'too early' in that state appears not to have been populated yet.

I'm currently using this in other places and also in client-conditions, hoping to share the logic of calculating these conditions. 

Is there anyway to ensure the state has been fully loaded? 

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Adam
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 21, 2015

I assume you have left out the code for 

var project = state.getProject();
var repository = state.getRepository();

 

Those should all be available on $(document).ready(...)

Tim Slatcher May 21, 2015

Ah, oops, yes, I did. Interesting - is there any order by which <client-conditions>s be evaluated? I would like to use the state set up here inside of these conditions for simplicity.

Tim Slatcher May 21, 2015

Updated the question to reflect what my code actually looks like In my atlassian-plugin.xml I then have: <client-condition>exampleUtils.isInterestingProject</client-condition>

Adam
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 26, 2015

The notification for your comment was lost completely in the jungle that is my gmail filters. My apologies! I'm not sure I understand your question, but the order that handlers are executed in is: on the server: <condition> (with the default context) <context-provider> (with the default context) then on the client: <client-condition> (with a combination of the default client context overridden with any properties from your server context-provider) <client-context-provider> (with a combination of the default client context overridden with any properties from your server context-provider) So unfortunately you can't use a client-context-provider to manipulate the input for your conditions. Generally what you do is you create a module to deal with all the transformations you need, and then just reuse the same code in your condition and in your context-provider or renderer if you need to. I know it's a few months later (sorry again) but let me know if I haven't answered your question or you need more help.

TAGS
AUG Leaders

Atlassian Community Events