-5

assignment syntax would that mean any code?

While both basic assignment syntax and … can be used to the same effect, typically it's recommended that you use the assignment syntax whenever possible, as it's easier to read.

https://lhorie.github.io/mithril/mithril.request.html


I added

When the assignment syntax possible?

user.json

[{"name": "John"}, {"name": "Mary"}]

index.html

var users = m.request({method: "GET", user.json});
console.log( users() ); // undefined

I added

「typically it's recommended that you use the assignment syntax whenever possible」 means Code below?

user.json

[{"name": "John"}, {"name": "Mary"}]

index.html

var users = m.request({method: "GET", url: "user.json"}, initialValue: []});
console.log( users() );

or

var users = m.request({method: "GET", url: "user.json"}, initialValue: [{"name": "John"}, {"name": "Mary"}]});
console.log( users() );
re1
  • 3
  • 3

1 Answers1

0

This is assignment syntax:

var users = m.request({method: "GET", url: "/user"});

This is the thennable syntaxe

var users = m.prop([]); //default value
m.request({method: "GET", url: "/user"}).then(users)
fluminis
  • 3,575
  • 4
  • 34
  • 47
  • When the assignment syntax possible? I think always 「getter-setter holds an undefined value until the AJAX request completes」.so there is no choice but to use thennable syntax. I want to know How to use AJAX request assignment syntax 「getter-setter value is not undefined」 – re1 Dec 17 '15 at 00:02
  • your example seems broken. `m.request` need an object with an url and optionally some data to make the ajax request to the server! Moreover, m.request gives you a promize that will be resolved when the request end. So right after the call to m.request the value is undefined (you can use initialValue to define an initial value) – fluminis Dec 17 '15 at 07:49
  • I made modifications.「typically it's recommended that you use the assignment syntax whenever possible」 means define an initial value? – re1 Dec 18 '15 at 00:21