Skip to content

Commit 84e2b48

Browse files
committed
rename lib/jtag to lib/tag
1 parent 883c47e commit 84e2b48

40 files changed

Lines changed: 253 additions & 253 deletions

element.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"sync/atomic"
1111

1212
"github.com/linkdata/jaws/lib/jid"
13-
"github.com/linkdata/jaws/lib/jtag"
13+
"github.com/linkdata/jaws/lib/tag"
1414
"github.com/linkdata/jaws/lib/what"
1515
"github.com/linkdata/jaws/lib/wire"
1616
)
@@ -44,8 +44,8 @@ func (e *Element) Tag(tags ...any) {
4444
}
4545

4646
// HasTag returns true if this Element has the given tag.
47-
func (e *Element) HasTag(tag any) bool {
48-
return !e.deleted.Load() && e.Request.HasTag(e, tag)
47+
func (e *Element) HasTag(tagValue any) bool {
48+
return !e.deleted.Load() && e.Request.HasTag(e, tagValue)
4949
}
5050

5151
// Jid returns the JaWS ID for this Element, unique within it's Request.
@@ -58,10 +58,10 @@ func (e *Element) Ui() UI {
5858
return e.ui
5959
}
6060

61-
func (e *Element) maybeDirty(tag any, err error) (bool, error) {
61+
func (e *Element) maybeDirty(tagValue any, err error) (bool, error) {
6262
switch err {
6363
case nil:
64-
e.Dirty(tag)
64+
e.Dirty(tagValue)
6565
return true, nil
6666
case ErrValueUnchanged:
6767
return false, nil
@@ -74,11 +74,11 @@ func (e *Element) renderDebug(w io.Writer) {
7474
_, _ = fmt.Fprintf(&sb, "<!-- id=%q %T tags=[", e.Jid(), e.Ui())
7575
if e.mu.TryRLock() {
7676
defer e.mu.RUnlock()
77-
for i, tag := range e.tagsOfLocked(e) {
77+
for i, tagValue := range e.tagsOfLocked(e) {
7878
if i > 0 {
7979
sb.WriteString(", ")
8080
}
81-
sb.WriteString(jtag.TagString(tag))
81+
sb.WriteString(tag.TagString(tagValue))
8282
}
8383
} else {
8484
sb.WriteString("n/a")
@@ -243,11 +243,11 @@ func (e *Element) ApplyParams(params []any) (retv []template.HTMLAttr) {
243243
//
244244
// Returns the Tag(s) added, or nil if getter was nil, along with
245245
// any error returned from JawsInit() if it was called.
246-
func (e *Element) ApplyGetter(getter any) (tag any, err error) {
246+
func (e *Element) ApplyGetter(getter any) (tagValue any, err error) {
247247
if getter != nil {
248-
tag = getter
249-
if tagger, ok := getter.(jtag.TagGetter); ok {
250-
tag = tagger.JawsGetTag(e.Request)
248+
tagValue = getter
249+
if tagger, ok := getter.(tag.TagGetter); ok {
250+
tagValue = tagger.JawsGetTag(e.Request)
251251
}
252252
if eh, ok := getter.(EventHandler); ok {
253253
e.handlers = append(e.handlers, eh)
@@ -259,7 +259,7 @@ func (e *Element) ApplyGetter(getter any) (tag any, err error) {
259259
e.handlers = append(e.handlers, contextMenuHandlerWrapper{ch})
260260
}
261261
}
262-
e.Tag(tag)
262+
e.Tag(tagValue)
263263
if initer, ok := getter.(InitHandler); ok {
264264
err = initer.JawsInit(e)
265265
}

element_test.go

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
"github.com/linkdata/deadlock"
1515
"github.com/linkdata/jaws/lib/jid"
16-
"github.com/linkdata/jaws/lib/jtag"
16+
"github.com/linkdata/jaws/lib/tag"
1717
"github.com/linkdata/jaws/lib/what"
1818
"github.com/linkdata/jaws/lib/wire"
1919
)
@@ -70,7 +70,7 @@ type testApplyGetterAll struct {
7070
initErr error
7171
}
7272

73-
func (a testApplyGetterAll) JawsGetTag(jtag.Context) any { return jtag.Tag("tg") }
73+
func (a testApplyGetterAll) JawsGetTag(tag.Context) any { return tag.Tag("tg") }
7474
func (a testApplyGetterAll) JawsClick(*Element, Click) error {
7575
return ErrEventUnhandled
7676
}
@@ -102,9 +102,9 @@ func TestElement_Tag(t *testing.T) {
102102

103103
tss := &testUi{}
104104
e := rq.NewElement(tss)
105-
is.True(!e.HasTag(jtag.Tag("zomg")))
106-
e.Tag(jtag.Tag("zomg"))
107-
is.True(e.HasTag(jtag.Tag("zomg")))
105+
is.True(!e.HasTag(tag.Tag("zomg")))
106+
e.Tag(tag.Tag("zomg"))
107+
is.True(e.HasTag(tag.Tag("zomg")))
108108
s := e.String()
109109
if !strings.Contains(s, "zomg") {
110110
t.Error(s)
@@ -220,8 +220,8 @@ func TestElement_ReplaceMessageTargetsElementHTML(t *testing.T) {
220220
rq := newTestRequest(t)
221221
defer rq.Close()
222222

223-
tag := &testUi{}
224-
jid := rq.Register(tag)
223+
tagValue := &testUi{}
224+
jid := rq.Register(tagValue)
225225
elem := rq.GetElementByJid(jid)
226226
if elem == nil {
227227
t.Fatal("missing element")
@@ -261,9 +261,9 @@ func TestElement_maybeDirty(t *testing.T) {
261261
th.Equal(changed, false)
262262
th.Equal(err, nil)
263263

264-
changed, err = e.maybeDirty(e, jtag.ErrNotComparable)
264+
changed, err = e.maybeDirty(e, tag.ErrNotComparable)
265265
th.Equal(changed, false)
266-
th.Equal(err, jtag.ErrNotComparable)
266+
th.Equal(err, tag.ErrNotComparable)
267267
}
268268

269269
func TestElement_RenderDebugAndDeletedBranches(t *testing.T) {
@@ -283,7 +283,7 @@ func TestElement_RenderDebugAndDeletedBranches(t *testing.T) {
283283
elem.renderDebug(&sb)
284284
rq.mu.Unlock()
285285

286-
elem.Tag(jtag.Tag("a"), jtag.Tag("b"))
286+
elem.Tag(tag.Tag("a"), tag.Tag("b"))
287287
sb.Reset()
288288
elem.renderDebug(&sb)
289289
if !strings.Contains(sb.String(), ", ") {
@@ -310,20 +310,20 @@ func TestElement_ApplyGetterDebugBranches(t *testing.T) {
310310
defer rq.Close()
311311
elem := rq.NewElement(&testUi{})
312312

313-
if tag, err := elem.ApplyGetter(nil); tag != nil || err != nil {
314-
t.Fatalf("unexpected %v %v", tag, err)
313+
if gotTag, err := elem.ApplyGetter(nil); gotTag != nil || err != nil {
314+
t.Fatalf("unexpected %v %v", gotTag, err)
315315
}
316316

317317
ag := testApplyGetterAll{}
318318
gotTags, err := elem.ApplyGetter(ag)
319319
if err != nil {
320320
t.Fatalf("unexpected error %v", err)
321321
}
322-
if !elem.HasTag(jtag.Tag("tg")) {
322+
if !elem.HasTag(tag.Tag("tg")) {
323323
t.Fatalf("missing Tag('tg') in %#v", gotTags)
324324
}
325-
agErr := testApplyGetterAll{initErr: jtag.ErrNotComparable}
326-
if _, err := elem.ApplyGetter(agErr); err != jtag.ErrNotComparable {
325+
agErr := testApplyGetterAll{initErr: tag.ErrNotComparable}
326+
if _, err := elem.ApplyGetter(agErr); err != tag.ErrNotComparable {
327327
t.Fatalf("expected init err, got %v", err)
328328
}
329329

@@ -408,9 +408,9 @@ func TestElement_ApplyGetter(t *testing.T) {
408408
e := rq.NewElement(tss)
409409

410410
var tch testClickHandler
411-
tag, err := e.ApplyGetter(tch)
412-
if tag != tch {
413-
t.Errorf("tag was %#v", tag)
411+
gotTag, err := e.ApplyGetter(tch)
412+
if gotTag != tch {
413+
t.Errorf("tag was %#v", gotTag)
414414
}
415415
if err != nil {
416416
t.Error(err)
@@ -545,15 +545,15 @@ func TestElement_JawsInit(t *testing.T) {
545545
defer rq.Close()
546546

547547
tss := &testUi{s: "foo"}
548-
tss.initError = jtag.ErrNotComparable
548+
tss.initError = tag.ErrNotComparable
549549
e := rq.NewElement(tss)
550550

551-
tag, err := e.ApplyGetter(tss)
551+
gotTag, err := e.ApplyGetter(tss)
552552
is.Equal(atomic.LoadInt32(&tss.initCalled), int32(1))
553-
if tag != tss {
554-
t.Errorf("tag was %#v", tag)
553+
if gotTag != tss {
554+
t.Errorf("tag was %#v", gotTag)
555555
}
556-
if err != jtag.ErrNotComparable {
556+
if err != tag.ErrNotComparable {
557557
t.Error(err)
558558
}
559559
}

eventhandler_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import (
88
"strings"
99
"testing"
1010

11-
"github.com/linkdata/jaws/lib/jtag"
11+
"github.com/linkdata/jaws/lib/tag"
1212
"github.com/linkdata/jaws/lib/what"
1313
"github.com/linkdata/jaws/lib/wire"
1414
)
1515

1616
type testJawsEvent struct {
1717
msgCh chan string
18-
tag any
18+
tagValue any
1919
clickerr error
2020
eventerr error
2121
}
@@ -36,15 +36,15 @@ func (t *testJawsEvent) JawsEvent(e *Element, wht what.What, val string) (err er
3636
return
3737
}
3838

39-
func (t *testJawsEvent) JawsGetTag(jtag.Context) (tag any) {
40-
return t.tag
39+
func (t *testJawsEvent) JawsGetTag(tag.Context) (tagValue any) {
40+
return t.tagValue
4141
}
4242

4343
func (t *testJawsEvent) JawsRender(e *Element, w io.Writer, params []any) (err error) {
44-
var tag any
45-
if tag, err = e.ApplyGetter(t); err == nil {
44+
var tagValue any
45+
if tagValue, err = e.ApplyGetter(t); err == nil {
4646
w.Write([]byte(fmt.Sprint(params)))
47-
t.msgCh <- fmt.Sprintf("JawsRender(%d)%#v", e.jid, tag)
47+
t.msgCh <- fmt.Sprintf("JawsRender(%d)%#v", e.jid, tagValue)
4848
}
4949
return
5050
}
@@ -55,7 +55,7 @@ func (t *testJawsEvent) JawsUpdate(e *Element) {
5555

5656
var _ ClickHandler = (*testJawsEvent)(nil)
5757
var _ EventHandler = (*testJawsEvent)(nil)
58-
var _ jtag.TagGetter = (*testJawsEvent)(nil)
58+
var _ tag.TagGetter = (*testJawsEvent)(nil)
5959
var _ UI = (*testJawsEvent)(nil)
6060

6161
func Test_JawsEvent_NonClickInvokesJawsEventForDualHandler(t *testing.T) {

jaws.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434
"github.com/linkdata/deadlock"
3535
"github.com/linkdata/jaws/lib/assets"
3636
"github.com/linkdata/jaws/lib/jid"
37-
"github.com/linkdata/jaws/lib/jtag"
37+
"github.com/linkdata/jaws/lib/tag"
3838
"github.com/linkdata/jaws/lib/what"
3939
"github.com/linkdata/jaws/lib/wire"
4040
"github.com/linkdata/secureheaders"
@@ -159,7 +159,7 @@ func (jw *Jaws) Done() <-chan struct{} {
159159
// strings to *template.Template.
160160
func (jw *Jaws) AddTemplateLookuper(tl TemplateLookuper) (err error) {
161161
if tl != nil {
162-
if err = jtag.NewErrNotComparable(tl); err == nil {
162+
if err = tag.NewErrNotComparable(tl); err == nil {
163163
jw.mu.Lock()
164164
if !slices.Contains(jw.tmplookers, tl) {
165165
jw.tmplookers = append(jw.tmplookers, tl)
@@ -174,7 +174,7 @@ func (jw *Jaws) AddTemplateLookuper(tl TemplateLookuper) (err error) {
174174
// the list of TemplateLookupers.
175175
func (jw *Jaws) RemoveTemplateLookuper(tl TemplateLookuper) (err error) {
176176
if tl != nil {
177-
if err = jtag.NewErrNotComparable(tl); err == nil {
177+
if err = tag.NewErrNotComparable(tl); err == nil {
178178
jw.mu.Lock()
179179
jw.tmplookers = slices.DeleteFunc(jw.tmplookers, func(x TemplateLookuper) bool { return x == tl })
180180
jw.mu.Unlock()
@@ -508,7 +508,7 @@ func (jw *Jaws) Broadcast(msg wire.Message) {
508508
case *Request: // send to that request
509509
case string: // HTML id (accepted by all requests)
510510
default:
511-
expanded, err := jtag.TagExpand(nil, msg.Dest)
511+
expanded, err := tag.TagExpand(nil, msg.Dest)
512512
jw.MustLog(err)
513513
switch len(expanded) {
514514
case 0:
@@ -529,9 +529,9 @@ func (jw *Jaws) Broadcast(msg wire.Message) {
529529
// setDirty marks all Elements that have one or more of the given tags as dirty.
530530
func (jw *Jaws) setDirty(tags []any) {
531531
jw.mu.Lock()
532-
for _, tag := range tags {
532+
for _, tagValue := range tags {
533533
jw.dirtOrder++
534-
jw.dirty[tag] = jw.dirtOrder
534+
jw.dirty[tagValue] = jw.dirtOrder
535535
}
536536
jw.mu.Unlock()
537537
}
@@ -541,7 +541,7 @@ func (jw *Jaws) setDirty(tags []any) {
541541
// Note that if any of the tags are a TagGetter, it will be called with a nil Request.
542542
// Prefer using Request.Dirty() which avoids this.
543543
func (jw *Jaws) Dirty(dirtyTags ...any) {
544-
jw.setDirty(jtag.MustTagExpand(nil, dirtyTags))
544+
jw.setDirty(tag.MustTagExpand(nil, dirtyTags))
545545
}
546546

547547
func (jw *Jaws) distributeDirt() int {
@@ -875,9 +875,9 @@ var whitespaceRemover = strings.NewReplacer(" ", "", "\n", "", "\t", "")
875875

876876
// JsCall calls the Javascript function 'jsfunc' with the argument 'jsonstr'
877877
// on all Requests that have the target UI tag.
878-
func (jw *Jaws) JsCall(tag any, jsfunc, jsonstr string) {
878+
func (jw *Jaws) JsCall(tagValue any, jsfunc, jsonstr string) {
879879
jw.Broadcast(wire.Message{
880-
Dest: tag,
880+
Dest: tagValue,
881881
What: what.Call,
882882
Data: whitespaceRemover.Replace(jsfunc) + "=" + maybeCompactJSON(jsonstr),
883883
})

jaws_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"time"
1818

1919
"github.com/linkdata/jaws/lib/assets"
20-
"github.com/linkdata/jaws/lib/jtag"
20+
"github.com/linkdata/jaws/lib/tag"
2121
"github.com/linkdata/jaws/lib/what"
2222
"github.com/linkdata/jaws/lib/wire"
2323
"github.com/linkdata/secureheaders"
@@ -26,8 +26,8 @@ import (
2626

2727
type testBroadcastTagGetter struct{}
2828

29-
func (testBroadcastTagGetter) JawsGetTag(jtag.Context) any {
30-
return jtag.Tag("expanded")
29+
func (testBroadcastTagGetter) JawsGetTag(tag.Context) any {
30+
return tag.Tag("expanded")
3131
}
3232

3333
func TestNew_DefaultWebSocketPingInterval(t *testing.T) {
@@ -133,12 +133,12 @@ func TestBroadcast_ExpandsTagDestBeforeQueue(t *testing.T) {
133133
if msg.What != what.Inner || msg.Data != "x" {
134134
t.Fatalf("unexpected msg %#v", msg)
135135
}
136-
if got, ok := msg.Dest.(jtag.Tag); !ok || got != jtag.Tag("expanded") {
136+
if got, ok := msg.Dest.(tag.Tag); !ok || got != tag.Tag("expanded") {
137137
t.Fatalf("expected expanded Tag destination, got %T(%#v)", msg.Dest, msg.Dest)
138138
}
139139

140140
jw.Broadcast(wire.Message{
141-
Dest: []any{tagger, jtag.Tag("extra")},
141+
Dest: []any{tagger, tag.Tag("extra")},
142142
What: what.Value,
143143
Data: "v",
144144
})
@@ -150,7 +150,7 @@ func TestBroadcast_ExpandsTagDestBeforeQueue(t *testing.T) {
150150
if !ok {
151151
t.Fatalf("expected []any destination, got %T(%#v)", msg.Dest, msg.Dest)
152152
}
153-
if len(dest) != 2 || dest[0] != jtag.Tag("expanded") || dest[1] != jtag.Tag("extra") {
153+
if len(dest) != 2 || dest[0] != tag.Tag("expanded") || dest[1] != tag.Tag("extra") {
154154
t.Fatalf("unexpected expanded destination %#v", dest)
155155
}
156156

@@ -375,11 +375,11 @@ func TestJaws_distributeDirt_AscendingOrder(t *testing.T) {
375375
rq := &Request{}
376376
jw.mu.Lock()
377377
jw.requests[1] = rq
378-
jw.dirty[jtag.Tag("fourth")] = 4
379-
jw.dirty[jtag.Tag("second")] = 2
380-
jw.dirty[jtag.Tag("fifth")] = 5
381-
jw.dirty[jtag.Tag("first")] = 1
382-
jw.dirty[jtag.Tag("third")] = 3
378+
jw.dirty[tag.Tag("fourth")] = 4
379+
jw.dirty[tag.Tag("second")] = 2
380+
jw.dirty[tag.Tag("fifth")] = 5
381+
jw.dirty[tag.Tag("first")] = 1
382+
jw.dirty[tag.Tag("third")] = 3
383383
jw.dirtOrder = 5
384384
jw.mu.Unlock()
385385

@@ -392,11 +392,11 @@ func TestJaws_distributeDirt_AscendingOrder(t *testing.T) {
392392
rq.mu.RUnlock()
393393

394394
want := []any{
395-
jtag.Tag("first"),
396-
jtag.Tag("second"),
397-
jtag.Tag("third"),
398-
jtag.Tag("fourth"),
399-
jtag.Tag("fifth"),
395+
tag.Tag("first"),
396+
tag.Tag("second"),
397+
tag.Tag("third"),
398+
tag.Tag("fourth"),
399+
tag.Tag("fifth"),
400400
}
401401
if !reflect.DeepEqual(got, want) {
402402
t.Fatalf("dirty tags = %#v, want %#v", got, want)
@@ -862,7 +862,7 @@ func TestJaws_Session(t *testing.T) {
862862
rq := newTestRequest(t)
863863
defer rq.Close()
864864

865-
dot := jtag.Tag("123")
865+
dot := tag.Tag("123")
866866

867867
h := rq.Jaws.Session(rq.Jaws.Handler("testtemplate", dot))
868868
var buf bytes.Buffer

0 commit comments

Comments
 (0)