Skip to content

Add module versioning #27

@rtjoa

Description

@rtjoa

Each module should have a integer version number associated with it.

When we change how the data for a module is represented, we increment its version number, and add a function to upgrade the version.

For example, say TextModule starts at version 1, and its data looks like {text: "Lorem ipsum"}:

// TextModule.js
TextModule.version = 1;

When we add a 'font_family' property to text modules, we increment the version to 2 and define a function to dictate how we upgrade from version 1 to 2:

// TextModule.js
TextModule.version = 2;
// TextModuleUpgrader.js
const UPGRADE_FUNCTIONS = {
  2: (data) => ({...data, 'font_family': 'Arial'});
}

If, in another update, we decide to represent text data as HTML, then we could do the following:

// TextModule.js
TextModule.version = 3;
// TextModuleUpgrader.js
const UPGRADE_FUNCTIONS = {
  2: (data) => ({...data, 'font_family': 'Arial'});
  3: (data) => `<p style="font-family:${data['font_family']}">${data['text'}</p>`;
}

Then, if need to render/edit a Text Module from version 1, we set its data to UPGRADE_FUNCTIONS[3](UPGRADE_FUNCTIONS[2](data)).

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions