Browse Source

Added functionality to allow for clean up operations by cogs

Wirecog 6 years 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
 	id              string
28
 	id              string
29
 	hasBeenRendered bool
29
 	hasBeenRendered bool
30
 	parseTree       *reconcile.ParseTree
30
 	parseTree       *reconcile.ParseTree
31
+	cleanupFunc     func()
31
 }
32
 }
32
 
33
 
33
 func (u *UXCog) getCogPrefixName() string {
34
 func (u *UXCog) getCogPrefixName() string {
48
 	u.id = id
49
 	u.id = id
49
 }
50
 }
50
 
51
 
52
+func (u *UXCog) SetCleanupFunc(cleanupFunc func()) {
53
+	u.cleanupFunc = cleanupFunc
54
+}
55
+
51
 func (u *UXCog) SetElement(element *dom.Element) {
56
 func (u *UXCog) SetElement(element *dom.Element) {
52
 	u.element = element
57
 	u.element = element
53
 }
58
 }
154
 
159
 
155
 func (u *UXCog) Render() error {
160
 func (u *UXCog) Render() error {
156
 	document := dom.GetWindow().Document()
161
 	document := dom.GetWindow().Document()
157
-
158
 	e := document.GetElementByID(u.ID())
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
 	if strings.ToLower(e.GetAttribute("data-component")) != "cog" {
171
 	if strings.ToLower(e.GetAttribute("data-component")) != "cog" {
160
 		return errors.New("The cog container div must have a \"data-component\" attribute with a value specified as \"cog\".")
172
 		return errors.New("The cog container div must have a \"data-component\" attribute with a value specified as \"cog\".")
161
 	}
173
 	}