···11111212[CRC Cards](https://en.wikipedia.org/wiki/Class-responsibility-collaboration_card) are a teaching tool on how to design software. They were proposed by Kent Beck and Ward Cunningham, and, hell yeah it's useful.
13131414+<CrcCard name="Component name" responsabilities={["First responsability", "second responsability"]} collaborators={["First collaborator", "second collaborator"]} />
1515+1416When I'm talking with tech leaders, my goal is to sharpen our vision about the software we are working on. When developers implemente features, I often see responsability leaks: the feature works, but the component are hard to read, hard to reuse and we pile up technical debt too quickly.
15171618CRC cards are a great tool to focus the discussion and to aknowledge the fact that the developer shared her global vision to each individual local component who must rely only on its local scope. Let's take an example of one discussion.
···19212022Disclaimer: we're about to look at a very ugly code that is definetely doing too many things. The purpose of the discussion I have is to show to the tech lead that we really want to prevent this to happen and it is her mission to standardize it with her team.
21232222-Let's say we have a `UserBookmarks` component. Its role is to display a list of bookmarks the user saved.
2424+Let's say we have a `UserBookmarks` component.
23252426```tsx
2527interface Props {
···6062 setIsLoading(false)
6163 }
6264 }
6565+6666+ const tilesAnimation = gsap.to({
6767+ duration: 0.8,
6868+ opacity: 0.35,
6969+ yoyo: true,
7070+ repeat: -1,
7171+ stagger: 0.025,
7272+ })
63736474 return <div className="user-bookmarks">
6575 <Title title={strings['frontoffice.bookmark.user_bookmarks']} />
6666- {toolList}
7676+ {isLoading
7777+ ? <TilesSkeleton animation={tilesAnimation} numberOfTiles={16} />
7878+ : <BookmarkItem
7979+ key={bookmark.id}
8080+ data={bookmark}
8181+ />}
67826883 <PrimaryButton
6984 text={strings['frontoffice.bookmark.all_bookmarks']}
···7590 <AddBookmarkModal
7691 visible={showAddBookmarkModal}
7792 onClose={() => setShowAddBookmarkModal(false)}
7878- tools={availableCustomTools}
9393+ bookmarks={bookmarks}
7994 onBookmarkAdd={addBookmarkToUser}
8095 />
8196 </div>
8297}
8383-8498```
85998686-```tsx
8787-import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
8888-import { gsap } from 'gsap';
8989-import differenceBy from 'lodash/differenceBy';
9090-import React, { useCallback, useEffect, useState } from 'react';
9191-9292-import { PrimaryButton } from 'components/CustomButton/CustomButton';
9393-import strings from 'components/Localization/Localisation';
9494-import { Title } from 'components/Title/Title';
9595-import { useLanguageContext } from 'context/LanguageContext';
9696-import {
9797- addToolToUser,
9898- fetchToolsForUser,
9999- removeToolFromUser,
100100-} from 'data/actions/ToolActions';
101101-import { CodeIso } from 'types/Language';
102102-import { Tool } from 'types/Tool';
103103-import { Tools } from 'types/Tools';
104104-import { Ui } from 'types/Ui';
105105-import { User } from 'types/User';
106106-107107-import AddToolModal from './AddToolModal/AddToolModal';
108108-import { TilesSkeleton } from './TilesSkeleton';
109109-import { ToolItem } from './Tool/ToolItem';
110110-111111-export const Toolbox: React.FC = ({
112112- user,
113113- ui,
114114- customTools,
115115- userTools,
116116- indispensableTools,
117117- userIsUpdating,
118118- getToolData,
119119- addToolToUser,
120120- removeToolFromUser,
121121-}) => {
122122- const { language } = useLanguageContext();
123123-124124- const [showAddToolModal, setShowAddToolModal] = useState(false);
125125- const [showDeleteTool, setShowDeleteTool] = useState(false);
126126-127127- const [tileAnimation, setTileAnimation] = useState<GSAPTween>();
128128- const [fakeTiles, setFakeTiles] = useState<unknown[]>([]);
129129-130130- const [toolList, setToolList] = useState<JSX.Element>();
131131-132132- const userId = user['@id'];
133133- const uiLoading = ui.loading;
134134-135135- const availableCustomTools = differenceBy(customTools, userTools, '@id');
136136-137137- const startLoadAnimation = (): void => {
138138- setTileAnimation(
139139- gsap.to(fakeTiles, {
140140- duration: 0.8,
141141- opacity: 0.35,
142142- yoyo: true,
143143- repeat: -1,
144144- stagger: 0.025,
145145- }),
146146- );
147147- };
148148-149149- const stopLoadingAnimation = useCallback((): void => {
150150- tileAnimation?.kill();
151151- }, [tileAnimation]);
152152-153153- const addBookmark = (): void => {
154154- setShowAddToolModal(true);
155155- setShowDeleteTool(false);
156156- };
157157-158158- useEffect(() => {
159159- startLoadAnimation();
160160- if (userId) {
161161- getToolData(user, language);
162162- }
163163- }, [userId, language]);
164164-165165- useEffect(() => {
166166- if (!uiLoading) {
167167- stopLoadingAnimation();
168168- setToolList(
169169- <div className="tool-list">
170170- {indispensableTools.map(tool => (
171171- <ToolItem key={tool['@id']} data={tool} showDeleteButton={false} />
172172- ))}
173173-174174- {userTools.map(tool => (
175175- <ToolItem
176176- key={tool['@id']}
177177- data={tool}
178178- showDeleteButton={showDeleteTool}
179179- onDelete={() => removeToolFromUser(tool)}
180180- />
181181- ))}
100100+It's a reeeeeeally long component that does many things, (FYI it is a simplified version of a component in one of my project). Most of the time, the tech lead freezes seeing how many things we need to talk to. Let's break it down piece by piece.
182101183183- </div>,
184184- );
185185- } else {
186186- setToolList(<TilesSkeleton setFakeTiles={setFakeTiles} numberOfTiles={16} />);
187187- }
188188- }, [uiLoading]);
102102+## Inputs and output
189103190190- return (
191191- <div className="Toolbox">
192192- <Title title={strings['frontoffice.toolbox.my_tools']} />
193193- {toolList}
104104+The `UserBookmarks` component takes a `user` prop and return a list of styled bookmarks with the possibility to add bookmark via a modal.
194105195195- <PrimaryButton
196196- text={strings['frontoffice.toolbox.all_apps']}
197197- onClick={addBookmark}
198198- alt={'see all apps button'}
199199- image={<FontAwesomeIcon icon={['fas', 'arrow-right']} color="white" />}
200200- positionOfImage="right"
201201- disabled={true}
202202- />
106106+Cool! That's the first thing we can note on our CRC card.
203107204204- <AddToolModal
205205- visible={showAddToolModal}
206206- onClose={() => setShowAddToolModal(false)}
207207- tools={availableCustomTools}
208208- onToolAdd={addToolToUser}
209209- userIsUpdating={userIsUpdating}
210210- />
211211- </div>
212212- );
213213-};
214214-```
108108+<CrcCard name="UserBookmarks" responsabilities={["Display user bookmarks"]} collaborators={["Home.tsx"]} />