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

Commit

Permalink
v0.1.3
Browse files Browse the repository at this point in the history
- $() method can now return any type of value
  • Loading branch information
areknawo committed Apr 10, 2020
1 parent fe6fa2b commit fb183b1
Show file tree
Hide file tree
Showing 14 changed files with 274 additions and 309 deletions.
10 changes: 5 additions & 5 deletions dist/isotope.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* @isotope/core v0.1.2
* @isotope/core v0.1.3
* (c) Arek Nawo <[email protected]> (areknawo.com)
* Released under the MIT License.
*/
Expand Down Expand Up @@ -47,7 +47,7 @@
* Executes the provided directive(s).
*
* @param directives - Directive(s) to be executed.
* @returns - The Node.
* @returns - The Node or the return value of the directive.
*/
$(directives) {
if (Array.isArray(directives)) {
Expand All @@ -56,9 +56,9 @@
});
}
else {
const node = directives(this);
if (node) {
return node;
const value = directives(this);
if (typeof value !== "undefined") {
return value;
}
}
return this;
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.

4 changes: 2 additions & 2 deletions docs/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ const node = view.child("div");
const childRef = node.$(component);
```

It's important to remember that the `$()` method returns different values, depending on whether the passed function returns a node or not.
It's important to remember that if the passed function returns a value, the `$()` method forwards and returns it as its result.

## Component encapsulation

Although a directive can create multiple direct child nodes of the passed node, it's recommended to have a singular top node when designing your components.

Isotope directives have unique properties, that allow component creators to decide how they want their users to interact with their components. One of such properties is the ability to control access to component-related nodes.

A directive can either return a node or not return anything. If a component directive returns a node, then the same node will be returned after calling the `$()` method. However, if a directive doesn't return anything the `$()` method will continue on to return the node it was called upon, for easier method chaining.
A directive can either return a value or not return anything. For component directives, a very common practice would be to return the component's top-level node. After that the same node will be returned from calling the `$()` method. Remember that if a directive doesn't return anything the `$()` method will continue on to return the node it was called upon, for easier method chaining.

```javascript
// ...
Expand Down
2 changes: 1 addition & 1 deletion docs/directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ node.$(directive);

**Returns**:

- If a single directive was passed, which returns a node then this node is returned, otherwise, the node the method was called upon is returned for easier chaining.
- The node it was called upon (default). If a single directive that returns a value was passed, the same value is returned.

## Component directives

Expand Down
6 changes: 3 additions & 3 deletions lib/node.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface IsotopeNode<S extends Indexable = any, C extends Indexable = any> {
onClean: Array<(node: this) => void>;
customDOM?: CustomDOM | null;
}
declare type Directive<S extends Indexable, C extends Indexable, R extends void | IsotopeNode> = (node: IsotopeNode<S, C>) => R;
declare type Directive<S extends Indexable, C extends Indexable, R extends void | any> = (node: IsotopeNode<S, C>) => R;
/**
* Class representing a Node.
*/
Expand All @@ -36,9 +36,9 @@ declare class IsotopeNode<S extends Indexable = any, C extends Indexable = any>
* Executes the provided directive(s).
*
* @param directives - Directive(s) to be executed.
* @returns - The Node.
* @returns - The Node or the return value of the directive.
*/
$<R extends void | IsotopeNode>(directives: Directive<S, C, R> | Array<Directive<S, C, void>>): R extends void ? this : R;
$<R extends void | any>(directives: Directive<S, C, R> | Array<Directive<S, C, void>>): R extends void ? this : R;
/**
* Adds a child Node to the Node.
*
Expand Down
8 changes: 4 additions & 4 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 fb183b1

Please sign in to comment.