Skip to content

Commit a291693

Browse files
authored
Merge pull request #31 from loteoo/v2
Hyperstatic V2
2 parents d0cc3b1 + 62e1d1b commit a291693

37 files changed

+1221
-9008
lines changed

package-lock.json

Lines changed: 468 additions & 8415 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,26 @@
11
{
2-
"version": "0.2.9",
2+
"version": "2.0.0",
33
"name": "hyperstatic",
44
"description": "Hyperapp static site framework",
55
"author": "Alexandre Lotte",
66
"license": "MIT",
77
"main": "dist/index.js",
8-
"module": "src/index.js",
8+
"types": "dist/index.d.ts",
99
"scripts": {
10-
"build": "parcel build ./src/index.js",
10+
"build": "tsc",
11+
"prepublish": "tsc",
1112
"test": "echo \"No test specified\""
1213
},
1314
"dependencies": {
14-
"fs-extra": "^8.1.0",
15-
"hyperapp": "^2.0.3",
16-
"puppeteer": "^1.18.1",
17-
"replace-in-file": "^4.1.1",
18-
"serve-handler": "^6.1.2",
19-
"url-pattern": "^1.0.3"
15+
"fs-extra": "^9.1.0",
16+
"hyperapp": "^2.0.12",
17+
"path-to-regexp": "^6.2.0",
18+
"puppeteer": "^7.1.0",
19+
"replace-in-file": "^6.2.0",
20+
"serve-handler": "^6.1.3"
2021
},
2122
"devDependencies": {
22-
"babel-core": "^7.0.0-0",
23-
"babel-eslint": "^10.0.2",
24-
"eslint": "^5.16.0",
25-
"eslint-config-standard": "^12.0.0",
26-
"eslint-plugin-import": "^2.18.2",
27-
"eslint-plugin-node": "^9.1.0",
28-
"eslint-plugin-promise": "^4.2.1",
29-
"eslint-plugin-react": "^7.14.2",
30-
"eslint-plugin-standard": "^4.0.0",
31-
"parcel-bundler": "^1.12.3",
32-
"rimraf": "^2.6.3"
23+
"@types/node": "^14.14.28"
3324
},
3425
"repository": {
3526
"type": "git",
@@ -43,5 +34,5 @@
4334
"bugs": {
4435
"url": "https://github.com/loteoo/hyperstatic/issues"
4536
},
46-
"homepage": "https://github.com/loteoo/hyperstatic#readme"
37+
"homepage": "https://hyperstatic.dev"
4738
}

src/Lifecycle.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/Link.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/NoPrerender.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/Router.js

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/StaticFetch.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/StaticQuery.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/actions.js

Lines changed: 0 additions & 110 deletions
This file was deleted.

src/actions/InitializePath.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import SetPathStatus from './SetPathStatus';
2+
import { LocationState, State } from '../types';
3+
4+
interface InitializePathArgs {
5+
location: LocationState
6+
bundle: any;
7+
}
8+
9+
/**
10+
* Run the "init" action if necessary once per page
11+
*/
12+
const InitializePath = (state: State, { location, bundle }: InitializePathArgs) => {
13+
const { path } = location;
14+
15+
// If current path is already initiated, do nothing
16+
if (state.paths[path] === 'ready') {
17+
return state;
18+
}
19+
20+
// If current path doesn't have an "init" to run
21+
if (typeof bundle?.init !== 'function') {
22+
23+
// Set as ready
24+
return SetPathStatus(state, { path, status: 'ready' })
25+
}
26+
27+
// Compute next state or action tuple using the provided "init" action
28+
const action = bundle?.init(
29+
state,
30+
location
31+
)
32+
33+
// If has init has side-effects
34+
if (Array.isArray(action)) {
35+
36+
// Get only the "loadStatic" effect tuples
37+
const loadEffects = action.slice(1).filter((fx => fx[0].fxName === 'loadStatic'))
38+
39+
// If this page has data requirements
40+
if (loadEffects.length > 0) {
41+
42+
// Set path as fetching
43+
action[0] = SetPathStatus(action[0], { path, status: 'fetching' })
44+
45+
// Set the path for the effect
46+
loadEffects.forEach(fx => fx[1].path = path)
47+
}
48+
49+
return action
50+
}
51+
52+
return SetPathStatus(action, { path, status: 'ready' })
53+
}
54+
55+
export default InitializePath

0 commit comments

Comments
 (0)