Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

Commit

Permalink
v0.2.2
Browse files Browse the repository at this point in the history
- Fix context initialization when working with config input directives.
  • Loading branch information
areknawo committed Apr 17, 2020
1 parent 790c588 commit 0ff1463
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 79 deletions.
42 changes: 26 additions & 16 deletions dist/isotope.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* @isotope/core v0.2.1
* @isotope/core v0.2.2
* (c) Arek Nawo <[email protected]> (areknawo.com)
* Released under the MIT License.
*/
Expand All @@ -24,7 +24,7 @@
if (typeof config === "string") {
this.element.textContent = config;
}
else if (typeof config === "object" && !Array.isArray(config)) {
else if (typeof config === "object") {
if (config.attach) {
this.childIndex = 0;
}
Expand All @@ -41,9 +41,6 @@
callback(this, config);
});
}
else if (config) {
this.$(config);
}
this.process();
}
/**
Expand Down Expand Up @@ -75,30 +72,28 @@
*/
child(tag, config) {
const shouldAttach = typeof this.childIndex !== "undefined";
const isConfigDirective = typeof config === "function" || Array.isArray(config);
let element = tag;
if (shouldAttach) {
const attachTarget = this.element.children[this.childIndex || 0];
const index = this.childIndex || 0;
const attachTarget = this.element.children[index];
if (attachTarget) {
element = attachTarget;
this.childIndex = (this.childIndex || 0) + 1;
this.childIndex = index + 1;
}
}
const node = new IsotopeNode(element, config);
const node = new IsotopeNode(element, isConfigDirective ? {} : config);
this.element.appendChild(node.element);
if (shouldAttach && !node.childIndex) {
node.childIndex = 0;
}
if (this.context) {
if (node.context) {
node.context = Object.assign(node.context, this.context);
}
else {
node.context = this.context;
}
}
this.passContext(node);
if (this.autoLink) {
this.link(node);
}
if (isConfigDirective) {
this.$(config);
}
return node;
}
/**
Expand Down Expand Up @@ -269,6 +264,21 @@
}
return element;
}
/**
* Passes context to the child node.
*
* @param node - Node to pass the context to.
*/
passContext(node) {
if (this.context) {
if (node.context) {
node.context = Object.assign(node.context, this.context);
}
else {
node.context = this.context;
}
}
}
/**
* Processes and renders the Node.
*/
Expand Down
4 changes: 2 additions & 2 deletions dist/isotope.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/isotope.min.js.map

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion lib/node.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ declare class IsotopeNode<S extends Indexable = any, C extends Indexable = any>
* @param element - The Node's HTML element or tag.
* @param config - The Node's configuration.
*/
constructor(element: string | CustomElement | Element, config?: IsotopeNodeConfig<S, C> | string | Directive<S, C, void> | Array<Directive<S, C, void>>);
constructor(element: string | CustomElement | Element, config?: IsotopeNodeConfig<S, C> | string);
/**
* Executes the provided directive(s).
*
Expand Down Expand Up @@ -136,6 +136,12 @@ declare class IsotopeNode<S extends Indexable = any, C extends Indexable = any>
* @returns - Retrieved element.
*/
protected getElement(element: string | CustomElement | Element, config?: IsotopeNodeConfig<S, C> | string | Directive<S, C, void> | Array<Directive<S, C, void>>): CustomElement;
/**
* Passes context to the child node.
*
* @param node - Node to pass the context to.
*/
protected passContext(node: IsotopeNode): void;
/**
* Processes and renders the Node.
*/
Expand Down
40 changes: 25 additions & 15 deletions lib/node.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/node.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0ff1463

Please sign in to comment.