This repository was archived by the owner on Jul 6, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 6 files changed +15
-24
lines changed
hello-world-spa/api/counter
hello-world-src-dir/src/api/counter Expand file tree Collapse file tree 6 files changed +15
-24
lines changed Original file line number Diff line number Diff line change 1
1
import type { APIRequest } from 'aleph/types.ts'
2
2
3
- const store = globalThis as any
4
-
5
3
export default async function handler ( req : APIRequest ) {
6
- let count = store . $ count || 0
4
+ let count = parseInt ( localStorage . getItem ( ' count' ) || '0' )
7
5
8
6
switch ( req . params [ 'action' ] ) {
9
7
case 'increase' :
10
8
count ++
11
- store . $ count = count
9
+ localStorage . setItem ( ' count' , count . toString ( ) )
12
10
req . json ( { count } )
13
11
break
14
12
case 'decrease' :
15
13
count --
16
- store . $ count = count
14
+ localStorage . setItem ( ' count' , count . toString ( ) )
17
15
req . json ( { count } )
18
16
break
19
17
default :
Original file line number Diff line number Diff line change 1
1
import type { APIRequest } from 'aleph/types.ts'
2
2
3
- const store = globalThis as any
4
-
5
3
export default async function handler ( req : APIRequest ) {
6
- req . json ( { count : store . $count || 0 } )
4
+ const count = parseInt ( localStorage . getItem ( 'count' ) || '0' )
5
+ req . json ( { count } )
7
6
}
Original file line number Diff line number Diff line change 1
1
import type { APIRequest } from 'aleph/types.ts'
2
2
3
- const store = globalThis as any
4
-
5
3
export default async function handler ( req : APIRequest ) {
6
- let count = store . $ count || 0
4
+ let count = parseInt ( localStorage . getItem ( ' count' ) || '0' )
7
5
8
6
switch ( req . params [ 'action' ] ) {
9
7
case 'increase' :
10
8
count ++
11
- store . $ count = count
9
+ localStorage . setItem ( ' count' , count . toString ( ) )
12
10
req . json ( { count } )
13
11
break
14
12
case 'decrease' :
15
13
count --
16
- store . $ count = count
14
+ localStorage . setItem ( ' count' , count . toString ( ) )
17
15
req . json ( { count } )
18
16
break
19
17
default :
Original file line number Diff line number Diff line change 1
1
import type { APIRequest } from 'aleph/types.ts'
2
2
3
- const store = globalThis as any
4
-
5
3
export default async function handler ( req : APIRequest ) {
6
- req . json ( { count : store . $count || 0 } )
4
+ const count = parseInt ( localStorage . getItem ( 'count' ) || '0' )
5
+ req . json ( { count } )
7
6
}
Original file line number Diff line number Diff line change 1
1
import type { APIRequest } from 'aleph/types.ts'
2
2
3
- const store = globalThis as any
4
-
5
3
export default async function handler ( req : APIRequest ) {
6
- let count = store . $ count || 0
4
+ let count = parseInt ( localStorage . getItem ( ' count' ) || '0' )
7
5
8
6
switch ( req . params [ 'action' ] ) {
9
7
case 'increase' :
10
8
count ++
11
- store . $ count = count
9
+ localStorage . setItem ( ' count' , count . toString ( ) )
12
10
req . json ( { count } )
13
11
break
14
12
case 'decrease' :
15
13
count --
16
- store . $ count = count
14
+ localStorage . setItem ( ' count' , count . toString ( ) )
17
15
req . json ( { count } )
18
16
break
19
17
default :
Original file line number Diff line number Diff line change 1
1
import type { APIRequest } from 'aleph/types.ts'
2
2
3
- const store = globalThis as any
4
-
5
3
export default async function handler ( req : APIRequest ) {
6
- req . json ( { count : store . $count || 0 } )
4
+ const count = parseInt ( localStorage . getItem ( 'count' ) || '0' )
5
+ req . json ( { count } )
7
6
}
You can’t perform that action at this time.
0 commit comments