Skip to content

Commit

Permalink
Updated CONTRIBUTING.md (#1066)
Browse files Browse the repository at this point in the history
  • Loading branch information
EricBAndrews authored May 16, 2024
1 parent 114a9d9 commit 38b7476
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
35 changes: 23 additions & 12 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,24 @@ To avoid having multiple in-flight tasks working on the same part of the codebas

When your code is approved, it can be merged into the `dev` branch by a member of the development team. If you need to tinker with your changes post-approval, please make a comment that you are doing so. PRs that sit approved for more than 12 hours with no input from the dev may be merged if they are blocking other work.

## Conventions
## Testing

We operate a Lemmy Instance at https://test-mlem.jo.wtf/ which you may use for testing purposes. Please note that, as of 2024-05-10, it is running Lemmy v17, which is no longer used by any major Lemmy instance and thus we do not bother maintaining compatibility for. You may wish to use a local Lemmy instance instead.

## Coding Conventions

Please develop according to the following principles:
### General Principles

- Files should be named according to the following patterns:
- All files: `TitleCase`. If the file contains extensions, it should be named `BaseEntity+Extensions`.
- `View` files: file name must end in `View` (e.g., `FeedsView`)
- One View per file.
- Within reason, any complex of views that renders a single component of a larger view should be placed in a descriptively named function, computed property or `@ViewBuilder` variable beneath the body of the View. This keeps pyramids from piling up and makes our accessibility experts' work easier.
- If you can reuse code, do. Prefer abstracting common components to a generic struct and common logic to a generic function.

## View Structure
### Views

All `View` structs should be organized according to the following template:
- Only one `View` struct should be defined per file
- Within reason, any complex of views that renders a single component of a larger view should be placed in a descriptively named function, computed property or `@ViewBuilder` variable beneath the body of the View. This keeps pyramids from piling up and makes our accessibility experts' work easier.
- All `View` structs should be organized according to the following template:

```
struct SomeView: View {
Expand All @@ -73,25 +77,32 @@ struct SomeView: View {
}
```

Further notes:

- If the view has modifiers that are attached to the entire body, place the view definition in `content` and attach these modifiers to it in `body` (see `ContentView.swift` for an example).
- Prefer `var helper: some View` to `func helper() -> some View` unless the helper view takes in parameters.
- Helper views should always appear lower in the file than the view they help.

## Global Objects
### Global Objects

There are several objects (e.g., `AppState`) that need to be available anywhere in the app. Normally this is handled with `@Environment`, but this is not available outside of the context of a `View`. To address this, globals that need to be available outside of a `View` define a `static var main: GlobalObject = .init()`, allowing them to be referenced as `GlobalObject.main`. This definition should be placed immediately above the initializer.

This pattern should be used only where necessary, and should not be blindly applied to any global object. Likewise, if possible, these objects should be referenced via `@Environment(GlobalObject.self) var globalObject`; the static singleton should be considered a last resort.

## Colors
### Colors

Colors are managed using the globally available `Palette` object, which enables color themes. The following conventions apply:

- Avoid referencing `Color` directly; always use a `Palette` color.
- Prefer semantic over literal colors (e.g., `.upvote` over `.blue`).

## Testing
### Main Actor

We operate a Lemmy Instance at https://test-mlem.jo.wtf/ which you may use for testing purposes. Please note that, as of 2024-05-10, it is running Lemmy v17, which is no longer used by any major Lemmy instance and thus we do not bother maintaining compatibility for. You may wish to use a local Lemmy instance instead.
To run code on the main actor, use either:

- `@MainActor` annotated method
- `Task { @MainActor in ... }`

If you need to execute code after a delay, use `DispatchQueue.main.asyncAfter`.

### Hashable

Explicit `hash` functions for `enum`s should, in the absence of associated values, use a descriptive string to identify each case rather than an integer.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/mlemgroup/MlemMiddleware.git",
"state" : {
"revision" : "3fc9bdebc74909dfdea2fcd51afb645d5d1ed2b6",
"version" : "0.1.0"
"revision" : "8a8784c789683df9248662108721a573e41ba6b8",
"version" : "0.1.2"
}
},
{
Expand Down

0 comments on commit 38b7476

Please sign in to comment.