IGListKit/docs/generating-your-models-using-remodel.html
Tim Oliver 6a521eaf60 Regenerate IGListKit documentation via jazzy
Summary: Regenerated the IGListKit documentation via jazzy.

Reviewed By: fabiomassimo

Differential Revision: D57263196

fbshipit-source-id: 1a649e29a4bfa0d12fa81d00f96ea9264a68f013
2024-05-12 21:14:35 -07:00

463 lines
20 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<title>Generating your models using remodel Reference</title>
<link rel="stylesheet" type="text/css" href="css/jazzy.css" />
<link rel="stylesheet" type="text/css" href="css/highlight.css" />
<meta charset='utf-8'>
<script src="js/jquery.min.js" defer></script>
<script src="js/jazzy.js" defer></script>
<script src="js/lunr.min.js" defer></script>
<script src="js/typeahead.jquery.js" defer></script>
<script src="js/jazzy.search.js" defer></script>
</head>
<body>
<a title="Generating your models using remodel Reference"></a>
<header>
<div class="content-wrapper">
<p><a href="index.html">IGListKit 4.1.0 Docs</a> (96% documented)</p>
<p class="header-right"><a href="https://github.com/Instagram/IGListKit"><img src="img/gh.png" alt="GitHub"/>View on GitHub</a></p>
<div class="header-right">
<form role="search" action="search.json">
<input type="text" placeholder="Search documentation" data-typeahead>
</form>
</div>
</div>
</header>
<div class="content-wrapper">
<p id="breadcrumbs">
<a href="index.html">IGListKit</a>
<img id="carat" src="img/carat.png" alt=""/>
<a href="Guides.html">Guides</a>
<img id="carat" src="img/carat.png" alt=""/>
Generating your models using remodel Reference
</p>
</div>
<div class="content-wrapper">
<nav class="sidebar">
<ul class="nav-groups">
<li class="nav-group-name">
<a href="Guides.html">Guides</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="best-practices-and-faq.html">Best Practices and FAQ</a>
</li>
<li class="nav-group-task">
<a href="generating-your-models-using-remodel.html">Generating your models using remodel</a>
</li>
<li class="nav-group-task">
<a href="getting-started.html">Getting Started</a>
</li>
<li class="nav-group-task">
<a href="iglistdiffable-and-equality.html">IGListDiffable and Equality</a>
</li>
<li class="nav-group-task">
<a href="installation.html">Installation</a>
</li>
<li class="nav-group-task">
<a href="migration.html">Migration</a>
</li>
<li class="nav-group-task">
<a href="modeling-and-binding.html">Modeling and Binding</a>
</li>
<li class="nav-group-task">
<a href="vision.html">VISION</a>
</li>
<li class="nav-group-task">
<a href="working-with-core-data.html">Working with Core Data</a>
</li>
<li class="nav-group-task">
<a href="working-with-uicollectionview.html">Working with UICollectionView</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="Classes.html">Classes</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="Classes/IGListAdapter.html">IGListAdapter</a>
</li>
<li class="nav-group-task">
<a href="Classes/IGListAdapterUpdater.html">IGListAdapterUpdater</a>
</li>
<li class="nav-group-task">
<a href="Classes/IGListBatchUpdateData.html">IGListBatchUpdateData</a>
</li>
<li class="nav-group-task">
<a href="Classes/IGListBindingSectionController.html">IGListBindingSectionController</a>
</li>
<li class="nav-group-task">
<a href="Classes/IGListBindingSingleSectionController.html">IGListBindingSingleSectionController</a>
</li>
<li class="nav-group-task">
<a href="Classes/IGListCollectionView.html">IGListCollectionView</a>
</li>
<li class="nav-group-task">
<a href="Classes/IGListCollectionViewLayout.html">IGListCollectionViewLayout</a>
</li>
<li class="nav-group-task">
<a href="Classes/IGListGenericSectionController.html">IGListGenericSectionController</a>
</li>
<li class="nav-group-task">
<a href="Classes/IGListIndexPathResult.html">IGListIndexPathResult</a>
</li>
<li class="nav-group-task">
<a href="Classes/IGListIndexSetResult.html">IGListIndexSetResult</a>
</li>
<li class="nav-group-task">
<a href="Classes/IGListMoveIndex.html">IGListMoveIndex</a>
</li>
<li class="nav-group-task">
<a href="Classes/IGListMoveIndexPath.html">IGListMoveIndexPath</a>
</li>
<li class="nav-group-task">
<a href="Classes.html#/c:objc(cs)IGListReloadDataUpdater">IGListReloadDataUpdater</a>
</li>
<li class="nav-group-task">
<a href="Classes/IGListSectionController.html">IGListSectionController</a>
</li>
<li class="nav-group-task">
<a href="Classes/IGListSingleSectionController.html">IGListSingleSectionController</a>
</li>
<li class="nav-group-task">
<a href="Classes/IGListTransitionData.html">IGListTransitionData</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="Constants.html">Constants</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="Constants.html#/c:@IGListKitVersionNumber">IGListKitVersionNumber</a>
</li>
<li class="nav-group-task">
<a href="Constants.html#/c:@IGListKitVersionString">IGListKitVersionString</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="Enums.html">Enumerations</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="Enums/IGListAdapterUpdateType.html">IGListAdapterUpdateType</a>
</li>
<li class="nav-group-task">
<a href="Enums/IGListDiffOption.html">IGListDiffOption</a>
</li>
<li class="nav-group-task">
<a href="Enums/IGListExperiment.html">IGListExperiment</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="Protocols.html">Protocols</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="Protocols/IGListAdapterDataSource.html">IGListAdapterDataSource</a>
</li>
<li class="nav-group-task">
<a href="Protocols/IGListAdapterDelegate.html">IGListAdapterDelegate</a>
</li>
<li class="nav-group-task">
<a href="Protocols/IGListAdapterMoveDelegate.html">IGListAdapterMoveDelegate</a>
</li>
<li class="nav-group-task">
<a href="Protocols/IGListAdapterPerformanceDelegate.html">IGListAdapterPerformanceDelegate</a>
</li>
<li class="nav-group-task">
<a href="Protocols/IGListAdapterUpdateListener.html">IGListAdapterUpdateListener</a>
</li>
<li class="nav-group-task">
<a href="Protocols/IGListAdapterUpdaterDelegate.html">IGListAdapterUpdaterDelegate</a>
</li>
<li class="nav-group-task">
<a href="Protocols/IGListBatchContext.html">IGListBatchContext</a>
</li>
<li class="nav-group-task">
<a href="Protocols/IGListBindable.html">IGListBindable</a>
</li>
<li class="nav-group-task">
<a href="Protocols/IGListBindingSectionControllerDataSource.html">IGListBindingSectionControllerDataSource</a>
</li>
<li class="nav-group-task">
<a href="Protocols/IGListBindingSectionControllerSelectionDelegate.html">IGListBindingSectionControllerSelectionDelegate</a>
</li>
<li class="nav-group-task">
<a href="Protocols/IGListCollectionContext.html">IGListCollectionContext</a>
</li>
<li class="nav-group-task">
<a href="Protocols/IGListCollectionViewDelegateLayout.html">IGListCollectionViewDelegateLayout</a>
</li>
<li class="nav-group-task">
<a href="Protocols/IGListCollectionViewLayoutCompatible.html">IGListCollectionViewLayoutCompatible</a>
</li>
<li class="nav-group-task">
<a href="Protocols/IGListDiffable.html">IGListDiffable</a>
</li>
<li class="nav-group-task">
<a href="Protocols/IGListDisplayDelegate.html">IGListDisplayDelegate</a>
</li>
<li class="nav-group-task">
<a href="Protocols/IGListScrollDelegate.html">IGListScrollDelegate</a>
</li>
<li class="nav-group-task">
<a href="Protocols/IGListSingleSectionControllerDelegate.html">IGListSingleSectionControllerDelegate</a>
</li>
<li class="nav-group-task">
<a href="Protocols/IGListSupplementaryViewSource.html">IGListSupplementaryViewSource</a>
</li>
<li class="nav-group-task">
<a href="Protocols/IGListTransitionDelegate.html">IGListTransitionDelegate</a>
</li>
<li class="nav-group-task">
<a href="Protocols/IGListUpdatingDelegate.html">IGListUpdatingDelegate</a>
</li>
<li class="nav-group-task">
<a href="Protocols/IGListWorkingRangeDelegate.html">IGListWorkingRangeDelegate</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="Type%20Definitions.html">Type Definitions</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="Type%20Definitions/IGListCollectionScrollingTraits.html">IGListCollectionScrollingTraits</a>
</li>
<li class="nav-group-task">
<a href="Type%20Definitions.html#/c:IGListUpdatingDelegate.h@T@IGListCollectionViewBlock">IGListCollectionViewBlock</a>
</li>
<li class="nav-group-task">
<a href="Type%20Definitions.html#/c:IGListUpdatingDelegate.h@T@IGListDataSourceChangeBlock">IGListDataSourceChangeBlock</a>
</li>
<li class="nav-group-task">
<a href="Type%20Definitions.html#/c:IGListUpdatingDelegate.h@T@IGListItemUpdateBlock">IGListItemUpdateBlock</a>
</li>
<li class="nav-group-task">
<a href="Type%20Definitions.html#/c:IGListUpdatingDelegate.h@T@IGListObjectTransitionBlock">IGListObjectTransitionBlock</a>
</li>
<li class="nav-group-task">
<a href="Type%20Definitions.html#/c:IGListUpdatingDelegate.h@T@IGListReloadUpdateBlock">IGListReloadUpdateBlock</a>
</li>
<li class="nav-group-task">
<a href="Type%20Definitions.html#/c:IGListSingleSectionController.h@T@IGListSingleSectionCellConfigureBlock">IGListSingleSectionCellConfigureBlock</a>
</li>
<li class="nav-group-task">
<a href="Type%20Definitions.html#/c:IGListSingleSectionController.h@T@IGListSingleSectionCellSizeBlock">IGListSingleSectionCellSizeBlock</a>
</li>
<li class="nav-group-task">
<a href="Type%20Definitions.html#/c:IGListUpdatingDelegate.h@T@IGListToObjectBlock">IGListToObjectBlock</a>
</li>
<li class="nav-group-task">
<a href="Type%20Definitions.html#/c:IGListUpdatingDelegate.h@T@IGListTransitionDataApplyBlock">IGListTransitionDataApplyBlock</a>
</li>
<li class="nav-group-task">
<a href="Type%20Definitions.html#/c:IGListUpdatingDelegate.h@T@IGListTransitionDataBlock">IGListTransitionDataBlock</a>
</li>
<li class="nav-group-task">
<a href="Type%20Definitions.html#/c:IGListAdapter.h@T@IGListUpdaterCompletion">IGListUpdaterCompletion</a>
</li>
<li class="nav-group-task">
<a href="Type%20Definitions.html#/c:IGListUpdatingDelegate.h@T@IGListUpdatingCompletion">IGListUpdatingCompletion</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="Functions.html">Functions</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="Functions.html#/c:@F@IGListDiff">IGListDiff</a>
</li>
<li class="nav-group-task">
<a href="Functions.html#/c:@F@IGListDiffPaths">IGListDiffPaths</a>
</li>
<li class="nav-group-task">
<a href="Functions.html#/c:IGListExperiments.h@F@IGListExperimentEnabled">IGListExperimentEnabled</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a href="Structs.html">Structures</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a href="Structs/IGListCollectionScrollingTraits.html">IGListCollectionScrollingTraits</a>
</li>
</ul>
</li>
</ul>
</nav>
<article class="main-content">
<section>
<section class="section">
<h1 id='generating-your-iglistdiffable-models-using-remodel' class='heading'>Generating your IGListDiffable models using remodel</h1>
<p>With the <code><a href="Protocols/IGListDiffable.html">IGListDiffable</a></code> plugin for <a href="https://github.com/facebook/remodel">remodel by facebook</a>, you can automatically generate models conforming to the <code><a href="Protocols/IGListDiffable.html">IGListDiffable</a></code>.</p>
<p>This will automatically implement <code>hash</code>, <code>isEqual:</code> and <code>description</code>, as well as <code>diffIdentifier</code> and <code>isEqualToDiffableObject:</code> for you. Remodel is also capable to generate additional code, like conforming to <code>NSCoding</code> or additional Builder classes for your model object. It will make creating and updating models much easier, faster and safer.</p>
<p>In <code>/remodel-plugin</code>, you can find the source files to build the <code><a href="Protocols/IGListDiffable.html">IGListDiffable</a></code> plugin locally.</p>
<h2 id='installation' class='heading'>Installation</h2>
<h3 id='1-remodel-installation' class='heading'>1. Remodel installation</h3>
<p>Please follow the <a href="https://github.com/facebook/remodel">installation instructions</a> in the main remodel repository.</p>
<p>tl;dr: Either clone the original repository, or use an npm installation. In the latter case you can run <code>which remodel-gen</code> to find out the path of your installation.</p>
<h3 id='2-plugin-installation' class='heading'>2. Plugin installation</h3>
<p>Copy the following files &amp; folders within <code>/remodel-plugin</code> into your local remodel checkout:</p>
<ul>
<li><code>/src/plugins/iglistdiffable.ts</code> - the actual plugin</li>
<li><code>/src/__tests__/plugins/iglistdiffable-test.ts</code> - unit tests</li>
<li><code>/features/iglistdiffable.feature</code> - integration tests</li>
</ul>
<p>And then register the new plugin with the system:</p>
<ul>
<li>Edit <code>/remodel/src/value-object-default-config.ts</code> and add <code>iglistdiffable</code> to the list of basePlugins:</li>
</ul>
<pre class="highlight plaintext"><code>// value-object-default-config.ts
basePlugins: List.of(
'assert-nullability',
'assume-nonnull',
'builder',
'coding',
'copying',
'description',
'equality',
'fetch-status',
'immutable-properties',
'init-new-unavailable',
'use-cpp',
'iglistdiffable'
)
</code></pre>
<h3 id='3-build-plugin' class='heading'>3. Build plugin:</h3>
<p>Once you copied them over and registered the plugin, you have to compile the typescript files into javascript. Do do so run this command from the remodel directory:</p>
<ul>
<li><code>./bin/build</code></li>
</ul>
<h3 id='4-run-tests-optional' class='heading'>4. Run tests (optional)</h3>
<p>To run the unit/integration tests, you can run the following commands:</p>
<ul>
<li><code>./bin/runUnitTests</code></li>
<li><code>./bin/runAcceptanceTests</code></li>
</ul>
<p>This is especially useful if you plan to change/extend the plugin in any way.</p>
<h3 id='5-use-the-plugin' class='heading'>5. Use the plugin</h3>
<p>Now you are ready to generate your <code><a href="Protocols/IGListDiffable.html">IGListDiffable</a></code> conforming models! To generate a model, create a new <code>.value</code> file. Here&rsquo;s an example:</p>
<pre class="highlight plaintext"><code># PersonModel.value
PersonModel includes(IGListDiffable) {
NSString *firstName
NSString *lastName
%diffIdentifier
NSString *uniqueId
}
</code></pre>
<p>To generate your Objective-C models, run the generation tool like this:</p>
<p><code>./bin/generate path/to/your/PersonModel.value</code></p>
<p>This will generate the following Objective-C files in the same directory:</p>
<pre class="highlight plaintext"><code>// PersonModel.h
@interface PersonModel : NSObject &lt;IGListDiffable, NSCopying&gt;
@property (nonatomic, readonly, copy) NSString *firstName;
@property (nonatomic, readonly, copy) NSString *lastName;
@property (nonatomic, readonly, copy) NSString *uniqueId;
- (instancetype)initWithFirstName:(NSString *)firstName lastName:(NSString *)lastName uniqueId:(NSString *)uniqueId;
@end
</code></pre>
<p>and</p>
<pre class="highlight plaintext"><code>// PersonModel.m
@implementation PersonModel
- (instancetype)initWithFirstName:(NSString *)firstName lastName:(NSString *)lastName uniqueId:(NSString *)uniqueId
{
if ((self = [super init])) {
_firstName = [firstName copy];
_lastName = [lastName copy];
_uniqueId = [uniqueId copy];
}
return self;
}
- (id&lt;NSObject&gt;)diffIdentifier
{
return _uniqueId;
}
- (BOOL)isEqualToDiffableObject:(nullable id&lt;IGListDiffable&gt;)object
{
return [self isEqual:object];
}
- (BOOL)isEqual:(PersonModel *)object
{
if (self == object) {
return YES;
} else if (self == nil || object == nil || ![object isKindOfClass:[self class]]) {
return NO;
}
return
(_firstName == object-&gt;_firstName ? YES : [_firstName isEqual:object-&gt;_firstName]) &amp;&amp;
(_lastName == object-&gt;_lastName ? YES : [_lastName isEqual:object-&gt;_lastName]) &amp;&amp;
(_uniqueId == object-&gt;_uniqueId ? YES : [_uniqueId isEqual:object-&gt;_uniqueId]);
}
- (id)copyWithZone:(nullable NSZone *)zone
{
return self;
}
- (NSString *)description
{
return [NSString stringWithFormat:@"%@ - \n\t firstName: %@; \n\t lastName: %@; \n\t uniqueId: %@; \n", [super description], _firstName, _lastName, _uniqueId];
}
- (NSUInteger)hash
{
NSUInteger subhashes[] = {[_firstName hash], [_lastName hash], [_uniqueId hash]};
NSUInteger result = subhashes[0];
for (int ii = 1; ii &lt; 3; ++ii) {
unsigned long long base = (((unsigned long long)result) &lt;&lt; 32 | subhashes[ii]);
base = (~base) + (base &lt;&lt; 18);
base ^= (base &gt;&gt; 31);
base *= 21;
base ^= (base &gt;&gt; 11);
base += (base &lt;&lt; 6);
base ^= (base &gt;&gt; 22);
result = base;
}
return result;
}
@end
</code></pre>
<h2 id='documentation' class='heading'>Documentation</h2>
<p>Please see the main remodel repository for <a href="https://github.com/facebook/remodel">additional documentation</a></p>
</section>
</section>
<section id="footer">
<p>&copy; 2024 <a class="link" href="https://twitter.com/MetaOpenSource" target="_blank" rel="external noopener">Instagram</a>. All rights reserved. (Last updated: 2024-05-13)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external noopener">jazzy ♪♫ v0.15.0</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external noopener">Realm</a> project.</p>
</section>
</article>
</div>
</body>
</html>