Skip to content

Understanding change sets

E. Lynette Rayle edited this page Feb 17, 2022 · 8 revisions

back to Introduction

Goals

  • Become familiar with terms and libraries associated with Change Sets.

References: Valkyrie Wiki | Reform API Documentation | Reform Code | Disposable Code

Purpose

Provides separation of the persistence model from models used for updating data, primarily within forms. They provide support for validations, dirty tracking, and coercion of data values.

Libraries

Highly recommend reading Disposable and Reform documentation, starting with Disposable. Change sets extend the Reform API which relies heavily on Disposable.

  • Disposable creates a twin with properties allowing for changes to the twin that can either be discarded or synced with the resource to apply the changes to the resource. The twin can be used to render a form using Rails, SimpleForm, or other form generation approach.
  • Reform extends Disposable to provide dirty tracking of changes and data validation before syncing. It provides a means for controlling the twinning and syncing process.

Terminology

  • twin - non-persistent domain object associated with persistent model object. -- defined by Disposable
  • twin #sync - method that copies property data from twin to model object attributes; does not save -- defined by Disposable
  • twin #save - method that syncs a twin to a model and then saves the model -- defined by Disposable
    • NOT supported by Valkyrie because resources do not define #save method; instead, call #sync method on the change set and then use persister to save the resource
  • nested twin - a property in a twin that is associated with a model other than the main twin's model -- defined by Disposable
  • automatic coercion - coerce an incoming value to a specific dry-type (e.g. for type Types::Params::Integer, "1" will coerce to 1) -- defined by Disposable
  • manual coercion - can override twin setters to add code that coerces the incoming value (e.g. def title=(v); super(v.trim); end) -- defined by Disposable
  • composition - create a twin from 2 or more model objects which is useful for creating a form gathers data for multiple persistent objects -- defined by Disposable
  • dirty tracking - the ability to check if a property within the twin has changed and to check if the twin as a whole has changed

Previous | Next