Jasonette / JASONETTE-iOS

📡 Native App over HTTP, on iOS
https://www.jasonette.com
MIT License
5.27k stars 352 forks source link

href as action does not carry over parameters #347

Open mexophantes opened 5 years ago

mexophantes commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

@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 commented 5 years ago

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 commented 4 years ago

https://github.com/jasonelle/jasonette-ios/pull/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.