@@ -76,13 +76,9 @@ export default {
76
76
name: " PlaygroundBlock" ,
77
77
components: { PgEditor, RulesSettings, SnsBar },
78
78
data () {
79
- const serializedString =
80
- (typeof window !== " undefined" && window .location .hash .slice (1 )) ||
81
- " "
82
- const state = deserializeState (serializedString)
83
79
return {
84
- code: state . code || DEFAULT_CODE ,
85
- rules: state . rules || Object .assign ({}, DEFAULT_RULES_CONFIG ),
80
+ code: DEFAULT_CODE ,
81
+ rules: Object .assign ({}, DEFAULT_RULES_CONFIG ),
86
82
messages: [],
87
83
}
88
84
},
@@ -103,19 +99,34 @@ export default {
103
99
},
104
100
watch: {
105
101
serializedString (serializedString ) {
106
- if (typeof window !== " undefined" ) {
102
+ if (
103
+ typeof window !== " undefined" &&
104
+ serializedString !== window .location .hash .slice (1 ) &&
105
+ ! this ._initializing
106
+ ) {
107
107
window .location .replace (` #${ serializedString} ` )
108
108
}
109
109
},
110
110
},
111
111
mounted () {
112
112
if (typeof window !== " undefined" ) {
113
- window .addEventListener (" hashchange" , this .onUrlHashChange )
113
+ window .addEventListener (" hashchange" , this .processUrlHashChange )
114
+ }
115
+ const serializedString =
116
+ (typeof window !== " undefined" && window .location .hash .slice (1 )) ||
117
+ " "
118
+ if (serializedString) {
119
+ this ._initializing = true
120
+ this .rules = {}
121
+ this .$nextTick ().then (() => {
122
+ this ._initializing = false
123
+ this .processUrlHashChange ()
124
+ })
114
125
}
115
126
},
116
- beforeDestroey () {
127
+ beforeUnmount () {
117
128
if (typeof window !== " undefined" ) {
118
- window .removeEventListener (" hashchange" , this .onUrlHashChange )
129
+ window .removeEventListener (" hashchange" , this .processUrlHashChange )
119
130
}
120
131
},
121
132
methods: {
@@ -125,7 +136,7 @@ export default {
125
136
getRule (ruleId ) {
126
137
return getRule (ruleId)
127
138
},
128
- onUrlHashChange () {
139
+ processUrlHashChange () {
129
140
const serializedString =
130
141
(typeof window !== " undefined" &&
131
142
window .location .hash .slice (1 )) ||
@@ -135,8 +146,9 @@ export default {
135
146
this .code = state .code || DEFAULT_CODE
136
147
this .rules =
137
148
state .rules || Object .assign ({}, DEFAULT_RULES_CONFIG )
138
- this . script = state . script
149
+ return true
139
150
}
151
+ return false
140
152
},
141
153
},
142
154
}
0 commit comments