Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

href as action does not carry over parameters #347

Open
mexophantes opened this issue Jul 17, 2018 · 7 comments
Open

href as action does not carry over parameters #347

mexophantes opened this issue Jul 17, 2018 · 7 comments

Comments

@mexophantes
Copy link

I would like to hand over a parameter (id) from one view to the next when clicking on a button like this:
Both version however don't work:

{
  "type": "button",
  "style": {
  "height": "20"
  },
  "url": "file://image.png",
  "action": {
  "type": "$href",
  "options": {
  "url": "file://some-local-json.json"
   },
   "id": "1234567"
}
{
  "type": "button",
  "style": {
  "height": "20"
  },
  "url": "file://image.png",
  "action": {
  "type": "$href",
  "options": {
  "url": "file://some-local-json.json"
  "id": "1234567"
   } 
}

The version that does work is this one, which is however not usable in my setup, since I would also like to implement the $ok two-way communication:

{
"type": "label",
"text": "Open view",
 "href": {
   "url": "file://some-local-json.json",
   "options": {
   "id": "1234567"
    }
  }
}
@clsource
Copy link
Contributor

clsource commented Jul 25, 2018

I think it´s better to store the value in the cache or global apis
http://docs.jasonette.com/actions/#cache
http://docs.jasonette.com/actions/#global

So you can have the variable in both views

@darenr
Copy link
Contributor

darenr commented Jul 25, 2018

why is that an advantage? it's more work for the caller to do this and I just don't see any advantage. The value is already available in both views, in the caller because they must have it to put it in the options and, if my suggestion was implemented, it would then also be in the target view. There are issues like pass by reference or by value which might be relevant, but my suggestion there would be to treat the view to view as a function call so the options would would be passed by value.

You closed this by saying something unrelated, the variable is available in both views anyway, the issue was how to pass it to another view.

There have been others who expected the view to view mechanism to work this way, so it's certainly more intuitive.

Using the cache wouldn't work anyway. "Cache and local variables are both sandboxed per view url", so the value would not be visible in the called view. Using global variables would of course, but in 2018, using global variables to pass values between views just seems seriously outdated.

@clsource
Copy link
Contributor

Please read this

https://medium.com/@gliechtenstein/native-mobile-view-as-microservice-fd24ea62defa

Here is an example of using $href with params

{
  "type": "$href",
  "options": {
    "url": "https://jasonbase.com/things/3fj.json",
    "options": {
      "firstName": "Bart",
      "lastName": "Simpson"
    }
  }
}

@mexophantes
Copy link
Author

Using only href works, see my initial post.
I cannot find a solution to work with an action of type href. Passing doesn't work in that setup.

@darenr
Copy link
Contributor

darenr commented Aug 20, 2018

@clsource I'm not sure what the blog post you mentioned has to do with this? I also don't really understand the point about sandboxing where views all share a common global dictionary, that's not really how sandboxing works. But regardless you originally closed this issue suggestion people not use the options and instead put their parameters into the $global dictionary, and I responded that that's not a very good user experience. Now you're suggesting that we use the parameter passing mechanism that mexophantes wanted all along. Letting two views manipulate a global variable is a very bad suggestion, it's just bad software engineering. The right way is to follow the traditional stack method, which is what $href does, pass by value (not reference), then return by value (with $ok). The problem is that mexophantes says this does not work with href actions, but does with $href. I haven't tried this to know since I'm passing values around using only $href, but at least now I think we're all in agreement that we shouldn't be communicating between views using $global variables.

@hanyg
Copy link

hanyg commented Sep 7, 2018

Hello,

I am also looking for a solution. I have tried both the action and the link versions without success. I do not think the options are getting passed to the target view via the $params reference. The item triggering the link looks as follows:

{
"type": "button",
"text": "test link",
"href": {
"url": "some json url",
"options": {
"name": "hello"
}
}
}

I expected to be able to just use:

{{$params.name}}

This example is right off the website. I tried both versions, action and link. Same results. The expansion of the template expression doesn't happen.

I see there isn't really an answer in this thread, but if anyone out there has solved this , I'd like to know how.

Thanks

@clsource
Copy link
Contributor

jasonelle-archive#4

Added $env.view.params variable that holds the query params inside the url. Example https://example.com?param1=1&params2=true. Will show param1 and param2 as properties inside the params dictionary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants