@nanostores/logger 0.2.4 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  <img align="right" width="92" height="92" title="Nano Stores logo"
4
4
  src="https://nanostores.github.io/nanostores/logo.svg">
5
5
 
6
- Logger of lifecycles, changes and actions for **[Nano Stores]**,
6
+ Logger of lifecycles and changes for **[Nano Stores]**,
7
7
  a tiny state manager with many atomic tree-shakable stores.
8
8
 
9
9
  * **Clean.** All messages are stacked in compact, collapsible nested groups.
@@ -1,11 +1,6 @@
1
1
  import type { AnyStore, Store, StoreValue } from 'nanostores'
2
2
 
3
3
  interface LoggerOptionsMessages {
4
- /**
5
- * Disable action logs.
6
- */
7
- action?: boolean
8
-
9
4
  /**
10
5
  * Disable change logs.
11
6
  */
@@ -23,11 +18,6 @@ interface LoggerOptionsMessages {
23
18
  }
24
19
 
25
20
  export interface LoggerOptions {
26
- /**
27
- * Disable logs of actions with a specific name.
28
- */
29
- ignoreActions?: string[]
30
-
31
21
  /**
32
22
  * Disable specific types of logs.
33
23
  */
@@ -39,33 +29,13 @@ interface EventPayloadBase {
39
29
  }
40
30
 
41
31
  interface EventChangePayload extends EventPayloadBase {
42
- actionId?: number
43
- actionName?: string
44
32
  changed?: keyof StoreValue<Store>
45
33
  newValue: any
46
34
  oldValue?: any
47
35
  valueMessage?: string
48
36
  }
49
37
 
50
- interface EventActionPayload extends EventPayloadBase {
51
- actionId: number
52
- actionName: string
53
- }
54
-
55
- interface EventActionStartPayload extends EventActionPayload {
56
- args: any[]
57
- }
58
-
59
- interface EventActionErrorPayload extends EventActionPayload {
60
- error: Error
61
- }
62
-
63
38
  interface BuildLoggerEvents {
64
- action?: {
65
- end?: (payload: EventActionPayload) => void
66
- error?: (payload: EventActionErrorPayload) => void
67
- start?: (payload: EventActionStartPayload) => void
68
- }
69
39
  change?: (payload: EventChangePayload) => void
70
40
  mount?: (payload: EventPayloadBase) => void
71
41
  unmount?: (payload: EventPayloadBase) => void
@@ -87,29 +57,12 @@ interface BuildLoggerEvents {
87
57
  * console.log(`${storeName} was unmounted`)
88
58
  * },
89
59
  *
90
- * change: ({ actionName, changed, newValue, oldValue, valueMessage }) => {
60
+ * change: ({ changed, newValue, oldValue, valueMessage }) => {
91
61
  * let message = `${storeName} was changed`
92
62
  * if (changed) message += `in the ${changed} key`
93
63
  * if (oldValue) message += `from ${oldValue}`
94
64
  * message += `to ${newValue}`
95
- * if (actionName) message += `by action ${actionName}`
96
65
  * console.log(message, valueMessage)
97
- * },
98
- *
99
- * action: {
100
- * start: ({ actionName, args }) => {
101
- * let message = `${actionName} was started`
102
- * if (args.length) message += 'with arguments'
103
- * console.log(message, args)
104
- * },
105
- *
106
- * error: ({ actionName, error }) => {
107
- * console.log(`${actionName} was failed`, error)
108
- * },
109
- *
110
- * end: ({ actionName }) => {
111
- * console.log(`${actionName} was ended`)
112
- * }
113
66
  * }
114
67
  * ```
115
68
  *
@@ -1,11 +1,4 @@
1
- import {
2
- actionId,
3
- lastAction,
4
- onAction,
5
- onMount,
6
- onNotify,
7
- onSet
8
- } from 'nanostores'
1
+ import { onMount, onNotify, onSet } from 'nanostores'
9
2
 
10
3
  const isAtom = store => store.setKey === undefined
11
4
  const isDeepMapKey = key => /.+(\..+|\[\d+\.*])/.test(key)
@@ -23,30 +16,8 @@ function handleMount(store, storeName, messages, events) {
23
16
  })
24
17
  }
25
18
 
26
- function handleAction(store, storeName, ignoreActions, events) {
27
- return onAction(store, ({ actionName, args, id, onEnd, onError }) => {
28
- if (ignoreActions && ignoreActions.includes(actionName)) return
29
-
30
- events.action.start({ actionId: id, actionName, args, storeName })
31
-
32
- onError(({ error }) => {
33
- events.action.error({ actionId: id, actionName, error, storeName })
34
- })
35
-
36
- onEnd(() => {
37
- events.action.end({ actionId: id, actionName, storeName })
38
- })
39
- })
40
- }
41
-
42
- function handleSet(store, storeName, messages, ignoreActions, events) {
19
+ function handleSet(store, storeName, events) {
43
20
  return onSet(store, ({ changed }) => {
44
- let currentActionId = store[actionId]
45
- let currentActionName = store[lastAction]
46
-
47
- if (messages.action === false && currentActionId) return
48
- if (ignoreActions && ignoreActions.includes(currentActionName)) return
49
-
50
21
  let oldValue = isAtom(store) ? store.value : { ...store.value }
51
22
  oldValue = isDeepMapKey(changed) ? structuredClone(oldValue) : oldValue
52
23
  let unbindNotify = onNotify(store, () => {
@@ -57,8 +28,6 @@ function handleSet(store, storeName, messages, ignoreActions, events) {
57
28
  }
58
29
 
59
30
  events.change({
60
- actionId: currentActionId,
61
- actionName: currentActionName,
62
31
  changed,
63
32
  newValue,
64
33
  oldValue,
@@ -72,7 +41,6 @@ function handleSet(store, storeName, messages, ignoreActions, events) {
72
41
  }
73
42
 
74
43
  export function buildLogger(store, storeName, events, opts = {}) {
75
- let ignoreActions = opts.ignoreActions
76
44
  let messages = opts.messages || {}
77
45
  let unbind = []
78
46
 
@@ -80,12 +48,8 @@ export function buildLogger(store, storeName, events, opts = {}) {
80
48
  unbind.push(handleMount(store, storeName, messages, events))
81
49
  }
82
50
 
83
- if (messages.action !== false) {
84
- unbind.push(handleAction(store, storeName, ignoreActions, events))
85
- }
86
-
87
51
  if (messages.change !== false) {
88
- unbind.push(handleSet(store, storeName, messages, ignoreActions, events))
52
+ unbind.push(handleSet(store, storeName, events))
89
53
  }
90
54
 
91
55
  return () => {
package/logger/index.js CHANGED
@@ -2,66 +2,13 @@ import { buildLogger } from '../build-logger/index.js'
2
2
  import { group, groupEnd, log } from '../printer/index.js'
3
3
 
4
4
  function createLogger(store, storeName, opts) {
5
- let queue = {}
6
-
7
5
  return buildLogger(
8
6
  store,
9
7
  storeName,
10
8
  {
11
- action: {
12
- end: ({ actionId }) => {
13
- for (let i of queue[actionId]) i()
14
- delete queue[actionId]
15
- groupEnd()
16
- },
17
-
18
- error: ({ actionId, actionName, error }) => {
19
- queue[actionId].push(() =>
20
- log({
21
- message: [
22
- ['bold', storeName],
23
- ['regular', 'store handled error in action'],
24
- ['bold', actionName]
25
- ],
26
- type: 'error',
27
- value: {
28
- message: error.message
29
- }
30
- })
31
- )
32
- },
33
-
34
- start: ({ actionId, actionName, args }) => {
35
- queue[actionId] = []
36
-
37
- let message = [
38
- ['bold', storeName],
39
- ['regular', 'store was changed by action'],
40
- ['bold', actionName]
41
- ]
42
-
43
- queue[actionId].push(() =>
44
- group({
45
- logo: true,
46
- message,
47
- type: 'action'
48
- })
49
- )
50
- if (args.length > 0) {
51
- message.push(['regular', 'with arguments'])
52
- queue[actionId].push(() =>
53
- log({
54
- type: 'arguments',
55
- value: args
56
- })
57
- )
58
- }
59
- }
60
- },
61
-
62
- change: ({ actionId, changed, newValue, oldValue, valueMessage }) => {
9
+ change: ({ changed, newValue, oldValue, valueMessage }) => {
63
10
  let groupLog = {
64
- logo: typeof actionId === 'undefined',
11
+ logo: true,
65
12
  message: [
66
13
  ['bold', storeName],
67
14
  ['regular', 'store was changed']
@@ -75,33 +22,24 @@ function createLogger(store, storeName, opts) {
75
22
  ['regular', 'key']
76
23
  )
77
24
  }
78
-
79
- let run = () => {
80
- group(groupLog)
81
- if (valueMessage) {
82
- log({
83
- message: valueMessage,
84
- type: 'value'
85
- })
86
- }
25
+ group(groupLog)
26
+ if (valueMessage) {
87
27
  log({
88
- type: 'new',
89
- value: newValue
28
+ message: valueMessage,
29
+ type: 'value'
90
30
  })
91
- if (oldValue) {
92
- log({
93
- type: 'old',
94
- value: oldValue
95
- })
96
- }
97
- groupEnd()
98
31
  }
99
-
100
- if (actionId) {
101
- queue[actionId].push(run)
102
- } else {
103
- run()
32
+ log({
33
+ type: 'new',
34
+ value: newValue
35
+ })
36
+ if (oldValue) {
37
+ log({
38
+ type: 'old',
39
+ value: oldValue
40
+ })
104
41
  }
42
+ groupEnd()
105
43
  },
106
44
 
107
45
  mount: () => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nanostores/logger",
3
- "version": "0.2.4",
4
- "description": "Pretty logger of lifecycles, changes and actions for Nano Stores",
3
+ "version": "0.4.0",
4
+ "description": "Pretty logger of lifecycles and changes for Nano Stores",
5
5
  "keywords": [
6
6
  "nanostores",
7
7
  "devtools",
@@ -24,12 +24,6 @@
24
24
  "node": "^18.0.0 || >=20.0.0"
25
25
  },
26
26
  "peerDependencies": {
27
- "nanostores": ">=0.9.2"
28
- },
29
- "nano-staged": {
30
- "*.{js,ts}": [
31
- "prettier --write",
32
- "eslint --fix"
33
- ]
27
+ "nanostores": ">=0.10.2"
34
28
  }
35
29
  }
@@ -1,5 +1,4 @@
1
1
  type LogType =
2
- | 'action'
3
2
  | 'arguments'
4
3
  | 'build'
5
4
  | 'change'
package/printer/index.js CHANGED
@@ -14,7 +14,6 @@ function borders(full) {
14
14
 
15
15
  const STYLES = {
16
16
  badges: {
17
- action: badge('#00899A'),
18
17
  arguments: badge('#007281'),
19
18
  build: badge('#BB5100'),
20
19
  change: badge('#0E8A00'),