-
Notifications
You must be signed in to change notification settings - Fork 741
Client API updates #9709
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
base: development
Are you sure you want to change the base?
Client API updates #9709
Changes from all commits
6974a0c
002e67b
2de1bd5
5aee559
edc993b
591337e
457d1eb
47cd100
4165acc
ccd7a3a
c41eab4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -183,18 +183,17 @@ For information on how to use *Big.js*, consult the [big.js API](https://mikemcl | |
Use the following code to create objects: | ||
|
||
```javascript | ||
mx.data.create({ | ||
entity: "MyFirstModule.Cat", | ||
callback: function(object) { | ||
console.log("Object created on server"); | ||
}, | ||
error: function(error) { | ||
console.error("Could not commit object:", error); | ||
} | ||
}); | ||
import { create } from "mx-api/data" | ||
|
||
try { | ||
const cat = await create({ entity: "MyFirstModule.Cat" }) | ||
console.log("Object created on server:", cat); | ||
} catch (err) { | ||
console.error("Could not commit object:", err); | ||
} | ||
``` | ||
|
||
For more information on creating objects, consult the [Create](https://apidocs.rnd.mendix.com/10/client/mx.data.html#.create) section of the *Mendix Client API*. | ||
For more information on creating objects, consult the [Create](https://apidocs.rnd.mendix.com/11/client-mx-api/module-mx-api_data.html#.create) section of the *Mendix Client API*. | ||
|
||
#### Changing Objects | ||
|
||
|
@@ -290,36 +289,6 @@ Use the following code to employ an asynchronous return for when your nanoflow n | |
|
||
Many APIs and functions are designed in an asynchronous way, and use callback functions or promises. A JavaScript action expects a promise to be returned. The promise should be resolved with the return value as expected in the action. | ||
|
||
#### Understanding Promises | ||
|
||
A `Promise` object represents the eventual completion (or failure) of an asynchronous operation and its resulting value. | ||
|
||
Use the following code to wrap a callback API in a promise: | ||
|
||
```javascript | ||
function AskConfirmation(question) { | ||
// BEGIN USER CODE | ||
return new Promise(function (resolve) { | ||
mx.ui.confirmation({ | ||
content: question, | ||
handler: function() { | ||
resolve(true); | ||
}, | ||
onCancel: function() { | ||
resolve(false); | ||
} | ||
}); | ||
}); | ||
// END USER CODE | ||
} | ||
``` | ||
|
||
Explaining the callback code: | ||
|
||
* Use the standard Mendix Client to show a confirmation dialog box with an **OK** and a **Cancel** button (the execution of the nanoflow halts until the user clicks one of the buttons) | ||
* The resolve will return a Boolean value, which is used as the return value of the action | ||
* In the nanoflow, the return variable can be used for an alternative flow for confirmation and cancel | ||
|
||
#### Understanding Promise API | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reading the section below this, I'm not sure why it is titled "Promise API" but the whole text is about "Fetch API"? |
||
|
||
This function uses the Fetch API: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -183,18 +183,17 @@ For information on how to use *Big.js*, consult the [big.js API](https://mikemcl | |
Use the following code to create objects: | ||
|
||
```javascript | ||
mx.data.create({ | ||
entity: "MyFirstModule.Cat", | ||
callback: function(object) { | ||
console.log("Object created on server"); | ||
}, | ||
error: function(error) { | ||
console.error("Could not commit object:", error); | ||
} | ||
}); | ||
import { create } from "mx-api/data" | ||
|
||
try { | ||
const cat = await create({ entity: "MyFirstModule.Cat" }) | ||
console.log("Object created on server:", cat); | ||
} catch (err) { | ||
console.error("Could not commit object:", err); | ||
} | ||
``` | ||
|
||
For more information on creating objects, consult the [Create](https://apidocs.rnd.mendix.com/10/client/mx.data.html#.create) section of the *Mendix Client API*. | ||
For more information on creating objects, consult the [Create](https://apidocs.rnd.mendix.com/10/client-mx-api/module-mx-api_data.html#.create) section of the *Mendix Client API*. | ||
Comment on lines
+186
to
+196
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need to keep the old information as well for those who are still using MTS versions of Mendix 10. |
||
|
||
#### Changing Objects | ||
|
||
|
@@ -290,30 +289,6 @@ Use the following code to employ an asynchronous return for when your nanoflow n | |
|
||
Many APIs and functions are designed in an asynchronous way, and use callback functions or promises. A JavaScript action expects a promise to be returned. The promise should be resolved with the return value as expected in the action. | ||
|
||
#### Understanding Promises | ||
|
||
A `Promise` object represents the eventual completion (or failure) of an asynchronous operation and its resulting value. | ||
|
||
Use the following code to wrap a callback API in a promise: | ||
|
||
```javascript | ||
function AskConfirmation(question) { | ||
// BEGIN USER CODE | ||
return new Promise(function (resolve) { | ||
mx.ui.confirmation({ | ||
content: question, | ||
handler: function() { | ||
resolve(true); | ||
}, | ||
onCancel: function() { | ||
resolve(false); | ||
} | ||
}); | ||
}); | ||
// END USER CODE | ||
} | ||
``` | ||
|
||
Comment on lines
-293
to
-316
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is still needed for customers who are using an MTS version of Mendix 10? |
||
Explaining the callback code: | ||
|
||
* Use the standard Mendix Client to show a confirmation dialog box with an **OK** and a **Cancel** button (the execution of the nanoflow halts until the user clicks one of the buttons) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see there are lots of mentions of
Promise
still in this document. Do we still need this explanation of what a Promise is, even if you don't need to use it on callback APIs?I see the next section is also about Promises,