duil

duil

Source:

duil = data + ui + loop

Classes

Widget

Object that re-renders when its data changes.

Group

Collection of models connected to views.

List

Data connected to Elements using a template.

Members

(static, constant) version

Semantic Version of duil.

Source:

Methods

(static) diff(first, second, prefixopt) → {Object|null}

Return the difference between two objects or arrays.

Source:

The diff format returned by this function (aka "normal" deltas):

  • {prop: [undefined, value]} - prop was created and set to value
  • {prop: [value, undefined]} - prop was removed; last value was value
  • {prop: [value, value2]} - prop was changed from value to value2

Other unusual, but legal, values (aka "weird" deltas):

  • null - no difference between the objects
  • {prop: [undefined, undefined]} - prop's creation was cancelled
  • {prop: undefined} - prop's change has been effected (cheaper way of deleting keys from a diff)
Parameters:
Name Type Attributes Description
first Object | Array

The first item to compare.

second Object | Array

The second item to compare.

prefix string <optional>

Optional prefix for the current key.

Returns:

Differences between the two objects, or null if none.

Type
Object | null

(static) merge(first, second) → {Object|null}

Return the diff that results from merging the two diffs.

Source:

In theory, some merges are not valid:

  • add + add - adding something that's already there
  • update + add - updating something that doesn't exist
  • remove + update - updating something that's been removed
  • remove + remove - removing something that's been removed

Nonetheless, for these situations, we infer what was meant by taking the pre-state of the first delta and combining it with the post-state of the second delta. We consider this sensible because the diffs do not need to represent sequential states and could represent states at very different times (e.g. jumping from one time to another in a timeline).

Basic rules:

  • normal + normal = normal
  • normal + weird = normal (the weird is ignored)
  • weird + normal = normal (again, the weird is ignored)
  • weird + weird = null (two weirds make a null)

In general, merging any two "normal" deltas together will result in a normal delta. Merging any two "weird" deltas will result in null.

Parameters:
Name Type Description
first Object

The first diff to merge.

second Object

The second diff to merge.

Returns:

The resulting diff when the two are merged.

Type
Object | null

Events

init

Fired when widget is initialized.

Source:
Properties:
Name Type Default Description
type string 'init'

The event type.

target string this

The widget itself.

data Object {}

The data payload.

render

Fired when widget finishes rendering.

Source:
Properties:
Name Type Default Description
type string 'render'

The event type.

target string this

The widget itself.

data Object {}

The data payload.

change

Fired when widget data changes or duil.Widget#set is called with force=true.

Source:
Properties:
Name Type Default Description
type string 'change'

The event type.

target string this

The widget itself.

data.changes Object {changes}

The data payload.

create

Fired when an item in a group is created.

Source:
Properties:
Name Type Default Description
type string 'create'

The event type.

target string this

The widget itself.

data.view Object

The view.

data.model Object

The associated model.

data.index Object

The index of the model.

update

Fired when an item in a group is updated.

Source:
Properties:
Name Type Default Description
type string 'update'

The event type.

target string this

The widget itself.

data.view Object

The view.

data.model Object

The associated model.

data.index Object

The index of the model.

remove

Fired when an item in a group is removed.

Source:
Properties:
Name Type Default Description
type string 'remove'

The event type.

target string this

The widget itself.

data.view Object

The view.

data.index Object

The previous index of the view.