Making it possible to store directly the reference to a function or the function itself as a part of the value in a document
{
cmsFunction: Function.byName("activate_numberOfShareholdersQuestions")
}
or
{
sell: (document) => {}
}
Fauna passes the reference to the document automatically to the function if the function includes the parameter “document” (like in ABAC)
(document) => {
// activate_numberOfShareholdersQuestions
}
Use Case 1:
We have CMS(Content management system) functions specific to single documents. With that change it would become easier working with functions in the context of documents.
Instead of doing this as today:
Document (Collection Answer)
{
cmsFunction:"activate_numberOfShareholdersQuestions"
}
Function activate_numberOfShareholdersQuestions
() => {
let document = Answer.byId("56546545546456564") // hardcoded reference to the connected document
}
Client
let cmsFunction = Function.byName(Answer.byId("56546545546456564").cmsFunction)
We could simplify it like that
Document (Collection Answer)
{
cmsFunction: Function.byName("activate_numberOfShareholdersQuestions")
}
Function activate_numberOfShareholdersQuestions
(document ) => {
// no hardcoded reference needed
}
Client
Answer.byId("56546545546456564").cmsFunction()
Use Case 2
Scoped Functions - Keeps functions organized and structured in a scaled environment.
e.g.
Car.byId("34223424").sell()
Car.sell()