Timer

Timer

UI

template

  • editor.template.components.pageX.timers.timer

    local props = {
      actionName    = "{{actionName}}",
      delay         = {{delay}},
      iterations    = {{iterations}},
      name          = "{{name}}",
    }
    
    return require("components.kwik.page_timer").new(props)

module

  • components.kwik.page_timer

    local M = {}
    ...
    ...
    function M:didShow(UI)
      self.timerObj = timer.performWithDelay( self.delay, function()
          if self.actionName then
            UI.scene:dispatchEvent({name = self.actionName })
          end
        end, self.iterations)
    end
    --

components.editor.timer

timer
  ├── buttons.lua
  ├── controller
  │   ├── cancel.lua
  │   └── save.lua
  ├── defaults
  │   └── timer.lua
  ├── index.lua
  └── timerTable.lua
  • comonents.editor.timer.index

    local model = {
      id ="timer",
      props = {
        {name="actionName", value=""},
        {name="delay",      value=0},
        {name="iterations", value = 1},
        {name="name",       value = ""},
      }
    }
    ...
    ...
    function controller:render(book, page, type, name, model)
      local dst = "App/"..book.."/"..page .."/components/timers/"..type.."/"..name ..".lua"
      local tmplt =  "editor.template/components/pageX/timers/timer.lua"
      util.mkdir("App", book, page, "components", "timers", type)
      util.saveLua(tmplt, dst, model)
      return dst
    end
    
    function controller:save(book, page, type, name, model)
      local dst = "App/"..book.."/models/"..page .."/timers/"..name..".json"
      util.mkdir("App", book, "models", page, "timers", type)
      util.saveJson(dst, model)
      return dst
    end
  • components.editor.timer.defaults

    the order of the table must be as same as the model.props table in index and must be sorted in alphavetical order

    local M = {
      actionName = "",
      delay      = 0,
      iterations = 1,
      name       = "timer-new",
    }