gwi/gwi

Types

An instruction to display.

pub opaque type Instruction(key, state, effect)

A world object.

pub type Object(key, state, effect) {
  Object(
    state: option.Option(state),
    from: option.Option(Tween(key, state, effect)),
  )
}

Constructors

A tween from an object past self.

pub type Tween(key, state, effect) {
  Tween(
    key: key,
    state: Object(key, state, effect),
    effect: effect,
  )
}

Constructors

  • Tween(
      key: key,
      state: Object(key, state, effect),
      effect: effect,
    )

Values

pub fn instruction_to_json(
  instruction: Instruction(key, state, effect),
  key_encoder: fn(key) -> json.Json,
  state_encoder: fn(state) -> json.Json,
  effect_encoder: fn(effect) -> json.Json,
) -> json.Json

Encode a instruction into a JSON object.

pub const no_object: Object(a, b, c)

A “nothing” world object, so object can be create from it or turn into it.

pub fn object_decoder(
  key_decoder: fn() -> decode.Decoder(key),
  state_decoder: fn() -> decode.Decoder(state),
  effect_decoder: fn() -> decode.Decoder(effect),
) -> decode.Decoder(Object(key, state, effect))

A decoder that decodes world object.

pub fn object_to_json(
  object: Object(key, state, effect),
  key_encoder: fn(key) -> json.Json,
  state_encoder: fn(state) -> json.Json,
  effect_encoder: fn(effect) -> json.Json,
) -> json.Json

Encode a world object into a JSON object.

pub fn process(
  model model: dynamic.Dynamic,
  msg msg: dynamic.Dynamic,
  input_handler input_handler: fn(option.Option(model), msg) -> Result(
    #(model, view),
    error,
  ),
  model_decoder model_decoder: fn() -> decode.Decoder(model),
  msg_decoder msg_decoder: fn() -> decode.Decoder(msg),
  model_to_json model_to_json: fn(model) -> json.Json,
  view_to_json view_to_json: fn(view) -> json.Json,
) -> json.Json

Take a model and a msg, put them through the input handler funtion, then return the result as a JSON object. Where:

If successed:

{
  model: output_model,
  view: output_view,
}

If failed:

{
  error: error,
}

For the model: nil, null, and undefined on Erlang, and undefined and null on JavaScript count as None.

pub fn process_string(
  model model: String,
  msg msg: String,
  input_handler input_handler: fn(option.Option(model), msg) -> Result(
    #(model, view),
    error,
  ),
  model_decoder model_decoder: fn() -> decode.Decoder(model),
  msg_decoder msg_decoder: fn() -> decode.Decoder(msg),
  model_to_json model_to_json: fn(model) -> json.Json,
  view_to_json view_to_json: fn(view) -> json.Json,
) -> String

Take a JSON string model and a JSON string msg, put them through the input handler funtion, then return the result as a JSON string. Where:

If successed:

{
  model: output_model,
  view: output_view,
}

If failed:

{
  error: error,
}

For the model: empty string count as None.

pub fn tween_from_decoder(
  key_decoder: fn() -> decode.Decoder(key),
  state_decoder: fn() -> decode.Decoder(state),
  effect_decoder: fn() -> decode.Decoder(effect),
) -> decode.Decoder(Tween(key, state, effect))

A decoder that decodes tween.

pub fn tween_to_json(
  tween_from: Tween(key, state, effect),
  key_encoder: fn(key) -> json.Json,
  state_encoder: fn(state) -> json.Json,
  effect_encoder: fn(effect) -> json.Json,
) -> json.Json

Encode a tween into a JSON object.

pub fn world_reset(
  world: dict.Dict(key, Object(key, state, effect)),
) -> dict.Dict(key, Object(key, state, effect))

Return a world without None state objects and reset all objects from to None.

pub fn world_to_instruction_list(
  world: dict.Dict(key, Object(key, state, effect)),
  converter: fn(key, state) -> view,
) -> List(Instruction(key, view, effect))

Convert a world to a list of instructions.

Search Document