File tree Expand file tree Collapse file tree 2 files changed +10
-25
lines changed
content/tutorial/01-svelte/07-lifecycle/03-update Expand file tree Collapse file tree 2 files changed +10
-25
lines changed Original file line number Diff line number Diff line change 1
1
<script >
2
2
import Eliza from ' elizabot' ;
3
- import {
4
- beforeUpdate ,
5
- afterUpdate
6
- } from ' svelte' ;
3
+ import { beforeUpdate , afterUpdate } from ' svelte' ;
7
4
8
5
let div;
9
6
18
15
19
16
const eliza = new Eliza ();
20
17
21
- let comments = [
22
- { author: ' eliza' , text: eliza .getInitial () }
23
- ];
18
+ let comments = [{ author: ' eliza' , text: eliza .getInitial () }];
24
19
25
20
function handleKeydown (event ) {
26
21
if (event .key === ' Enter' ) {
45
40
46
41
setTimeout (() => {
47
42
comments = comments
48
- .filter (
49
- (comment ) => ! comment .placeholder
50
- )
43
+ .filter ((comment ) => ! comment .placeholder )
51
44
.concat ({
52
45
author: ' eliza' ,
53
46
text: reply
103
96
.eliza span {
104
97
background-color : #eee ;
105
98
border-radius : 1em 1em 1em 0 ;
99
+ color : black ;
106
100
}
107
101
108
102
.user span {
Original file line number Diff line number Diff line change 1
1
<script >
2
2
import Eliza from ' elizabot' ;
3
- import {
4
- beforeUpdate ,
5
- afterUpdate
6
- } from ' svelte' ;
3
+ import { beforeUpdate , afterUpdate } from ' svelte' ;
7
4
8
5
let div;
9
6
let autoscroll;
10
7
11
8
beforeUpdate (() => {
12
9
autoscroll =
13
- div &&
14
- div .offsetHeight + div .scrollTop >
15
- div .scrollHeight - 20 ;
10
+ div && div .offsetHeight + div .scrollTop > div .scrollHeight - 20 ;
16
11
});
17
12
18
13
afterUpdate (() => {
19
- if (autoscroll)
20
- div .scrollTo (0 , div .scrollHeight );
14
+ if (autoscroll) div .scrollTo (0 , div .scrollHeight );
21
15
});
22
16
23
17
const eliza = new Eliza ();
24
18
25
- let comments = [
26
- { author: ' eliza' , text: eliza .getInitial () }
27
- ];
19
+ let comments = [{ author: ' eliza' , text: eliza .getInitial () }];
28
20
29
21
function handleKeydown (event ) {
30
22
if (event .key === ' Enter' ) {
49
41
50
42
setTimeout (() => {
51
43
comments = comments
52
- .filter (
53
- (comment ) => ! comment .placeholder
54
- )
44
+ .filter ((comment ) => ! comment .placeholder )
55
45
.concat ({
56
46
author: ' eliza' ,
57
47
text: reply
107
97
.eliza span {
108
98
background-color : #eee ;
109
99
border-radius : 1em 1em 1em 0 ;
100
+ color : black ;
110
101
}
111
102
112
103
.user span {
You can’t perform that action at this time.
0 commit comments