You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CSS/style_guide.md
+14Lines changed: 14 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -171,6 +171,16 @@ grep "info" * -R
171
171
172
172
## Naming Convention
173
173
174
+
Component vs Page-level naming. We should not use Page-level if possible. Prefer Component-level names. However, Page-level can be used to override generic components in very specific contexts:
175
+
176
+
```css
177
+
.home-page { /* Page-level */
178
+
.nav { /* Component-level */
179
+
margin-top: 10px; /* Override */
180
+
}
181
+
}
182
+
```
183
+
174
184
*[Naming CSS stuff is really hard](http://seesparkbox.com/foundry/naming_css_stuff_is_really_hard)
175
185
176
186
We can fit a given class name into these 3 categories:
@@ -244,6 +254,10 @@ The aim of a component/template/object-oriented architecture is to be able to de
244
254
}
245
255
```
246
256
257
+
### Avoid run-on classnames
258
+
259
+
The evolution being: `.button` → `.button-primary` → `.button-primary-dark` → `.button-primary-dark-container` → `.button-primary-dark-container-label`, ad nauseam.
260
+
247
261
# My Style Guide
248
262
249
263
* Base - normalize and element selector. Base are not for button, table, input, those are modules.
`connect()` does a ton of trickery to be very optimized. Always re-rendering from the top means you're doing a bunch of unnecessary reconciliation.
102
+
103
+
> A widget is an autonomous component that has its own reducer, use something like "connect" to get the state of that reducer. The widget only re-renders when its state changes. I try to make the widget only receive its own state, to make it really independent but it is really a mater of taste and many don't adopt a similar approach and assume the widget should have a global knowledge of the global appstate to select the state it needs to use.
> You can use HOC in various situations like authentication: `requireAuth({ role: 'admin' })(MyComponent)` (check for a user in higher component and redirect if the user is not logged in) or connecting your component with Flux/Redux store.
4
+
>
5
+
> You can also separate data fetching and controller-like logic to higher order components and keep our views as simple as possible.
6
+
7
+
How do you wrap your components? What does wrapping even mean?
8
+
9
+
A higher-order component is a function that takes an existing component and returns another component that wraps it. The wrapping component will take care to render the wrapped component and also forwards the props to it, but also adds some useful behavior.
React 0.14 switches to [parent-based context](https://github.com/facebook/react/pull/3615).
19
+
20
+
**Note**: Lambdas are frequently confused with anonymous functions, closures, first-class functions, and higher-order functions. The concepts are all similar, but they mean different things.
21
+
22
+
Not all lambdas are closures, and not all closures are lambdas. A closure is created when a function references data that is contained outside the function scope. A lambda is a function that is used as a value.
23
+
24
+
> HoCs are very similar to higher-order functions. In higher-order functions you pass one function to another function which returns a function. How does that help us? Well, with higher-order components, you pass a component (which as we know is just a function) to another function, which returns a component (again, is just a function).
25
+
26
+
```js
27
+
// This is a higher-order container component accepting
28
+
// a presentation component which is a pure-function.
29
+
// The container component just handle all the states logic.
* [react-heatpack: Quick React development with webpack hot reloading](https://github.com/insin/react-heatpack)
189
189
190
-
## Higher-order Components
191
-
192
-
> You can use HOC in various situations like authentication: `requireAuth({ role:'admin' })(MyComponent)` (check for a user in higher component and redirect if the user is not logged in) or connecting your component with Flux/Redux store.
193
-
>
194
-
> You can also separate data fetching and controller-like logic to higher order components and keep our views as simple as possible.
195
-
196
-
How do you wrap your components? What does wrapping even mean?
197
-
198
-
A higher-order component is a function that takes an existing component and returns another component that wraps it. The wrapping component will take care to render the wrapped component and also forwards the props to it, but also adds some useful behavior.
React 0.14 switches to [parent-based context](https://github.com/facebook/react/pull/3615).
207
-
208
-
**Note**: Lambdas are frequently confused with anonymous functions, closures, first-class functions, and higher-order functions. The concepts are all similar, but they mean different things.
209
-
210
-
Not all lambdas are closures, and not all closures are lambdas. A closure is created when a function references data that is contained outside the function scope. A lambda is a function that is used as a value.
211
-
212
-
> HoCs are very similar to higher-order functions. In higher-order functions you pass one function to another function which returns a function. How does that help us? Well, with higher-order components, you pass a component (which as we know is just a function) to another function, which returns a component (again, is just a function).
213
-
214
-
```js
215
-
// This is a higher-order container component accepting
216
-
// a presentation component which is a pure-function.
217
-
// The container component just handle all the states logic.
0 commit comments