module Disposable::Twin::Sync::SkipUnchanged

This will skip unchanged properties in sync. To use this for all nested form do as follows.

class SongForm < Reform::Form
  feature Sync::SkipUnchanged

Public Class Methods

included(base) click to toggle source
# File lib/disposable/twin/sync.rb, line 134
def self.included(base)
  base.send :include, Disposable::Twin::Changed
end

Public Instance Methods

sync_options(options) click to toggle source
Calls superclass method
# File lib/disposable/twin/sync.rb, line 138
def sync_options(options)
  # DISCUSS: we currently don't track if nested forms have changed (only their attributes). that's why i include them all here, which
  # is additional sync work/slightly wrong. solution: allow forms to form.changed? not sure how to do that with collections.
  scalars   = schema.each(scalar: true).collect { |dfn| dfn[:name ]}
  unchanged = scalars - changed.keys

  # exclude unchanged scalars, nested forms and changed scalars still go in here!
  options.exclude!(unchanged)
  super
end