-
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
Conversation
Mendix 11 guide for Session Management already mentions the new |
const mxObject = await create({ entity: "HowTo.GitHubUser" }); | ||
// Dynamically set attributes | ||
mxObject.getAttributes() | ||
.forEach(function(attributeName) { |
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 think we can just use arrow functions as well in the examples?
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.
Done 👍
const mxObject = await create({ entity: userEntity }); | ||
// Dynamically set attributes | ||
mxObject.getAttributes() | ||
.forEach(function(attributeName) { |
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 think we can just use arrow functions as well in the examples?
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.
Done 👍
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 have a couple of comments about the things which have been taken out of the Mendix 10 version of the document and how that affects customers who are still on earlier versions of Mendix (10.12 or 10.18).
Can you have a look and see if we need to keep some of that documentation to support customers who cannot upgrade quickly.
@@ -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. |
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,
* 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 comment
The 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"?
#### 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 | ||
} | ||
``` | ||
|
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 think this is still needed for customers who are using an MTS version of Mendix 10?
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*. |
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 think we need to keep the old information as well for those who are still using MTS versions of Mendix 10.
async function createGitHubUser(user) { | ||
try { | ||
const mxObject = await create({ entity: "HowTo.GitHubUser" }); | ||
mxObject.set("login", user.login); | ||
mxObject.set("avatar_url", user.avatar_url); | ||
return mxObject; | ||
} catch(err) { | ||
throw new Error("Could not create object:" + err.message) | ||
} |
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.
Will this work in MTS versions of Mendix 10 (e.g. 10.18)
In Mendix 10.22 we introduced the new Client API. It uses promises and works as a modern JS module instead of being attached to the global window object.
This PR removes all mentions of the old
mx.
andlogger
APIs for Mendix 10 and 11. JS actions guide was also partially rewritten using new APIs.Note that docs still mention
mx.session.getConfig("csrftoken")
in Mendix 10 guide.getCSRFToken
was introduced quite late (Mendix 10.23). Plus, at the moment there is no way to import the new API in pluggable widgets.We'll revise these docs after 10.6, 10.12 and 10.18 are out of support and after
getCSRFToken
is availaible in Pluggable Widgets.