Module: Disposable::Twin::Sync::SkipUnchanged

Defined in:
lib/disposable/twin/sync.rb

Overview

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

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



134
135
136
# File 'lib/disposable/twin/sync.rb', line 134

def self.included(base)
  base.send :include, Disposable::Twin::Changed
end

Instance Method Details

#sync_options(options) ⇒ Object



138
139
140
141
142
143
144
145
146
147
# 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