Skip to content

Commit

Permalink
Transform to monorepo (#2589)
Browse files Browse the repository at this point in the history
* Moved mobx as package

Build & tests are working

* Fix tests for mobx-undecorate

* Maybe fixed circle CI

* Run prettier on some docs

* Finish up CI build

* Use changesets for mobx-undecorate

* Remove mention of gitpod from docs

* Fix CI again :)

* Persist some artifacts

* Remove coveralls upload

Will be handled with GH action

* Run tests in band

* Add coveralls action

* Faster coveralls?

Co-authored-by: Daniel K <[email protected]>
Co-authored-by: urugator <[email protected]>
  • Loading branch information
3 people authored Nov 3, 2020
1 parent 81b0b46 commit 6f99e30
Show file tree
Hide file tree
Showing 161 changed files with 11,298 additions and 13,642 deletions.
5 changes: 5 additions & 0 deletions .changeset/fast-seahorses-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"mobx-undecorate": patch
---

Fix [#2540](https://github.com/mobxjs/mobx/issues/2540) makeObservable not added to imports
5 changes: 5 additions & 0 deletions .changeset/quick-cars-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"mobx-undecorate": patch
---

Fix [#2558](https://github.com/mobxjs/mobx/issues/2558) Undecorate removes non-mobx decorator
120 changes: 40 additions & 80 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,130 +1,90 @@
version: 2.1

executors:
my-executor:
node-executor:
docker:
- image: circleci/node:14
- image: circleci/node:12
environment:
CI: true

orbs:
node: circleci/[email protected]

jobs:
build:
executor: my-executor
mobx-build:
executor: node-executor
steps:
- checkout

- node/install-packages:
pkg-manager: yarn

- run: yarn build

- run: yarn mobx build
- persist_to_workspace:
root: .
paths:
- ./*

test-check:
executor: my-executor
mobx-check:
executor: node-executor
steps:
- attach_workspace:
at: .
- run: yarn mobx test:check

- run: yarn test:check

test-performance:
executor: my-executor
mobx-performance:
executor: node-executor
steps:
- attach_workspace:
at: .

- run:
command: time node --expose-gc test/perf/index.js legacy
environment:
PERSIST: true

- run:
command: time node --expose-gc test/perf/index.js proxy
command: yarn mobx test:performance
environment:
PERSIST: true
- store_artifacts:
path: packages/mobx/perf_report
destination: mobx-perf

test-coverage:
executor: my-executor
steps:
- attach_workspace:
at: .

- run: yarn test:coverage
- persist_to_workspace:
root: .
paths:
- ./coverage

test-codemod:
executor: my-executor
mobx-test:
executor: node-executor
steps:
- attach_workspace:
at: .
- run:
name: run codemod
command: |
cd packages/mobx-undecorate
yarn
yarn test
- run: yarn mobx test -i

test-size:
executor: my-executor
mobx-size:
executor: node-executor
steps:
- attach_workspace:
at: .

- run: yarn test:size
- run: yarn mobx test:size

# upload coverage
upload-coveralls:
executor: my-executor
mobx-undecorate-test:
executor: node-executor
steps:
- attach_workspace:
at: .

# only run coveralls if the token is present (it is not present for fork PRs for security reasons)
- run:
name: upload coveralls
command: |
if [[ -v COVERALLS_REPO_TOKEN ]]
then
cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
echo "Coveralls info uploaded"
else
echo "Warning - Coveralls info could NOT be uploaded since the COVERALLS_REPO_TOKEN was not available"
fi
- checkout
- node/install-packages:
pkg-manager: yarn
- run: yarn mobx-undecorate test

workflows:
version: 2
build-and-test:
mobx:
jobs:
- build:
filters:
branches:
ignore:
- gh-pages
- test-check:
requires:
- build
- test-performance:
- mobx-build
- mobx-check:
requires:
- build
- test-coverage:
- mobx-build
- mobx-performance:
requires:
- build
- test-size:
- mobx-build
- mobx-test:
requires:
- build
- test-codemod:
- mobx-build
- mobx-size:
requires:
- build
- upload-coveralls:
requires:
- test-coverage
- mobx-build

mobx-undecorate:
jobs:
- mobx-undecorate-test
32 changes: 32 additions & 0 deletions .github/workflows/coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Coveralls

on: ["push", "pull_request"]

jobs:
mobx:
name: MobX Coverage
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@master
with:
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
fetch-depth: 0

- name: Setup Node.js 12.x
uses: actions/setup-node@master
with:
node-version: 12.x

- name: Install Dependencies
run: yarn --frozen-lockfile --ignore-scripts

- name: Run Coverage
run: yarn mobx test:coverage

- name: Upload to coveralls
uses: coverallsapp/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ./packages/mobx/coverage/lcov.info
base-path: packages/mobx
33 changes: 0 additions & 33 deletions .gitpod.yml

This file was deleted.

6 changes: 0 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ Here are some ways to contribute to the project, from easiest to most difficult:

## Issues

## Online one-click setup for contributing

You can use Gitpod (a free online VS Code-like IDE) for working on issues and making PRs. With a single click it will launch a ready to code workspace with everything setup so that you can start straight away.

[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/from-referrer/)

### Reporting bugs

If you encounter a bug, please file an issue on GitHub via the repository of the sub-project you think contains the bug. If an issue you have is already reported, please add additional information or add a 👍 reaction to indicate your agreement.
Expand Down
4 changes: 2 additions & 2 deletions docs/analyzing-reactivity.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ Spy listeners always receive one object, which usually has at least a `type` fie
| scheduled-reaction | | name | no |
| reaction | | name | yes |
| error | | name, message, error | no |
| add,update,remove,delete,splice | | Check out [Intercept & observe {🚀}](intercept-and-observe.md) | yes |
| add,update,remove,delete,splice | | Check out [Intercept & observe {🚀}](intercept-and-observe.md) | yes |
| report-end | | spyReportEnd=true, time? (total execution time in ms) | no |

The `report-end` events are part of an earlier fired event that had `spyReportStart: true`.
This event indicates the end of an event and this way groups of events with sub-events are created.
This event might report the total execution time as well.

The spy events for observable values are identical to the events passed to `observe`.
The spy events for observable values are identical to the events passed to `observe`.
In production builds, the `spy` API is a no-op as it will be minimized away.

Check out the [Intercept & observe {🚀}](intercept-and-observe.md#event-overview) section for an extensive overview.
3 changes: 1 addition & 2 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ _Computed values can be used to derive information from other observables._

### `computed`

[**Usage**](computeds.md): `computed(fn, options?)` or `computed(options?)` _(annotation)_
[**Usage**](computeds.md): `computed(fn, options?)` or `computed(options?)` _(annotation)_

Creates an observable value that is derived from other observables, but won't be recomputed unless one of the underlying observables changes.

Expand Down Expand Up @@ -395,7 +395,6 @@ Is the value an observable object?

Is the value an observable Set?


### `isObservableMap`

{🚀} Usage: `isObservableMap(map)`
Expand Down
2 changes: 1 addition & 1 deletion docs/computeds.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ This string is used as a debug name in the [Spy event listeners](analyzing-react

### `equals`

Set to `comparer.default` by default. It acts as a comparison function for comparing the previous value with the next value. If this function considers the values to be equal, then the observers will not be re-evaluated.
Set to `comparer.default` by default. It acts as a comparison function for comparing the previous value with the next value. If this function considers the values to be equal, then the observers will not be re-evaluated.

This is useful when working with structural data and types from other libraries. For example, a computed [moment](https://momentjs.com/) instance could use `(a, b) => a.isSame(b)`. `comparer.structural` and `comparer.shallow` come in handy if you want to use structural / shallow comparison to determine whether the new value is different from the previous value, and as a result notify its observers.

Expand Down
4 changes: 2 additions & 2 deletions docs/intercept-and-observe.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ _⚠️ **Warning**: intercept and observe are low level utilities, and should n

`observe` and `intercept` can be used to monitor the changes of a single observable, but they **_don't_** track nested observables.

- `intercept` can be used to detect and modify mutations before they are applied to the observable (validating, normalizing or cancelling).
- `observe` allows you to intercept changes after they have been made.
- `intercept` can be used to detect and modify mutations before they are applied to the observable (validating, normalizing or cancelling).
- `observe` allows you to intercept changes after they have been made.

## Intercept

Expand Down
12 changes: 5 additions & 7 deletions docs/react-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,14 +296,12 @@ Or, we can create an in-line anonymous observer using [`<Observer />`](https://g

```javascript
const TodoView = observer(({ todo }: { todo: Todo }) => {
// WRONG: GridRow.onRender won't pick up changes in todo.title / todo.done
// since it isn't an observer.
return <GridRow onRender={() => <td>{todo.title}</td>} />
// WRONG: GridRow.onRender won't pick up changes in todo.title / todo.done
// since it isn't an observer.
return <GridRow onRender={() => <td>{todo.title}</td>} />

// CORRECT: wrap the callback rendering in Observer to be able to detect changes.
return <GridRow onRender={() => <Observer>{() =>
<td>{todo.title}</td>
}</Observer>} />
// CORRECT: wrap the callback rendering in Observer to be able to detect changes.
return <GridRow onRender={() => <Observer>{() => <td>{todo.title}</td>}</Observer>} />
})
```

Expand Down
6 changes: 3 additions & 3 deletions docs/reactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ Once we run the `for` loop to change the `energyLevel` with the `reduceEnergy`
action, we see a new log entry every time an `autorun` function observes a
change in its observable state:

1. For the _"Energy level"_ function, this is every time the `energyLevel` observable changes, 10 times in total.
1. For the _"Energy level"_ function, this is every time the `energyLevel` observable changes, 10 times in total.

2. For the _"Now I'm hungry"_ function, this is every time the `isHungry` computed
2. For the _"Now I'm hungry"_ function, this is every time the `isHungry` computed
changes, only one time.

## Reaction
Expand Down Expand Up @@ -338,7 +338,7 @@ Before you set up a reaction, it is good to first check if it conforms to the fo
1. **Only use Reactions if there is no direct relation between cause and effect**: If a side effect should happen in response to a very limited set of events / actions, it will often be clearer to directly trigger the effect from those specific actions. For example, if pressing a form submit button should lead to a network request to be posted, it is clearer to trigger this effect directly in response of the `onClick` event, rather than indirectly through a reaction. In contrast, if any change you make to the form state should automatically end up in local storage, then a reaction can be very useful, so that you don't have to trigger this effect from every individual `onChange` event.
1. **Reactions shouldn't update other observables**: Is the reaction going to modify other observables? If the answer is yes, typically the observable you want to update should be annotated as a [`computed`](computeds.md) value instead. For example, if a collection of todos is altered, don't use a reaction to compute the amount of `remainingTodos`, but annotate `remainingTodos` as a computed value. That will lead to much clearer and easier to debug code. Reactions should not compute new data, but only cause effects.
1. **Reactions should be independent**: Does your code rely on some other reaction having to run first? If that is the case, you probably
either violated the first rule, or the new reaction you are about to create should be merged into the one it is depending upon. MobX does not guarantee the order in which reactions will be run.
either violated the first rule, or the new reaction you are about to create should be merged into the one it is depending upon. MobX does not guarantee the order in which reactions will be run.

There are real-life scenarios that do not fit in the above principles. That is why they are _principles_, not _laws_.
But, the exceptions are rare so only violate them as a last resort.
Expand Down
6 changes: 3 additions & 3 deletions docs/the-gist-of-mobx.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ The golden rule is, always use `computed` if you want to create a value based on

#### 3.1. Model derived values using computed

To create a *computed* value, define a property using a JS getter function `get` and mark it as `computed` with `makeObservable`.
To create a _computed_ value, define a property using a JS getter function `get` and mark it as `computed` with `makeObservable`.

```javascript
import { makeObservable, observable, computed } from "mobx"
Expand All @@ -104,7 +104,7 @@ class TodoList {
todos: observable,
unfinishedTodoCount: computed
})
this.todos = todos;
this.todos = todos
}
}
```
Expand Down Expand Up @@ -196,7 +196,7 @@ MobX uses a uni-directional data flow where _actions_ change the _state_, which
2. All _derivations_ are updated **synchronously** by default. This means that, for example, _actions_ can safely inspect a computed value directly after altering the _state_.

3. _Computed values_ are updated **lazily**. Any computed value that is not actively in use will not be updated until it is needed for a side effect (I/O).
If a view is no longer in use it will be garbage collected automatically.
If a view is no longer in use it will be garbage collected automatically.

4. All _computed values_ should be **pure**. They are not supposed to change _state_.

Expand Down
Loading

0 comments on commit 6f99e30

Please sign in to comment.