Building Apps with Jigx

Best practice

9min
when to use solution state (global state) state docid 0js3trstyj4kcu6vviv1y manages the state of the app, including the ui's data and the user's interactions, and is best used in scenarios with a one to one relationship ; for example, a field services person selects one job or task to complete, or a pilot selects one mission to fly design pattern singletons setup set the id to be stored in the solution state, using the set state action the id is the least amount of data required to identify each job uniquely the id is used throughout the solution to reference the necessary data in each of the solution's {{jig}} s in the datasource queries use the id to return the required data in a global datasource https //docs jigx com/datasources#gcn9o query reference the data required the global datasource is referenced in each {{jig}} where the data is required in the individual {{jig}} 's datasource https //docs jigx com/datasources#2ad3k query the query is configured to only return the exact data required for that {{jig}} using the id as the unique identifier set solution state (action) actions \ children \ type action set state options title task a state =@ctx solution state id value =@ctx solution state id use solution state (datasource) datasources contactdata type datasource sqlite options isdocument true provider data provider dynamic entities \ default/tasks query | select id, '$ firstname', '$ lastname', '$ jobtitle', '$ companyname', '$ phone', '$ email' from \[default/tasks] where id = @taskid queryparameters taskid =@ctx solution state id state resources and code samples state docid 0js3trstyj4kcu6vviv1y set state docid\ fyzrungim4tiuigoehwip reset state docid\ eqv7lutbz9p2 zyfcosyv state docid 0js3trstyj4kcu6vviv1y when to use inputs passing data using inputs docid\ uwuun8rfrbpkqniayc0a1 are used in complex apps to pass multiple variables between {{jig}} s using parameters, and is best used in scenarios where there is a one to many relationship , for example, a manager needs to check on the progress of each field service worker design pattern mediator setup set up parameters in the {{jig}} that needs to pass data, then in the {{jig}} needing to receive the data set up inputs multiple parameters and inputs can be configured on a single {{jig}} in the components of the {{jig}} use expressions to reference the data passed in, for example, =@ctx jig inputs parametername set parameters actions \ children \ type action go to options title team progress linkto team progress \# define what data the parameters must use \# the parameters name is used in the receiving jig's input expression parameters taskid =@ctx components taskid state value taskstatus =@ctx components taskstatus state value taskcost =@ctx components taskcost state value taskassignee =@ctx components taskassignee state value use input title team progress type jig default \# define the input type inputs taskid type number required true taskassignee type string required true taskstatus type string required true taskcost type number required false children \ type component expander options header centerelement type component titles options align left \# use the parameter in the input expression \# to show who is working on the task title =@ctx jig inputs taskassignee icon professions man construction 2 iconcolor color10 children \ type component entity options children \ type component entity field options label task status \# use the parameter in the input expression to show the status value =@ctx jig inputs taskstatus \ type component entity field options label task costs \# use the parameter in the input expression to show the cost value =@ctx jig inputs taskcost input resources and code samples passing data using inputs docid\ uwuun8rfrbpkqniayc0a1 passing data using inputs docid\ uwuun8rfrbpkqniayc0a1 when to use outputs passing data using outputs docid\ bjdqkoxxisxrb5rs1xbvt are used to combine multiple {{jig}} s into one {{jig}} outputs pass variables from each {{jig}} into the next {{jig}} , and is best used in scenarios where there is a many to one relationship , for example, a manager needs to report on the progress of the team creating a master detail form is another usecase for outputs design pattern observer setup in the {{jig}} that will pass the data define the output property with an expression that will pass the variable, such as an id in the composite {{jig}} , which combines multiple {{jig}} s, define the input property on the {{jig}} that must receive the variable team progress (output) title team list type jig list icon contact ishorizontal true ishorizontalscrollindicatorhidden false isselectable true hasactiveitem true datasources team type datasource sqlite options provider data provider dynamic entities \ default/tasks query | select id, '$ taskid', '$ profile', '$ taskassignee', '$ team' from \[default/tasks] where '$ team' is not null \# set the output to use the id defined in the set state \# the output key will be passed in the input property, \# in the composite jig outputs output key =@ctx solution state teamid data =@ctx datasources team item type component list item options title =@ctx current item taskassignee horizontalitemsize large progress =@ctx current item id = @ctx solution state teamid ? 1 0 color \ when =@ctx current item id = @ctx solution state teamid ? true \ false color color2 iscontained true leftelement element image text '' uri =@ctx current item profile onpress type action action list options actions \# set the solution state and the value as id of the current selected item \ type action set state options state =@ctx solution state teamid value =@ctx current item id team title team progress type jig list icon contact datasources team update type datasource sqlite options provider data provider dynamic entities \ default/tasks \# define a query parameter to use the output property, \# when it is passed into the jig query | select id, '$ taskid', '$ taskassignee', '$ taskcost', '$ taskstatus', '$ taskprofile' from \[default/tasks] where id = @statid queryparameters statid =@ctx solution state teamid data =@ctx datasources team update item type component list item options title =@ctx current item taskid subtitle =@ctx current item taskcost leftelement element avatar text =@ctx current item taskassignee uri =@ctx current item taskprofile rightelement element value text =@ctx current item taskstatus team report (input) title team report type jig composite children \ jigid team list instanceid team profile \ jigid team data inputs id =@ctx jigs team profile outputs output key output resources and code samples passing data using outputs docid\ bjdqkoxxisxrb5rs1xbvt passing data using outputs docid\ bjdqkoxxisxrb5rs1xbvt performance optimization using an id in your datasource enhances performance, particularly when handling large volumes of records datasource datasources team update type datasource sqlite options provider data provider dynamic entities \ default/tasks query | select id, '$ taskid', '$ taskassignee', '$ taskcost', '$ taskstatus', '$ taskprofile' from \[default/tasks] where id = @statid queryparameters statid =@ctx solution state teamid