Skip to content
This repository was archived by the owner on Oct 1, 2022. It is now read-only.

Commit 24fa262

Browse files
authored
Update Pulse to 3.1.0 (#128)
Develop — updates
2 parents dfdb022 + 031b8f4 commit 24fa262

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+2528
-41126
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ private/
2525
*.sw*
2626

2727
# Generated files from build
28+
build/
29+
declarations/
2830
dist/
2931
docs/dist/
3032

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
examples
2-
test
2+
test
3+
build/

_config.yml

Lines changed: 0 additions & 1 deletion
This file was deleted.

config/readme.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
please do NOT change any config files without consulting Jamie first! Thanks :P
2+
3+
handy command to remove accidental build files in lib
4+
5+
```
6+
rm -f lib/**/*.(js|js.map)
7+
```

config/tsconfig.dev.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "../dist",
5+
"declaration": true,
6+
"declarationDir": "../dist"
7+
}
8+
}

config/tsconfig.prod.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"declaration": true,
5+
"declarationDir": "../declarations"
6+
}
7+
}

config/webpack.config.dev.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const base = require('../webpack.config');
2+
3+
module.exports = {
4+
...base('dev'),
5+
name: 'dev',
6+
mode: 'development',
7+
devtool: 'inline-source-map',
8+
watch: true,
9+
entry: {
10+
index: './lib/index.ts',
11+
next: './lib/next'
12+
},
13+
plugins: []
14+
};

config/webpack.config.prod.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const base = require('../webpack.config');
2+
const dts = require('dts-bundle-webpack');
3+
const TerserPlugin = require('terser-webpack-plugin');
4+
5+
module.exports = {
6+
...base('prod'),
7+
name: 'build',
8+
mode: 'production',
9+
devtool: 'hidden-source-map',
10+
entry: {
11+
index: './lib/index.ts',
12+
next: './lib/next'
13+
},
14+
optimization: {
15+
minimize: true,
16+
minimizer: [
17+
new TerserPlugin({
18+
terserOptions: {
19+
keep_classnames: true,
20+
keep_fnames: true
21+
}
22+
})
23+
]
24+
},
25+
plugins: [
26+
new dts({
27+
name: 'pulse-framework',
28+
main: 'declarations/index.d.ts',
29+
out: '../dist/index.d.ts'
30+
}),
31+
new dts({
32+
name: 'pulse-framework/next',
33+
main: 'declarations/next/index.d.ts',
34+
out: '../../dist/next.d.ts'
35+
})
36+
]
37+
};

docs/.vuepress/config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ module.exports = {
121121
{
122122
title: 'Getting Started',
123123
collapsable: false,
124-
children: ['getting-started/setup-with-react', 'getting-started/concepts']
124+
children: ['getting-started/setup-with-react', 'getting-started/setup-with-vue', 'getting-started/concepts']
125125
},
126126
{
127127
title: 'Documentation',
@@ -136,6 +136,7 @@ module.exports = {
136136
'docs/core',
137137
'docs/api',
138138
'docs/persisting-data',
139+
'docs/events',
139140
'docs/ssr'
140141
]
141142
},

docs/v3/docs/api.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
---
22
title: API
33
---
4-
54
## Introduction
6-
5+
::: warning Sorry!
6+
This page is not up to standards, improvements need to be made inline with the rest of the documentation.
7+
:::
78
# API
89

910
This is Pulse's integrated fetch API. It's a wrapper around Fetch, which is native to the browser environment.
10-
11+
```ts
12+
const MyAPI = App.API()
13+
```
1114
## Setup
12-
13-
To create an api instance, you must pass a config object. This will define several things such as the options, baseurl, path, timeout and some functions to run before and after each http request.
14-
15+
The API class accepts a config object.
1516
```ts
1617
const MyAPI = App.API({
1718
options: {
1819
headers: {
1920
'content-type': 'application/json, text/plain' // this is not necessary
2021
}
21-
// ...
2222
},
2323
baseURL: 'https://api.mysite.co', // default: 'https://localhost'
2424
path: '/api', // default: '/'
@@ -71,9 +71,9 @@ interface PulseResponse<DataType = any> {
7171
}
7272
```
7373

74-
**Available functions and Properties**
74+
## Methods
7575

76-
## `API.with()`
76+
# `.with()`
7777

7878
This function allows you to override the API config and request options. It returns a modified instance of the original API with the options in the config parameter overriding the original config options.
7979

@@ -85,7 +85,7 @@ This function allows you to override the API config and request options. It retu
8585

8686
- [response (Response)](#response)
8787

88-
## `API.get()`
88+
# `.get()`
8989

9090
Send a HTTP get request to a url
9191

@@ -98,7 +98,7 @@ Send a HTTP get request to a url
9898

9999
- [response (Response)](#response)
100100

101-
## `API.post()`
101+
# `.post()`
102102

103103
Send a HTTP post request to a URL
104104

@@ -112,7 +112,7 @@ Send a HTTP post request to a URL
112112

113113
- [response (Response)](#response)
114114

115-
## `API.put()`
115+
# `.put()`
116116

117117
Send a HTTP put request to a URL
118118

@@ -126,7 +126,7 @@ Send a HTTP put request to a URL
126126

127127
- [response (Response)](#response)
128128

129-
## `API.patch()`
129+
# `.patch()`
130130

131131
Send a HTTP patch request to a URL
132132

@@ -140,7 +140,7 @@ Send a HTTP patch request to a URL
140140

141141
- [Response (response)](#response)
142142

143-
## `API.delete()`
143+
# `.delete()`
144144

145145
Send a HTTP delete request to a URL
146146

docs/v3/docs/computed.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,32 @@ _Forces the Computed instance to recompute_
6666
```typescript
6767
MY_COMPUTED.recompute();
6868
```
69+
70+
## Initial compute
71+
Computed functions need to compute their value initially, however doing this upon declaration can cause issues depending on data accessed within the compute function.
72+
73+
Normally Pulse applications use `App.Core()` to export the [Core](), but this function also acts as a way to finalize Pulse. This is a perfect opportunity to compute the initial values for all Computed instances.
74+
75+
```ts
76+
const App = new Pulse();
77+
78+
const MY_COMPUTED = App.Computed(() => 1 + 1);
79+
80+
MY_COMPUTED.value // undefined
81+
82+
const core = App.Core(myCore);
83+
84+
MY_COMPUTED.value // 2
85+
```
86+
87+
88+
If they were to compute immediately after declaration, other State / Computed values in your core might not be defined yet, throwing many angry errors.
89+
90+
If this is not the behavior you want, or you are not using a core you can bypass this logic using the config option `noCore: true`
91+
```ts
92+
const App = new Pulse({ noCore: true });
93+
94+
const MY_COMPUTED = App.Computed(() => 1 + 1);
95+
96+
MY_COMPUTED.value // 2
97+
```

docs/v3/docs/controllers.md

Lines changed: 41 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -26,62 +26,59 @@ The first parameter of the Controller function is `ControllerConfig`
2626
const App = new Pulse();
2727

2828
const config = {
29-
collection: App.Collection()(),
30-
state: {
31-
MY_STATE: App.State(boolean),
32-
MY_COMPUTED_STATE: App.Computed<boolean>(() => true)
33-
}
34-
}
29+
collection: App.Collection()(),
30+
state: {
31+
MY_STATE: App.State(),
32+
MY_COMPUTED_STATE: App.Computed(() => true)
33+
}
34+
};
3535
export const accounts = App.Controller(config);
3636
```
3737

38-
### Controller Config Structure
38+
## Config Structure
3939

40-
> The following example is demonstrating the structure of the `ControllerConfig` with a Typescript interface, in practice this of course would be a real object.
40+
Each of the below properties passed into the config will be made available on the root. Think of these as pre-defined containers within your controller.
4141

42-
```js
43-
interface ControllerConfig {
44-
name?: string;
45-
collection?: Collection | { [name: string]: Collection }; // A single Collection, or an object of Collections
46-
groups?: { [name: string]: Group } // an object of Groups
47-
selectors?: { [name: string]: Selector } // an object of Selectors
48-
actions?: { [name: string]: Function } // an object of functions
49-
helpers?: { [name: string]: Function } // an object of functions
50-
routes?: { [name: string]: Function } // an object of functions
51-
}
52-
```
42+
| parameter | type | description |
43+
| -------------- | ------------------------ | ------------------------------------------------------------------------------------- |
44+
| `state?` | `Object` of `State` | A container for State objects. |
45+
| `collection?` | `Collection` | The primary Collection also exposes `.groups` and `.selectors` to root of controller. |
46+
| `collections?` | `Object` of `Collection` | Other Collection instances this controller may need. |
47+
| `actions?` | `Object` of `Function` | |
48+
| `routes?` | `Object` of `Function` | |
49+
| `helpers?` | `Object` of `Function` | |
5350

54-
These are the only available properties for the `ControllerConfig`, any aditional will be ignored. However it is possible to add custom root properties ([See Below](#custom-root-properties)).
51+
These are the only available properties for the `ControllerConfig`, any additional will be ignored. However it is possible to add custom root properties ([See .root()](#methods)).
5552

5653
::: tip Type Safety
5754
For Typescript users, the inferred types of the object you pass in will be preserved, but only for the properties shown on the above object.
5855
:::
5956

60-
## Custom Root Properties
57+
## Methods
58+
59+
# `.root()`
6160

6261
In some cases you will prefer to use more than the default Controller categories, you might want to spread actions to the root of the controller instance so they can be access like the following.
6362

6463
```js
6564
accounts.myAction();
6665
```
6766

68-
We can do this with the second parameter of the `App.Controller` function. The properties of the supplied object will be spread to the root of the Controller instance.
67+
The `Controller.root()` method will return the Controller instance with the properties of the object supplied infused into the Controller at root level.
6968

70-
In order to maintain type safety we can export the account and cast a custom type that combines the `controller` with `actions` in this case.
69+
```ts
70+
const state = { MY_STATE: App.State() };
71+
const actions = { myAction: App.Action() };
7172

72-
```js
73-
const controller = App.Controller({
74-
state: AccountState,
75-
collection: AccountCollection,
76-
routes,
77-
}, actions);
73+
const controller = App.Controller({ state }).root(actions);
7874

79-
export const accounts = controller as typeof controller & typeof actions;
75+
controller.state.MY_STATE;
76+
controller.myAction();
8077
```
8178

8279
## Structure
8380

84-
This is how a controller folder should be organised.
81+
This is how a controller folder should be organized.
8582

8683
### `index.ts`
8784

@@ -94,10 +91,7 @@ import { state, computed, collection } from './state';
9491
import * as actions from './actions';
9592

9693
// init controller, merge state and computed state
97-
const controller = App.Controller({ state: { ...state, ...computed }, collection }, actions);
98-
99-
// export with typesaftey
100-
export default controller as typeof controller & typeof actions;
94+
const controller = App.Controller({ state: { ...state, ...computed }, collection }).root(actions);
10195
```
10296

10397
The order of imports above is important, state/collections must be imported first to also allow them to be imported into `actions.ts` without creating a cyclic import. Sometimes this can cause `import * as ...` to return an empty object at runtime, following this structure will avoid that.
@@ -108,22 +102,22 @@ The order of imports above is important, state/collections must be imported firs
108102
import App from '../../app';
109103

110104
export const collection = App.Collection()(Collection => ({
111-
groups: {
112-
MY_GROUP: Collection.Group()
113-
}
114-
}))
105+
groups: {
106+
MY_GROUP: Collection.Group()
107+
}
108+
}));
115109

116110
export const state = {
117-
MY_STATE: App.State('hello')
118-
// etc...
119-
}
111+
MY_STATE: App.State('hello')
112+
// etc...
113+
};
120114

121115
export const computed = {
122-
MY_COMPUTED: App.Computed(() => {
123-
return 1 + 2
124-
})
125-
// etc...
126-
}
116+
MY_COMPUTED: App.Computed(() => {
117+
return 1 + 2;
118+
})
119+
// etc...
120+
};
127121
```
128122

129123
### `actions.ts`

0 commit comments

Comments
 (0)