Browse Source

Added functionality to allow for clean up operations by cogs

Wirecog, LLC 1 year ago
parent
commit
003a4b1bc1
1 changed files with 13 additions and 1 deletions
  1. 13
    1
      uxcog.go

+ 13
- 1
uxcog.go View File

@@ -28,6 +28,7 @@ type UXCog struct {
28 28
 	id              string
29 29
 	hasBeenRendered bool
30 30
 	parseTree       *reconcile.ParseTree
31
+	cleanupFunc     func()
31 32
 }
32 33
 
33 34
 func (u *UXCog) getCogPrefixName() string {
@@ -48,6 +49,10 @@ func (u *UXCog) SetID(id string) {
48 49
 	u.id = id
49 50
 }
50 51
 
52
+func (u *UXCog) SetCleanupFunc(cleanupFunc func()) {
53
+	u.cleanupFunc = cleanupFunc
54
+}
55
+
51 56
 func (u *UXCog) SetElement(element *dom.Element) {
52 57
 	u.element = element
53 58
 }
@@ -154,8 +159,15 @@ func (u *UXCog) RenderCogTemplate() {
154 159
 
155 160
 func (u *UXCog) Render() error {
156 161
 	document := dom.GetWindow().Document()
157
-
158 162
 	e := document.GetElementByID(u.ID())
163
+
164
+	if u.hasBeenRendered == true && e == nil {
165
+		if u.cleanupFunc != nil {
166
+			u.cleanupFunc()
167
+			return nil
168
+		}
169
+	}
170
+
159 171
 	if strings.ToLower(e.GetAttribute("data-component")) != "cog" {
160 172
 		return errors.New("The cog container div must have a \"data-component\" attribute with a value specified as \"cog\".")
161 173
 	}