@domql/utils 2.0.7 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/object.js +21 -8
  2. package/package.json +3 -3
package/object.js CHANGED
@@ -1,8 +1,8 @@
1
1
  'use strict'
2
2
 
3
- import { TAGS } from '@domql/registry'
3
+ import { HTML_TAGS } from '@domql/tags'
4
4
 
5
- export const isValidHtmlTag = arg => TAGS.body.indexOf(arg)
5
+ export const isValidHtmlTag = arg => HTML_TAGS.body.indexOf(arg)
6
6
 
7
7
  export const isObject = arg => {
8
8
  if (arg === null) return false
@@ -119,6 +119,7 @@ export const deepClone = (obj, excluding = ['parent', 'node', '__element', '__ro
119
119
  * Overwrites object properties with another
120
120
  */
121
121
  export const overwrite = (element, params, options) => {
122
+ const { ref } = element
122
123
  const changes = {}
123
124
 
124
125
  for (const e in params) {
@@ -128,22 +129,34 @@ export const overwrite = (element, params, options) => {
128
129
  const paramsProp = params[e]
129
130
 
130
131
  if (paramsProp) {
131
- element.__cached[e] = changes[e] = elementProp
132
- element[e] = paramsProp
132
+ ref.__cache[e] = changes[e] = elementProp
133
+ ref[e] = paramsProp
133
134
  }
134
-
135
- if (options.cleanExec) delete element.__exec[e]
136
135
  }
137
136
 
138
137
  return changes
139
138
  }
140
139
 
140
+ export const diff = (obj, original, cache) => {
141
+ const changes = cache || {}
142
+ for (const e in obj) {
143
+ const originalProp = original[e]
144
+ const objProp = obj[e]
145
+ if (isObjectLike(originalProp) && isObjectLike(objProp)) {
146
+ changes[e] = {}
147
+ diff(originalProp, objProp, changes[e])
148
+ } else if (originalProp !== undefined) {
149
+ changes[e] = objProp
150
+ }
151
+ }
152
+ return changes
153
+ }
154
+
141
155
  /**
142
156
  * Overwrites DEEPly object properties with another
143
157
  */
144
- export const overwriteDeep = (obj, params, excluding = ['node', '__root']) => {
158
+ export const overwriteDeep = (params, obj) => {
145
159
  for (const e in params) {
146
- if (excluding.indexOf(e) > -1) continue
147
160
  const objProp = obj[e]
148
161
  const paramsProp = params[e]
149
162
  if (isObjectLike(objProp) && isObjectLike(paramsProp)) {
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@domql/utils",
3
- "version": "2.0.7",
3
+ "version": "2.2.0",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "dependencies": {
7
- "@domql/registry": "^2.0.7"
7
+ "@domql/tags": "latest"
8
8
  },
9
- "gitHead": "6d9ef59d4aa1f481159f8fdbe38112479e86e21a",
9
+ "gitHead": "ec7e77cec088dafc6b4a5d2893f72e3590a6761e",
10
10
  "source": "index.js"
11
11
  }