Promote Script Folders to Classes with handler scripts

Idea created by mrwatson-gbs on Apr 7, 2016
    Active
    Score7

    Context

     

    Once FMI implement Perform Script [ by Name: ... ] - immediately + natively (Modular-FileMaker) a wealth of possibilities open up.

     

    One of the problems, however, will be scripts with the same name in different script folders, e.g. "initialise":

     

         Calendar

              initialise

              doThis

              doThat

         Email

              initialise

              doThis

              doThat

         Tasks

              initialise

              doThis

              doThat

     

    Idea Part 1

     

    A perfect way of getting around this would be to make it possible to specify the folder name as well as the script name, e.g.

     

         Perform Script [ by Name: "Calendar//initialise" ]

         Perform Script [ by Name: "Email//initialise" ]

         Perform Script [ by Name: "Tasks//initialise" ]

     

    Note: I am passively suggesting here that a double-slash may be a good separator between folder name and script name.

     

    Idea Part 2

     

    What if a script folder could be promoted into a type of "class" and have a handler script to process calls if the required child script ('method') does not exist.

     

    This could be used, for example, to implement setter + getter functionality:

     

         Perform Script [ by Name: "Calendar//SetView" ; Param: "week" ]

         Perform Script [ by Name: "Calendar//SetDate" ; Param: GetAsDate( Get ( CurrentHostTimestamp ) ) ]

        

    ...but as no SetView script exists in the Calendar folder/class, the Calendar handler script is called...

     

    Script Folder "Calendar" handler Script:

     

         Set Variable [ $Parameter ; Get ( ScriptParameter ) ]

         Set Variable [ $CallScriptName ; Get ( PerformScriptName ) ]

     

         If [ Left ( $CallScriptName ; 3 ) = "Set" ]

              # Setter

              Set Variable [ $FieldName ; Right ( $CallScriptName ; Length( $CallScriptName ) -  3 ) ]

              Set Field by Name [ $FieldName ; $Parameter ]

     

         Else If [ Left ( $CallScriptName ; 3 ) = "Get" ]

              # Getter

              Set Variable [ $FieldName ; Right ( $CallScriptName ; Length( $CallScriptName ) -  3 ) ]

              Set Variable [ $FieldName ; Get ( LayoutTableName ) & "::" & $FieldName ]

              Exit Script [ GetField( $FieldName ) ]

     

         Else

              # Unknown Method - Throw a custom error back

              Set LastError [ -2 ]

              Exit Script [ "Error: Unknown Method: " & $CallScriptName ]

     

         End If

     

    ...And thus sets the View field to "week"

     

     

    Maybe we can also make it hierarchical, so that one class handler script can call its parent class handler script .... much like abstract classes and concrete classes.

     

     

     

    Benefits

     

    • By allowing folder names to be specified script names are freed up of having to also define the context of the script (as is the case in this example from modularfilemaker.org):
      Crazy script naming.png
      (see also the similar idea on freeing up script names from script parameters)
    • adding a class handler script to a folder makes it more like a class with a bit of inheritance
    • needs more thought

     

    Use Case

     

    • Setters + Getters
    • Inheritance
    • need to think about specific use cases

     

     

    Note: This idea is very much in the brainstorming phase - PLEASE CONTRIBUTE and help develop it.

     

    Happy

         File

              Making