Skip to content

Commit 7018c0e

Browse files
authored
Merge pull request #27 from okwolf/update
all the hyperapp 2 updates
2 parents 634e52b + 1f1069e commit 7018c0e

12 files changed

Lines changed: 247 additions & 269 deletions

File tree

.github/workflows/ci.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: CI
2+
on: push
3+
jobs:
4+
test:
5+
env:
6+
NODE_ENV: development
7+
runs-on: ubuntu-latest
8+
strategy:
9+
matrix:
10+
node-version: [12.x, 14.x, 16.x]
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v1
14+
- name: Use Node.js ${{ matrix.node-version }}
15+
uses: actions/setup-node@v1
16+
with:
17+
node-version: ${{ matrix.node-version }}
18+
- name: Test
19+
run: |
20+
npm install -g codecov
21+
npm install
22+
npm test
23+
codecov

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
.vscode/
2-
yarn.lock
31
coverage/
42
node_modules/
53
dist/

.npmrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
package-lock = false
2+
save-prefix = =

.prettierrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"trailingComma": "none",
3+
"arrowParens": "avoid"
4+
}

.travis.yml

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

.vscode/launch.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Debug Jest Tests",
9+
"type": "node",
10+
"request": "launch",
11+
"program": "${workspaceRoot}/node_modules/jest/bin/jest.js",
12+
"args": [
13+
"--runInBand",
14+
"--watch"
15+
],
16+
"runtimeArgs": [
17+
"--nolazy",
18+
"--experimental-vm-modules"
19+
],
20+
"console": "integratedTerminal",
21+
"internalConsoleOptions": "neverOpen"
22+
}
23+
]
24+
}

README.md

Lines changed: 52 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,37 @@
1-
# <img height=24 src=https://cdn.rawgit.com/jorgebucaran/f53d2c00bafcf36e84ffd862f0dc2950/raw/882f20c970ff7d61aa04d44b92fc3530fa758bc0/Hyperapp.svg> Hyperapp Logger
1+
# Hyperapp Logger
22

3-
[![Travis CI](https://img.shields.io/travis/hyperapp/logger/master.svg)](https://travis-ci.org/hyperapp/logger)
4-
[![Codecov](https://img.shields.io/codecov/c/github/hyperapp/logger/master.svg)](https://codecov.io/gh/hyperapp/logger)
5-
[![npm](https://img.shields.io/npm/v/@hyperapp/logger.svg)](https://www.npmjs.org/package/@hyperapp/logger)
6-
[![Slack](https://hyperappjs.herokuapp.com/badge.svg)](https://hyperappjs.herokuapp.com "Join us")
3+
[![Build Status](https://github.com/okwolf/hyperapp-logger/actions/workflows/ci.yml/badge.svg)](https://github.com/okwolf/hyperapp-logger/actions)
4+
[![Codecov](https://img.shields.io/codecov/c/github/okwolf/hyperapp-logger/master.svg)](https://codecov.io/gh/okwolf/hyperapp-logger)
5+
[![npm](https://img.shields.io/npm/v/hyperapp-logger.svg?maxAge=2592000?style=plastic)](https://www.npmjs.com/package/hyperapp-logger)
76

8-
A [Hyperapp](https://github.com/hyperapp/hyperapp) higher-order `app` that logs state updates and action information to the console.
7+
A [Hyperapp](https://github.com/hyperapp/hyperapp) [dispatch initializer](https://github.com/jorgebucaran/hyperapp/blob/main/docs/architecture/dispatch.md#dispatch-initializer) that logs state updates and action information to the console.
98

109
## Getting Started
1110

1211
This example shows a counter that can be incremented or decremented. Go ahead and [try it online](https://codepen.io/okwolf/pen/xLQmvW?editors=0010) with your browser console open to see the log messages.
1312

14-
```js
15-
import { h, app } from "hyperapp"
16-
import { withLogger } from "@hyperapp/logger"
17-
18-
const state = {
19-
count: 0
20-
}
21-
22-
const actions = {
23-
down: () => state => ({ count: state.count - 1 }),
24-
up: () => state => ({ count: state.count + 1 })
25-
}
26-
27-
const view = (state, actions) => (
28-
<main>
29-
<h1>{state.count}</h1>
30-
<button onclick={actions.down} disabled={state.count <= 0}>
31-
32-
</button>
33-
<button onclick={actions.up}></button>
34-
</main>
35-
)
36-
37-
withLogger(app)(state, actions, view, document.body)
13+
```jsx
14+
import { app } from "hyperapp";
15+
import logger from "hyperapp-logger";
16+
17+
const Up = state => state + 1;
18+
const Down = state => state - 1;
19+
20+
app({
21+
init: 0,
22+
view: state => (
23+
<main>
24+
<h1>{state.count}</h1>
25+
<button onclick={Down}></button>
26+
<button onclick={Up}></button>
27+
</main>
28+
),
29+
node: document.getElementById("app"),
30+
dispatch: logger
31+
});
3832
```
3933

40-
![Screenshot](https://user-images.githubusercontent.com/3735164/36941306-d7233132-1f0c-11e8-9b97-335f7957a685.png)
34+
![Screenshot](https://user-images.githubusercontent.com/3735164/152481590-d18dc32a-71fa-47da-8606-742bc6fc42b1.png)
4135

4236
## Installation
4337

@@ -46,40 +40,44 @@ withLogger(app)(state, actions, view, document.body)
4640
Install with npm / Yarn.
4741

4842
<pre>
49-
npm i <a href="https://www.npmjs.com/package/@hyperapp/logger">@hyperapp/logger</a>
43+
npm i <a href="https://www.npmjs.com/package/hyperapp-logger">hyperapp-logger</a>
5044
</pre>
5145

5246
Then with a module bundler like [rollup](https://github.com/rollup/rollup) or [webpack](https://github.com/webpack/webpack) use as you would anything else.
5347

5448
```js
55-
import { withLogger } from "@hyperapp/logger"
49+
import logger from "hyperapp-logger";
5650
```
5751

5852
### Browser
5953

60-
Download the minified library from the [CDN](https://unpkg.com/@hyperapp/logger).
54+
Download the minified library from the [CDN](https://unpkg.com/hyperapp-logger).
6155

6256
```html
63-
<script src="https://unpkg.com/@hyperapp/logger"></script>
57+
<script src="https://unpkg.com/hyperapp-logger"></script>
6458
```
6559

6660
You can find the library in `window.hyperappLogger`.
6761

68-
```js
69-
const { withLogger } = hyperappLogger
70-
```
71-
7262
## Usage
7363

74-
Compose the `withLogger` function with your `app` before calling it with the usual arguments.
75-
7664
```js
77-
import { withLogger } from "@hyperapp/logger"
65+
import logger from "hyperapp-logger";
7866

79-
withLogger(app)(state, actions, view, document.body)
67+
app({
68+
init,
69+
view,
70+
node,
71+
dispatch: logger
72+
});
8073

8174
// Or if you need to pass options
82-
withLogger(options)(app)(state, actions, view, document.body)
75+
app({
76+
init,
77+
view,
78+
node,
79+
dispatch: logger(options)
80+
});
8381
```
8482

8583
### Options
@@ -89,11 +87,16 @@ withLogger(options)(app)(state, actions, view, document.body)
8987
Use it to customize the log function.
9088

9189
```js
92-
withLogger({
93-
log(prevState, action, nextState) {
94-
// format and send your log messages anywhere you like
95-
}
96-
})(app)(state, actions, view, document.body)
90+
app({
91+
init,
92+
view,
93+
node,
94+
dispatch: logger({
95+
log(state, action, props, actionResult) {
96+
// format and send your log messages anywhere you like
97+
}
98+
})
99+
});
97100
```
98101

99102
## License

package.json

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,47 @@
11
{
2-
"name": "@hyperapp/logger",
2+
"name": "hyperapp-logger",
33
"version": "0.5.0",
44
"description": "Log Hyperapp state updates and action information to the console",
55
"main": "dist/hyperappLogger.js",
6-
"jsnext:main": "src/index.js",
6+
"type": "module",
77
"module": "src/index.js",
88
"repository": {
99
"type": "git",
10-
"url": "git+https://github.com/hyperapp/logger.git"
10+
"url": "git+https://github.com/okwolf/hyperapp-logger.git"
1111
},
1212
"files": [
1313
"src/**",
1414
"dist/**"
1515
],
1616
"scripts": {
17-
"clean": "npx rimraf coverage dist node_modules",
18-
"format": "prettier --write '{src,test}/**/*.js'",
19-
"format:check": "prettier --list-different {src,test}/**/*.js",
20-
"test": "jest --coverage --no-cache",
17+
"clean": "npx --ignore-existing --quiet rimraf coverage dist node_modules",
18+
"format": "prettier --write \"{src,test}/**/*.js\"",
19+
"format:check": "prettier --list-different \"{src,test}/**/*.js\"",
20+
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --coverage --no-cache",
2121
"bundle": "rollup -i src/index.js -o dist/hyperappLogger.js -m -f umd -n hyperappLogger",
2222
"minify": "uglifyjs dist/hyperappLogger.js -o dist/hyperappLogger.js -mc pure_funcs=['Object.defineProperty'] --source-map includeSources,url=hyperappLogger.js.map",
2323
"check": "npm run format:check && npm t",
2424
"build": "npm run check && npm run bundle && npm run minify",
25-
"prepare": "npm run build",
26-
"release": "npm run clean && npm i && git commit -am $npm_package_version && git tag $npm_package_version && git push && git push --tags && npm publish"
25+
"release:dry": "npm run clean && npm i && npm run check && npm run build",
26+
"release": "node --experimental-json-modules release"
2727
},
28-
"prettier": {
29-
"semi": false
28+
"jest": {
29+
"transform": {}
3030
},
31-
"babel": {
32-
"presets": "env"
31+
"peerDependencies": {
32+
"hyperapp": "^2.0.0"
3333
},
3434
"devDependencies": {
35-
"babel-preset-env": "^1.6.1",
36-
"hyperapp": "^1.1.2",
37-
"jest": "^21.2.1",
38-
"prettier": "^1.11.1",
39-
"rollup": "^0.56.3",
40-
"uglify-js": "^3.3.12"
41-
},
42-
"peerDependencies": {
43-
"hyperapp": "^1.1.2"
35+
"hyperapp": "=2.0.20",
36+
"jest": "=27.4.7",
37+
"prettier": "=2.5.1",
38+
"rollup": "=2.67.0",
39+
"uglify-js": "=3.15.0"
4440
},
4541
"author": "Wolfgang Wedemeyer <wolf@okwolf.com>",
4642
"license": "MIT",
4743
"bugs": {
48-
"url": "https://github.com/hyperapp/logger/issues"
44+
"url": "https://github.com/okwolf/hyperapp-logger/issues"
4945
},
50-
"homepage": "https://github.com/hyperapp/logger"
46+
"homepage": "https://github.com/okwolf/hyperapp-logger"
5147
}

release.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { execSync } from "child_process";
2+
import packageJson from "./package.json";
3+
import { fileURLToPath } from "url";
4+
import { dirname } from "path";
5+
6+
const __filename = fileURLToPath(import.meta.url);
7+
const __dirname = dirname(__filename);
8+
const exec = command => execSync(command, { encoding: "utf8" }).trim();
9+
10+
const exitWithError = error => {
11+
process.stderr.write(`\x1b[1;31m${error}\x1b[0m\n\n`);
12+
process.exit(1);
13+
};
14+
15+
const gitBranchName = exec("git rev-parse --abbrev-ref HEAD");
16+
if (gitBranchName !== "master") {
17+
exitWithError("please checkout the master branch to make a release!");
18+
}
19+
20+
const workingCopyChanges = exec("git status --porcelain");
21+
if (workingCopyChanges) {
22+
exitWithError("please commit your changes before making a release!");
23+
}
24+
25+
const tagExists = exec(`git tag -l "${packageJson.version}"`);
26+
if (tagExists) {
27+
exitWithError(`${packageJson.version} has already been released!`);
28+
}
29+
30+
execSync(
31+
`npm run release:dry && git tag ${packageJson.version} && git push && git push --tags && npm publish`,
32+
{
33+
shell: true,
34+
stdio: "inherit",
35+
cwd: __dirname
36+
}
37+
);

src/defaultLog.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
export default function(prevState, action, nextState) {
2-
console.group("%c action", "color: gray; font-weight: lighter;", action.name)
3-
console.log("%c prev state", "color: #9E9E9E; font-weight: bold;", prevState)
4-
console.log("%c data", "color: #03A9F4; font-weight: bold;", action.data)
5-
console.log("%c next state", "color: #4CAF50; font-weight: bold;", nextState)
6-
console.groupEnd()
1+
export default function (state, action, props, actionResult) {
2+
console.group("%c action", "color: gray; font-weight: lighter;", action.name);
3+
console.log("%c state", "color: #9E9E9E; font-weight: bold;", state);
4+
console.log("%c props", "color: #03A9F4; font-weight: bold;", props);
5+
console.log(
6+
"%c action result",
7+
"color: #4CAF50; font-weight: bold;",
8+
actionResult
9+
);
10+
console.groupEnd();
711
}

0 commit comments

Comments
 (0)