Skip to content

Commit

Permalink
Replace deepmerge with lodash mergeWith
Browse files Browse the repository at this point in the history
  • Loading branch information
thewebartisan7 committed Oct 25, 2022
1 parent ecd7d54 commit 36db959
Show file tree
Hide file tree
Showing 13 changed files with 149 additions and 56 deletions.
8 changes: 7 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
## 1.0.0-beta.7 (2022-10-24)

* Replace underscore with lodash
* Replace deepmerge with lodash method `mergeWith`
* Added merge customizer via options for lodash method `mergeWith`

## 1.0.0-beta.6 (2022-10-24)

* Fix $slots context
* Fix `$slots` context

## 1.0.0-beta.5 (2022-10-24)

Expand Down
23 changes: 23 additions & 0 deletions docs/docs.html
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,23 @@ <h2 id="options" tabindex="-1">
</td>
<td style="text-align:left">Boolean value for enable or disable throw an exception.</td>
</tr>
<tr>
<td style="text-align:center">
<strong>mergeCustomizer</strong>
</td>
<td style="text-align:center">
<code>function</code>
</td>
<td style="text-align:left">
Function callback passed to lodash
<code>mergeWith</code>
for attribute
<code>locals</code>
and
<code>merge:attribute</code>
. By default it's used to concat array.
</td>
</tr>
</tbody>
</table>
<h2 id="features" tabindex="-1">
Expand Down Expand Up @@ -1087,6 +1104,12 @@ <h3 id="props" tabindex="-1">
<code>class</code>
attribute of the first node. Let's see in next section more about this.
</p>
<p>
You can change how attributes are merged by passing via options a callback function used by lodash method
<a href="https://lodash.com/docs/4.17.15#mergeWith">mergeWith</a>
.
By default, it's used to concat array.
</p>
<h3 id="attributes" tabindex="-1">
<a class="header-anchor" href="#attributes">#</a>
Attributes
Expand Down
23 changes: 23 additions & 0 deletions examples/dist/docs.html
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,23 @@ <h2 id="options" tabindex="-1">
</td>
<td style="text-align:left">Boolean value for enable or disable throw an exception.</td>
</tr>
<tr>
<td style="text-align:center">
<strong>mergeCustomizer</strong>
</td>
<td style="text-align:center">
<code>function</code>
</td>
<td style="text-align:left">
Function callback passed to lodash
<code>mergeWith</code>
for attribute
<code>locals</code>
and
<code>merge:attribute</code>
. By default it's used to concat array.
</td>
</tr>
</tbody>
</table>
<h2 id="features" tabindex="-1">
Expand Down Expand Up @@ -1087,6 +1104,12 @@ <h3 id="props" tabindex="-1">
<code>class</code>
attribute of the first node. Let's see in next section more about this.
</p>
<p>
You can change how attributes are merged by passing via options a callback function used by lodash method
<a href="https://lodash.com/docs/4.17.15#mergeWith">mergeWith</a>
.
By default, it's used to concat array.
</p>
<h3 id="attributes" tabindex="-1">
<a class="header-anchor" href="#attributes">#</a>
Attributes
Expand Down
8 changes: 7 additions & 1 deletion examples/src/md/changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
## 1.0.0-beta.7 (2022-10-24)

* Replace underscore with lodash
* Replace deepmerge with lodash method `mergeWith`
* Added merge customizer via options for lodash method `mergeWith`

## 1.0.0-beta.6 (2022-10-24)

* Fix $slots context
* Fix `$slots` context

## 1.0.0-beta.5 (2022-10-24)

Expand Down
48 changes: 26 additions & 22 deletions examples/src/md/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,28 +88,29 @@ See also the `examples` folder. You can run `npm run build-examples` to compile

## Options

| Option | Default | Description |
|:----------------------:|:----------------------------:|:----------------------------------------------------------------------------------------------------------------------|
| **root** | `'./'` | String value as root path for components lookup. |
| **folders** | `['']` | Array of additional multi folders path from `options.root` or any defined namespaces root, fallback or custom. |
| **tagPrefix** | `x-` | String for tag prefix. The plugin will use RegExp with this string. |
| **tag** | `false` | String or boolean value for component tag. Use this with `options.attribute`. Boolean only false. |
| **attribute** | `src` | String value for component attribute for set path. |
| **namespaces** | `[]` | Array of namespace's root path, fallback path and custom path for override. |
| **namespaceSeparator** | `::` | String value for namespace separator to be used with tag name. Example `<x-namespace::button>` |
| **fileExtension** | `html` | String value for file extension of the components used for retrieve x-tag file. |
| **yield** | `yield` | String value for `<yield>` tag name. Where main content of component is injected. |
| **slot** | `slot` | String value for `<slot>` tag name. Used with RegExp by appending `:` (example `<slot:slot-name>`). |
| **fill** | `fill` | String value for `<fill>` tag name. Used with RegExp by appending `:` (example `<fill:slot-name>`). |
| **slotSeparator** | `:` | String value used for separate `<slot>` and `<fill>` tag from their names. |
| **push** | `push` | String value for `<push>` tag name. |
| **stack** | `stack` | String value for `<stack>` tag name. |
| **localsAttr** | `props` | String value used in `<script props>` parsed by the plugin to retrieve locals in the components. |
| **expressions** | `{}` | Object to configure `posthtml-expressions`. You can pre-set locals or customize the delimiters for example. |
| **plugins** | `[]` | PostHTML plugins to apply for every parsed components. |
| **matcher** | `[{tag: options.tagPrefix}]` | Array of object used to match the tags. |
| **attrsParserRules** | `{}` | Additional rules for attributes parser plugin. |
| **strict** | `true` | Boolean value for enable or disable throw an exception. |
| Option | Default | Description |
|:----------------------:|:----------------------------:|:-----------------------------------------------------------------------------------------------------------------------------------|
| **root** | `'./'` | String value as root path for components lookup. |
| **folders** | `['']` | Array of additional multi folders path from `options.root` or any defined namespaces root, fallback or custom. |
| **tagPrefix** | `x-` | String for tag prefix. The plugin will use RegExp with this string. |
| **tag** | `false` | String or boolean value for component tag. Use this with `options.attribute`. Boolean only false. |
| **attribute** | `src` | String value for component attribute for set path. |
| **namespaces** | `[]` | Array of namespace's root path, fallback path and custom path for override. |
| **namespaceSeparator** | `::` | String value for namespace separator to be used with tag name. Example `<x-namespace::button>` |
| **fileExtension** | `html` | String value for file extension of the components used for retrieve x-tag file. |
| **yield** | `yield` | String value for `<yield>` tag name. Where main content of component is injected. |
| **slot** | `slot` | String value for `<slot>` tag name. Used with RegExp by appending `:` (example `<slot:slot-name>`). |
| **fill** | `fill` | String value for `<fill>` tag name. Used with RegExp by appending `:` (example `<fill:slot-name>`). |
| **slotSeparator** | `:` | String value used for separate `<slot>` and `<fill>` tag from their names. |
| **push** | `push` | String value for `<push>` tag name. |
| **stack** | `stack` | String value for `<stack>` tag name. |
| **localsAttr** | `props` | String value used in `<script props>` parsed by the plugin to retrieve locals in the components. |
| **expressions** | `{}` | Object to configure `posthtml-expressions`. You can pre-set locals or customize the delimiters for example. |
| **plugins** | `[]` | PostHTML plugins to apply for every parsed components. |
| **matcher** | `[{tag: options.tagPrefix}]` | Array of object used to match the tags. |
| **attrsParserRules** | `{}` | Additional rules for attributes parser plugin. |
| **strict** | `true` | Boolean value for enable or disable throw an exception. |
| **mergeCustomizer** | `function` | Function callback passed to lodash `mergeWith` for attribute `locals` and `merge:attribute`. By default it's used to concat array. |

## Features

Expand Down Expand Up @@ -597,6 +598,9 @@ So the prop `size` is not override since we prepend `computed:` to the attribute
And the prop `items` is merged and not override.
You can also notice how the `class` attribute is merged with `class` attribute of the first node. Let's see in next section more about this.

You can change how attributes are merged by passing via options a callback function used by lodash method [mergeWith](https://lodash.com/docs/4.17.15#mergeWith).
By default, it's used to concat array.

### Attributes

Your can pass any attributes to your components and this will be added to the first node of your component, or to the node with an attribute named `attributes`.
Expand Down
2 changes: 1 addition & 1 deletion examples/src/pages/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ <h1 class="display-1 fw-bold mb-4">Build the web with PostHTML</h1>
</div>

<p class="text-muted">
Currently <strong>v1.0.0-beta.6</strong>
Currently <strong>v1.0.0-beta.7</strong>
<span class="px-1">·</span>
<a href="#" class="link-secondary" data-bs-toggle="modal" data-bs-target="#modalWithComponents">Changelog</a>
</p>
Expand Down
5 changes: 3 additions & 2 deletions package-lock.json

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

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "posthtml-component",
"version": "1.0.0-beta.6",
"version": "1.0.0-beta.7",
"description": "PostHTML Components Blade-like with slots, attributes as props and custom tag",
"license": "MIT",
"repository": "thewebartisan7/posthtml-components",
"author": "Damir Grgic <[email protected]> (https://github.com/thewebartisan7)",
"main": "src",
"engines": {
"node": ">=12"
"node": ">=10"
},
"scripts": {
"version": "conventional-changelog -i changelog.md -s -r 0 && git add changelog.md",
Expand All @@ -23,7 +23,6 @@
"html"
],
"dependencies": {
"deepmerge": "^4.2.2",
"lodash": "^4.17.21",
"posthtml-attrs-parser": "^0.1.1",
"posthtml-expressions": "^1.9.0",
Expand Down
Loading

0 comments on commit 36db959

Please sign in to comment.