Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2d85b9f

Browse files
authored
Merge pull request#92 from github/refetch
add refetch API
2 parents5dfb899 +5056f9f commit2d85b9f

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

‎src/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ export default class IncludeFragmentElement extends HTMLElement {
125125
returnfetch(request)
126126
}
127127

128+
refetch(){
129+
privateData.delete(this)
130+
this.#handleData()
131+
}
132+
128133
#observer=newIntersectionObserver(
129134
entries=>{
130135
for(constentryofentries){
@@ -169,11 +174,17 @@ export default class IncludeFragmentElement extends HTMLElement {
169174
constcanceled=!this.dispatchEvent(
170175
newCustomEvent('include-fragment-replace',{cancelable:true,detail:{fragment}})
171176
)
172-
if(canceled)return
177+
if(canceled){
178+
this.#busy=false
179+
return
180+
}
181+
173182
this.replaceWith(fragment)
174183
this.dispatchEvent(newCustomEvent('include-fragment-replaced'))
175184
}catch{
176185
this.classList.add('is-error')
186+
}finally{
187+
this.#busy=false
177188
}
178189
}
179190

‎test/test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ suite('include-fragment-element', function () {
9797
teardown(()=>{
9898
document.body.innerHTML=''
9999
})
100+
100101
test('create from document.createElement',function(){
101102
constel=document.createElement('include-fragment')
102103
assert.equal('INCLUDE-FRAGMENT',el.nodeName)
@@ -141,6 +142,19 @@ suite('include-fragment-element', function () {
141142
)
142143
})
143144

145+
test('skips cache when using refetch',asyncfunction(){
146+
constel=document.createElement('include-fragment')
147+
el.src='/count'
148+
149+
letdata=awaitel.data
150+
assert.equal('1',data)
151+
152+
el.refetch()
153+
154+
data=awaitel.data
155+
assert.equal('2',data)
156+
})
157+
144158
test('data with src attribute',function(){
145159
constel=document.createElement('include-fragment')
146160
el.setAttribute('src','/hello')

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp