# Wijmo_Grid_Immutable.Immutabilityprovider

## Content

<div class="content__tsd">
						<div style="display:flex;justify-content:space-between;align-items:center">
							<h1>
								ImmutabilityProvider Class
							</h1>
						</div>
						<section class="tsd-comment">
							<div class="tsd-comment">
								<div class="lead">
									<p>The <strong>ImmutabilityProvider</strong> object,
										being attached to a <a href="wijmo_grid.flexgrid.html">wijmo.grid.FlexGrid</a> control,
										allows the latter to perform data edits without mutating the underlying
										data. Instead, this class provides a data change event, which can be used to dispatch
										change actions to the global <em>Store</em>, such as a
									<a href="https://redux.js.org/" target="_blank">Redux</a> <em>Store</em>.</p>
								</div>
								<p>In framework interops, this class is usually represented by a framework specific
									component, like a <a href="../modules/wijmo_react_grid_immutable.html#immutabilityprovider">wijmo.react.grid.immutable.ImmutabilityProvider</a> component
									for <a href="https://reactjs.org/" target="_blank">React</a>,
								which is more convenient to use in the context of the framework.</p>
								<p>The controlled <strong>FlexGrid</strong> control should not specify its <strong>itemsSource</strong>. Instead, the
									<strong>itemsSource</strong> property of this class instance should be assigned with the
								immutable array from the <em>Store</em>, which grid will display and edit.</p>
								<p>When a user edits data via the datagrid,
									the <a href="wijmo_grid_immutable.immutabilityprovider.html#datachanged">wijmo.grid.immutable.ImmutabilityProvider.dataChanged</a> event is triggered,
									bringing all the necessary information to you about the change (which item is affected,
									if item was changed or added or deleted, and so on). This event should be used to dispatch
								corresponding data change actions to the <em>Store</em>.</p>
								<p>Note that <strong>FlexGrid</strong> edits data on a row level basis, which means that you can change multiple
									cell values in the same row, and only after you move focus out of the row, all the changes
									to the row will be applied simultaneously. Or you can press the <em>Cancel</em> key to cancel all
								the changes in the row. The same is true for adding a row into the datagrid.</p>
								<p>Note also that some changes like pasting a text into the datagrid, or deleting rows,
									can affect multiple rows. In this case <strong>ImmutabilityProvider</strong> will trigger
									the <a href="wijmo_grid_immutable.immutabilityprovider.html#datachanged">ImmutabilityProvider.dataChanged</a> event
									multiple times, separately for each affected row. This simplifies data change processing
								in the <em>Store</em> reducers.</p>
								<p>This example demonstrates a fully editable <strong>FlexGrid</strong> component, with an associated
									<strong>ImmutabilityProvider</strong> component bound to an array from the <em>Redux Store</em>. The dataChanged
								event handler dispatches corresponding data change actions to the <em>Store</em>.</p>
								<pre><code class="language-typescript">  <span class="hljs-keyword">import</span> { ImmutabilityProvider, DataChangeEventArgs, DataChangeAction } <span class="hljs-keyword">from</span> <span class="hljs-string">'@mescius/wijmo.grid.immutable'</span>;
  <span class="hljs-keyword">import</span> { FlexGrid } <span class="hljs-keyword">from</span> <span class="hljs-string">'@mescius/wijmo.grid'</span>;
  <span class="hljs-keyword">import</span> { store } <span class="hljs-keyword">from</span> <span class="hljs-string">'./store'</span>;
  <span class="hljs-keyword">import</span> { addItemAction, removeItemAction, changeItemAction } <span class="hljs-keyword">from</span> <span class="hljs-string">'./actions'</span>;

  <span class="hljs-keyword">const</span> grid = <span class="hljs-keyword">new</span> FlexGrid(<span class="hljs-string">'#grid'</span>, {
      allowAddNew: <span class="hljs-literal">true</span>,
      allowDelete: <span class="hljs-literal">true</span>
  });
  <span class="hljs-keyword">const</span> provider = <span class="hljs-keyword">new</span> ImmutabilityProvider(grid, {
      itemsSource: store.getState().items,
      dataChanged: <span class="hljs-function">(<span class="hljs-params">s: ImmutabilityProvider, e: DataChangeEventArgs</span>) =&gt;</span> {
         <span class="hljs-keyword">switch</span> (e.action) {
              <span class="hljs-keyword">case</span> DataChangeAction.Add:
                  store.dispatch(addItemAction(e.newItem));
                <span class="hljs-keyword">break</span>;
              <span class="hljs-keyword">case</span> DataChangeAction.Remove:
                  store.dispatch(removeItemAction(e.newItem, e.itemIndex));
                  <span class="hljs-keyword">break</span>;
            <span class="hljs-keyword">case</span> DataChangeAction.Change:
                  store.dispatch(changeItemAction(e.newItem, e.itemIndex));
                  <span class="hljs-keyword">break</span>;
         }
      }
  });
  store.subscribe(<span class="hljs-function"><span class="hljs-params">()</span> =&gt;</span> {
      provider.itemsSource = store.getState().items;
  })</code></pre>
							</div>
						</section>
						<section class="tsd-type-parameters">
							<h3>Type parameters</h3>
							<ul class="tsd-type-parameters">
								<li>
									<h4>T</h4>
								</li>
							</ul>
						</section>
						<section class="tsd-hierarchy">
							<h3>Heirarchy</h3>
							<ul class="tsd-hierarchy">
								<li>
									<span class="target">ImmutabilityProvider</span>
								</li>
							</ul>
						</section>
						<section class="tsd-index-group">
							<section class="tsd-index-panel">
								<div class="tsd-index-content">
									<section class="tsd-index-section ">
										<div class="title">
											<div class="gc_api_tree-item_icon_img_wrapper">
												<div class="gc_api_tree-item_icon_img" data-expand="true">
												</div>
											</div>
											<h3>
												Constructors
											</h3>
										</div>
										<ul class="tsd-index-list">
											<li class="tsd-kind-constructor tsd-parent-kind-class"><a href="wijmo_grid_immutable.immutabilityprovider.html#constructor" class="tsd-kind-icon">constructor</a></li>
										</ul>
									</section>
									<section class="tsd-index-section ">
										<div class="title">
											<div class="gc_api_tree-item_icon_img_wrapper">
												<div class="gc_api_tree-item_icon_img" data-expand="true">
												</div>
											</div>
											<h3>
												Properties
											</h3>
										</div>
										<ul class="tsd-index-list">
											<li class="tsd-kind-property tsd-parent-kind-class"><a href="wijmo_grid_immutable.immutabilityprovider.html#collectionview" class="tsd-kind-icon">collection<wbr>View</a></li>
											<li class="tsd-kind-property tsd-parent-kind-class"><a href="wijmo_grid_immutable.immutabilityprovider.html#grid" class="tsd-kind-icon">grid</a></li>
											<li class="tsd-kind-property tsd-parent-kind-class"><a href="wijmo_grid_immutable.immutabilityprovider.html#itemssource" class="tsd-kind-icon">items<wbr>Source</a></li>
										</ul>
									</section>
									<section class="tsd-index-section ">
										<div class="title">
											<div class="gc_api_tree-item_icon_img_wrapper">
												<div class="gc_api_tree-item_icon_img" data-expand="true">
												</div>
											</div>
											<h3>
												Methods
											</h3>
										</div>
										<ul class="tsd-index-list">
											<li class="tsd-kind-method tsd-parent-kind-class"><a href="wijmo_grid_immutable.immutabilityprovider.html#oncloningitem" class="tsd-kind-icon">on<wbr>Cloning<wbr>Item</a></li>
											<li class="tsd-kind-method tsd-parent-kind-class"><a href="wijmo_grid_immutable.immutabilityprovider.html#ondatachanged" class="tsd-kind-icon">on<wbr>Data<wbr>Changed</a></li>
										</ul>
									</section>
									<section class="tsd-index-section ">
										<div class="title">
											<div class="gc_api_tree-item_icon_img_wrapper">
												<div class="gc_api_tree-item_icon_img" data-expand="true">
												</div>
											</div>
											<h3>
												Events
											</h3>
										</div>
										<ul class="tsd-index-list">
											<li class="tsd-kind-event tsd-parent-kind-class"><a href="wijmo_grid_immutable.immutabilityprovider.html#cloningitem" class="tsd-kind-icon">cloning<wbr>Item</a></li>
											<li class="tsd-kind-event tsd-parent-kind-class"><a href="wijmo_grid_immutable.immutabilityprovider.html#datachanged" class="tsd-kind-icon">data<wbr>Changed</a></li>
										</ul>
									</section>
								</div>
							</section>
						</section>
						<section class="tsd-panel-group tsd-member-group ">
							<h2>Constructors</h2>
							<section class="tsd-panel tsd-member tsd-kind-constructor tsd-parent-kind-class">
								<a name="constructor" class="tsd-anchor"></a>
								<h3>constructor</h3>
								<ul class="tsd-signatures tsd-kind-constructor tsd-parent-kind-class">
									<li class="tsd-signature tsd-kind-icon">new <wbr>Immutability<wbr>Provider<span class="tsd-signature-symbol">(</span>grid<span class="tsd-signature-symbol">: </span><a href="wijmo_grid.flexgrid.html" class="tsd-signature-type">FlexGrid</a>, options<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="wijmo_grid_immutable.immutabilityprovider.html" class="tsd-signature-type">ImmutabilityProvider</a></li>
								</ul>
								<ul class="tsd-descriptions">
									<li class="tsd-description">
										<aside class="tsd-sources">
										</aside>
										<div class="tsd-comment">
											<div class="lead">
												<p>Creates an instance of the ImmutabilityProvider attached to the specified FlexGrid
												control.</p>
											</div>
										</div>
										<h4 class="tsd-parameters-title">Parameters</h4>
										<ul class="tsd-parameters">
											<li>
												<h5>grid: <a href="wijmo_grid.flexgrid.html" class="tsd-signature-type">FlexGrid</a></h5>
												<div class="tsd-comment">
													<div class="lead">
														<p><a href="wijmo_grid.flexgrid.html">FlexGrid</a> control to attach to.</p>
													</div>
												</div>
											</li>
											<li>
												<h5><span class="tsd-flag ts-flagOptional">Optional</span> options: <span class="tsd-signature-type">any</span></h5>
												<div class="tsd-comment">
													<div class="lead">
														<p>Initialization options for the ImmutabilityProvider instance.</p>
													</div>
												</div>
											</li>
										</ul>
										<h4 class="tsd-returns-title">Returns <a href="wijmo_grid_immutable.immutabilityprovider.html" class="tsd-signature-type">ImmutabilityProvider</a></h4>
									</li>
								</ul>
							</section>
						</section>
						<section class="tsd-panel-group tsd-member-group ">
							<h2>Properties</h2>
							<section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class">
								<a name="collectionview" class="tsd-anchor"></a>
								<h3>collectionView</h3>
								<div class="tsd-signature tsd-kind-icon">collection<wbr>View<span class="tsd-signature-symbol">:</span> <a href="wijmo.collectionview.html" class="tsd-signature-type">CollectionView</a><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">T</span><span class="tsd-signature-symbol">&gt;</span></div>
								<aside class="tsd-sources">
								</aside>
								<div class="tsd-comment">
									<div class="lead">
										<p>Gets a <a href="wijmo.collectionview.html">CollectionView</a> object internally maintained by the ImmutabilityProvider.
											You <em>can not</em> change data in this CollectionView, instead any data changes must be
											dispatched to the <em>Store</em>.
											But you can change its sort/group/filter settings, use currency
										and data change events.</p>
									</div>
								</div>
							</section>
							<section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class">
								<a name="grid" class="tsd-anchor"></a>
								<h3>grid</h3>
								<div class="tsd-signature tsd-kind-icon">grid<span class="tsd-signature-symbol">:</span> <a href="wijmo_grid.flexgrid.html" class="tsd-signature-type">FlexGrid</a></div>
								<aside class="tsd-sources">
								</aside>
								<div class="tsd-comment">
									<div class="lead">
										<p>Gets a <a href="wijmo_grid.flexgrid.html">FlexGrid</a> instance controlled by the ImmutabilityProvider.</p>
									</div>
								</div>
							</section>
							<section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class">
								<a name="itemssource" class="tsd-anchor"></a>
								<h3>itemsSource</h3>
								<div class="tsd-signature tsd-kind-icon">items<wbr>Source<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">any</span></div>
								<aside class="tsd-sources">
								</aside>
								<div class="tsd-comment">
									<div class="lead">
										<p>Gets or sets a source data array that should be displayed in the controlled
											FlexGrid. The <strong>FlexGrid.itemsSource</strong> property <strong>should not</strong> be assigned.
											Every time a new version of the source array appears in the <em>Store</em>, this
											property must be re-assigned with this new array instance. This can be done, for example,
										in the handler function for the <em>Store</em> change event.</p>
									</div>
								</div>
							</section>
						</section>
						<section class="tsd-panel-group tsd-member-group ">
							<h2>Methods</h2>
							<section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class">
								<a name="oncloningitem" class="tsd-anchor"></a>
								<h3>onCloningItem</h3>
								<ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class">
									<li class="tsd-signature tsd-kind-icon">on<wbr>Cloning<wbr>Item<span class="tsd-signature-symbol">(</span>e<span class="tsd-signature-symbol">: </span><a href="wijmo_grid_immutable.cloningitemeventargs.html" class="tsd-signature-type">CloningItemEventArgs</a><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">void</span></li>
								</ul>
								<ul class="tsd-descriptions">
									<li class="tsd-description">
										<aside class="tsd-sources">
										</aside>
										<div class="tsd-comment">
											<div class="lead">
												<p>Raises the <a href="wijmo_grid_immutable.immutabilityprovider.html#cloningitem">cloningItem</a> event.</p>
											</div>
										</div>
										<h4 class="tsd-parameters-title">Parameters</h4>
										<ul class="tsd-parameters">
											<li>
												<h5>e: <a href="wijmo_grid_immutable.cloningitemeventargs.html" class="tsd-signature-type">CloningItemEventArgs</a></h5>
												<div class="tsd-comment">
													<p><a href="wijmo_grid_immutable.cloningitemeventargs.html">CloningItemEventArgs</a> that contains the event data.</p>
												</div>
											</li>
										</ul>
										<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4>
									</li>
								</ul>
							</section>
							<section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class">
								<a name="ondatachanged" class="tsd-anchor"></a>
								<h3>onDataChanged</h3>
								<ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class">
									<li class="tsd-signature tsd-kind-icon">on<wbr>Data<wbr>Changed<span class="tsd-signature-symbol">(</span>e<span class="tsd-signature-symbol">: </span><a href="wijmo_grid_immutable.datachangeeventargs.html" class="tsd-signature-type">DataChangeEventArgs</a><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">void</span></li>
								</ul>
								<ul class="tsd-descriptions">
									<li class="tsd-description">
										<aside class="tsd-sources">
										</aside>
										<div class="tsd-comment">
											<div class="lead">
												<p>Raises the <a href="wijmo_grid_immutable.immutabilityprovider.html#datachanged">dataChanged</a> event.</p>
											</div>
										</div>
										<h4 class="tsd-parameters-title">Parameters</h4>
										<ul class="tsd-parameters">
											<li>
												<h5>e: <a href="wijmo_grid_immutable.datachangeeventargs.html" class="tsd-signature-type">DataChangeEventArgs</a></h5>
												<div class="tsd-comment">
													<p><a href="wijmo_grid_immutable.datachangeeventargs.html">DataChangeEventArgs</a> that contains the event data.</p>
												</div>
											</li>
										</ul>
										<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4>
									</li>
								</ul>
							</section>
						</section>
						<section class="tsd-panel-group tsd-member-group ">
							<h2>Events</h2>
							<section class="tsd-panel tsd-member tsd-kind-event tsd-parent-kind-class">
								<a name="cloningitem" class="tsd-anchor"></a>
								<h3>cloningItem</h3>
								<div class="tsd-signature tsd-kind-icon">cloning<wbr>Item<span class="tsd-signature-symbol">:</span> <a href="wijmo.event.html" class="tsd-signature-type">Event</a><span class="tsd-signature-symbol">&lt;</span><a href="wijmo_grid.flexgrid.html" class="tsd-signature-type">FlexGrid</a><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">&gt;</span><span class="tsd-signature-symbol">, </span><a href="wijmo_grid_immutable.cloningitemeventargs.html" class="tsd-signature-type">CloningItemEventArgs</a><span class="tsd-signature-symbol">&gt;</span></div>
								<aside class="tsd-sources">
								</aside>
								<div class="tsd-comment">
									<div class="lead">
										<p>Triggered when <a href="wijmo_grid.flexgrid.html">FlexGrid</a> needs to create a clone of an item which is
										about to be changed.</p>
									</div>
									<p>This event allows you to provide a custom logic for cloning items.
										The cloned item should be assigned to the <a href="wijmo_grid_immutable.cloningitemeventargs.html#cloneditem">CloningItemEventArgs.clonedItem</a>
									property of the event arguments.</p>
								</div>
							</section>
							<section class="tsd-panel tsd-member tsd-kind-event tsd-parent-kind-class">
								<a name="datachanged" class="tsd-anchor"></a>
								<h3>dataChanged</h3>
								<div class="tsd-signature tsd-kind-icon">data<wbr>Changed<span class="tsd-signature-symbol">:</span> <a href="wijmo.event.html" class="tsd-signature-type">Event</a><span class="tsd-signature-symbol">&lt;</span><a href="wijmo_grid.flexgrid.html" class="tsd-signature-type">FlexGrid</a><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">&gt;</span><span class="tsd-signature-symbol">, </span><a href="wijmo_grid_immutable.datachangeeventargs.html" class="tsd-signature-type">DataChangeEventArgs</a><span class="tsd-signature-symbol">&gt;</span></div>
								<aside class="tsd-sources">
								</aside>
								<div class="tsd-comment">
									<div class="lead">
										<p>Triggered after a user has added, removed or changed a data item in the
											controlled FlexGrid instance.
										Can be used to dispatch a corresponding data change action to the <em>Store</em>.</p>
									</div>
								</div>
							</section>
						</section>
					</div>