Skip to content

Commit 4f9c63c

Browse files
committed
fix: moved observer out of loop as only needs to be declared once.
- Added organization_id and host to selectors
1 parent 28a9175 commit 4f9c63c

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/form.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,6 @@ function init(elements) {
1717
else if (!Array.isArray(elements)) elements = [elements];
1818

1919
for (let element of elements) {
20-
Observer.init({
21-
name: "CoCreateFormElements",
22-
observe: ["addedNodes"],
23-
selector:
24-
"[storage], [database], [array], [index], [object], [key]",
25-
callback: function (mutation) {
26-
if (element == mutation.target.form)
27-
setAttribute(element, [mutation.target]);
28-
}
29-
});
30-
3120
runObjectId(element);
3221
setAttribute(element);
3322
disableAutoFill(element);
@@ -43,6 +32,8 @@ function init(elements) {
4332
/**
4433
* @param form
4534
*/
35+
// TODO: runObjectId could potentially be removed and handled by element-prototype getAttribute $object_id
36+
// Somthing to consider is that $object_id is not replaced by an _id causing getAttribute to return a new _id on each get
4637
function runObjectId(form) {
4738
let elements = Array.from(form.querySelectorAll("[object='ObjectId()']"));
4839

@@ -62,7 +53,7 @@ function runObjectId(form) {
6253
function setAttribute(form, elements) {
6354
if (!elements)
6455
elements = form.querySelectorAll(
65-
"[storage], [database], [array], [index], [object], [key]"
56+
"[organization_id], [host], [storage], [database], [array], [index], [object], [key]"
6657
);
6758

6859
for (let attribute of form.attributes) {
@@ -184,6 +175,8 @@ Observer.init({
184175
name: "CoCreateForm",
185176
observe: ["attributes"],
186177
attributeName: getAttributeNames([
178+
"organization_id",
179+
"host",
187180
"storage",
188181
"database",
189182
"array",
@@ -195,6 +188,17 @@ Observer.init({
195188
mutation.target.tagName === "FORM" && setAttribute(mutation.target)
196189
});
197190

191+
Observer.init({
192+
name: "CoCreateFormElements",
193+
observe: ["addedNodes"],
194+
selector:
195+
"[organization_id], [host], [storage], [database], [array], [index], [object], [key]",
196+
callback: function (mutation) {
197+
if (mutation.target.form)
198+
setAttribute(mutation.target.form, [mutation.target]);
199+
}
200+
});
201+
198202
Action.init({
199203
name: "reset",
200204
endEvent: "reset",

0 commit comments

Comments
 (0)