Skip to content

Commit 71e3179

Browse files
authored
Docs: Migration guide to v3 (#312)
* docs: guide for migrating to v3. * docs: migration guide toc. * docs: migration guide for imports. * README: group packages.
1 parent d229779 commit 71e3179

File tree

3 files changed

+246
-16
lines changed

3 files changed

+246
-16
lines changed

README.md

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,24 @@ Find more examples [here](https://github.com/Travix-International/frint/tree/mas
4242

4343
The framework is a collection of these packages, which can be composed together on demand:
4444

45-
| Package | Status | Description |
46-
|----------------------------|------------------------------------------------------------------------|-------------|
47-
| [frint] | [![frint-status]][frint-package] | Base for creating Apps |
48-
| [frint-store] | [![frint-store-status]][frint-store-package] | State management with reactive stores |
49-
| [frint-data] | [![frint-data-status]][frint-data-package] | Reactive data modelling |
50-
| [frint-react] | [![frint-react-status]][frint-react-package] | React.js integration |
51-
| [frint-react-server] | [![frint-react-server-status]][frint-react-server-package] | Server-side rendering of Apps |
52-
| [frint-router] | [![frint-router-status]][frint-router-package] | Router services for building Single Page Applications |
53-
| [frint-router-react] | [![frint-router-react-status]][frint-router-react-package] | React components for building SPAs |
54-
| [frint-cli] | [![frint-cli-status]][frint-cli-package] | CLI runner |
55-
| [frint-compat] | [![frint-compat-status]][frint-compat-package] | Backwards compatibility for older versions |
56-
| [frint-model] | [![frint-model-status]][frint-model-package] | Use `frint-data` instead |
57-
| [frint-component-utils] | [![frint-component-utils-status]][frint-component-utils-package] | Utils for reactive Components |
58-
| [frint-component-handlers] | [![frint-component-handlers-status]][frint-component-handlers-package] | Handlers for integrating with other rendering libraries |
59-
| [frint-test-utils] | [![frint-test-utils-status]][frint-test-utils-package] | Internally used test utilities |
60-
| [frint-config] | [![frint-config-status]][frint-config-package] | Common config for your Apps |
45+
| Package | Status | Description |
46+
|-----------------------------|------------------------------------------------------------------------|-------------|
47+
| [frint] | [![frint-status]][frint-package] | Base for creating Apps |
48+
| [frint-store] | [![frint-store-status]][frint-store-package] | State management with reactive stores |
49+
| [frint-data] | [![frint-data-status]][frint-data-package] | Reactive data modelling |
50+
| [frint-react] | [![frint-react-status]][frint-react-package] | React.js integration |
51+
| [frint-react-server] | [![frint-react-server-status]][frint-react-server-package] | Server-side rendering of Apps |
52+
| [frint-router] | [![frint-router-status]][frint-router-package] | Router services for building Single Page Applications |
53+
| [frint-router-react] | [![frint-router-react-status]][frint-router-react-package] | React components for building SPAs |
54+
| [frint-cli] | [![frint-cli-status]][frint-cli-package] | CLI runner |
55+
| [frint-compat] | [![frint-compat-status]][frint-compat-package] | Backwards compatibility for older versions |
56+
| [frint-model] | [![frint-model-status]][frint-model-package] | Use `frint-data` instead |
57+
| **For library developers:** | | |
58+
| [frint-component-utils] | [![frint-component-utils-status]][frint-component-utils-package] | Utils for reactive Components |
59+
| [frint-component-handlers] | [![frint-component-handlers-status]][frint-component-handlers-package] | Handlers for integrating with other rendering libraries |
60+
| **Internally used:** | | |
61+
| [frint-test-utils] | [![frint-test-utils-status]][frint-test-utils-package] | Internally used test utilities |
62+
| [frint-config] | [![frint-config-status]][frint-config-package] | Common config for your Apps |
6163

6264
[frint]: https://frint.js.org/docs/packages/frint
6365
[frint-store]: https://frint.js.org/docs/packages/frint-store

site/content/docs/migration/v3.md

Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
---
2+
title: Migrating from v2.x to v3.x
3+
sidebarPartial: docsSidebar
4+
---
5+
6+
# Migrating from v2.x to v3.x
7+
8+
<!-- MarkdownTOC depth=1 autolink=true bracket=round -->
9+
10+
- [RxJS imports](#rxjs-imports)
11+
- [Lodash imports](#lodash-imports)
12+
- [Webpack builds](#webpack-builds)
13+
- [`frint-store`](#frint-store)
14+
- [`frint-model`](#frint-model)
15+
- [`frint-compat`](#frint-compat)
16+
17+
<!-- /MarkdownTOC -->
18+
19+
## RxJS imports
20+
21+
All RxJS modules are now imported individually, resulting in smaller bundle sizes in your applications.
22+
23+
This also means, the observables returned by FrintJS packages will not have the operators (like `map`, `filter`, etc) built in any more, and they need to be imported manually too if you need them.
24+
25+
### Before
26+
27+
We can take an example from `frint-store`:
28+
29+
```js
30+
const todos$ = store.getState$()
31+
.filter(state => state.showTodos === true)
32+
.map(state => state.todos);
33+
34+
todos$.subscribe(todos => console.log(todos));
35+
```
36+
### After
37+
38+
```js
39+
import { filter } from 'rxjs/operator/filter';
40+
import { map } from 'rxjs/operator/map';
41+
42+
const todos$ = store.getState$()
43+
::filter(state => state.showTodos === true)
44+
::map(state => state.todos);
45+
46+
todos$.subscribe(todos => console.log(todos));
47+
```
48+
49+
The syntax above is written using the [bind-operator](https://github.com/tc39/proposal-bind-operator).
50+
51+
It could also have been written like this:
52+
53+
```js
54+
import { filter } from 'rxjs/operator/filter';
55+
import { map } from 'rxjs/operator/map';
56+
57+
const todos$ = map.call(
58+
filter.call(
59+
store.getState$(),
60+
state => state.showTodos === true
61+
),
62+
state => state.todos
63+
);
64+
65+
todos$.subscribe(todos => console.log(todos));
66+
```
67+
68+
## Lodash imports
69+
70+
All lodash imports have also been updated to import only the modules that are needed.
71+
72+
If you want to take benefit of reduced bundle size in your applications, then you can follow the same approach.
73+
74+
### Before
75+
76+
```js
77+
import _ from 'lodash';
78+
79+
_.isPlainObject({});
80+
```
81+
82+
## After
83+
84+
```js
85+
import isPlainObject from 'lodash/isPlainObject';
86+
87+
isPlainObject({});
88+
```
89+
90+
## Webpack builds
91+
92+
If your application is set up in a way like this:
93+
94+
* `vendors.js`: All third party libraries (RxJS, Lodash, Frint, etc)
95+
* `app.js`: Your custom code for Frint App(s)
96+
97+
Or you are loading the vendors directly from CDN via `<script>` tags, then you risk loading some RxJS and Lodash modules twice.
98+
99+
To help avoid that, we are shipping a new `frint-config` package that has information about the list of external dependencies, that you can map accordingly.
100+
101+
### Before
102+
103+
```js
104+
// webpack.config.js
105+
module.exports = {
106+
entry: __dirname + '/src/index.js',
107+
output: {
108+
path: __dirname + '/build'
109+
},
110+
externals: {
111+
'lodash': '_', // window._
112+
'rxjs': 'Rx', // window.Rx
113+
114+
// other libraries
115+
'react': 'React',
116+
'react-dom': 'ReactDOM',
117+
},
118+
}
119+
```
120+
121+
### After
122+
123+
```js
124+
// webpack.js
125+
126+
// all RxJS and Lodash imports
127+
// are mapped to global `window._` and `window.Rx`
128+
const externals = require('frint-config').externals;
129+
130+
module.exports = {
131+
entry: __dirname + '/src/index.js',
132+
output: {
133+
path: __dirname + '/build'
134+
},
135+
externals: Object.assign(
136+
{},
137+
138+
// RxJS and Lodash
139+
externals,
140+
141+
// other libraries
142+
{
143+
'react': 'React',
144+
'react-dom': 'ReactDOM',
145+
}
146+
),
147+
}
148+
```
149+
150+
## frint-store
151+
152+
`thunkArgument` option has been renamed to `deps`.
153+
154+
### Before
155+
156+
```js
157+
import { createStore } from 'frint-store';
158+
159+
const Store = createStore({
160+
thunkArgument: {},
161+
});
162+
```
163+
164+
### After
165+
166+
```js
167+
import { createStore } from 'frint-store';
168+
169+
const Store = createStore({
170+
deps: {},
171+
});
172+
```
173+
174+
## frint-model
175+
176+
Deprecated and will be completely removed when v4.0 gets released. Use `frint-data` instead.
177+
178+
### Before
179+
180+
```js
181+
import { createModel } from 'frint-model';
182+
183+
const Todo = createModel({
184+
getTitle() {
185+
return this.get('title');
186+
},
187+
setTitle(newTitle) {
188+
this.set('title', newTitle);
189+
},
190+
});
191+
192+
const todo = new Todo({
193+
title: 'Hello World',
194+
completed: false,
195+
});
196+
197+
const title = todo.getTitle();
198+
todo.setTitle('Updated title');
199+
```
200+
201+
### After
202+
203+
```js
204+
import { Types, createModel } from 'frint-data';
205+
206+
const Todo = createModel({
207+
schema: {
208+
title: Types.string, // or, Types.string.required
209+
completed: Types.bool, // or, Types.bool.defaults(false),
210+
},
211+
setTitle(newTitle) {
212+
this.title = newTitle;
213+
},
214+
});
215+
216+
const todo = new Todo({
217+
title: 'Hello World',
218+
completed: false,
219+
});
220+
221+
const title = todo.title;
222+
todo.setTitle('Updated title');
223+
```
224+
225+
## frint-compat
226+
227+
Completely emptied, and `v0.x` is no longer supported in any way.

site/partials/docsSidebar.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
<ul class="menu-list">
3636
<li><a href="/docs/migration/v1">Migrating to v1.x</a></li>
3737
<li><a href="/docs/migration/v2">Migrating to v2.x</a></li>
38+
<li><a href="/docs/migration/v3">Migrating to v3.x</a></li>
3839
</ul>
3940

4041
<p class="menu-label">

0 commit comments

Comments
 (0)