Skip to content

Commit

Permalink
feat(conclude): add option options.mergeObjectCustomizer
Browse files Browse the repository at this point in the history
  • Loading branch information
cloydlau committed Sep 10, 2024
1 parent 7b23d9f commit ebe5149
Show file tree
Hide file tree
Showing 15 changed files with 2,724 additions and 2,241 deletions.
23 changes: 11 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,7 @@ npm i vue-global-config
}
</script>
<script type="module">
import {
conclude,
getLocalListeners,
listenGlobalHooks,
resolveConfig,
} from 'vue-global-config'
import { conclude, getLocalListeners, listenGlobalHooks, resolveConfig } from 'vue-global-config'
</script>
```

Expand All @@ -170,8 +165,7 @@ npm i vue-global-config
```html
<script src="https://cdn.jsdelivr.net/npm/vue-global-config@0.6"></script>
<script>
const { conclude, getLocalListeners, listenGlobalHooks, resolveConfig } =
VueGlobalConfig
const { conclude, getLocalListeners, listenGlobalHooks, resolveConfig } = VueGlobalConfig
</script>
```

Expand Down Expand Up @@ -264,10 +258,11 @@ The role of `conclude` is to help you figure out the final configuration.
* @param {boolean} [options.defaultIsDynamic = false] - Dynamic generation of default values
* @param {boolean} [options.required = false] - Requirement checking
* @param {(prop: any) => boolean} [options.validator] - Custom validator
* @param {string} [options.camelizeObjectKeys = false] - whether to camelize object keys
* @param {string} [options.camelizeObjectKeys = false] - Whether to camelize object keys
* @param {false|string} [options.mergeObject = 'deep'] - The way to merge objects
* @param {(objValue: any, srcValue: any, key: string, object: Record<string, any>, source: Record<string, any>, stack: object) => any} [options.mergeObjectCustomizer] - To produce the merged values of the destination and source properties. Returning undefined to maintain the default behavior
* @param {boolean} [options.mergeObjectApplyOnlyToDefault = false] - `mergeObject` only works on `default`
* @param {false|((accumulator, currentValue, index?, array?) => )} [options.mergeFunction = false] - The way to fuse functions
* @param {false|((accumulator, currentValue, currentIndex?, array?) => )} [options.mergeFunction = false] - The way to merge functions
* @param {boolean} [options.mergeFunctionApplyOnlyToDefault = true] - `mergeFunction` only works on `default`
* @returns {any} Final prop
*/
Expand Down Expand Up @@ -295,6 +290,10 @@ Same as [Vue's prop validation](https://vuejs.org/guide/components/props.html#pr
- `'shallow'`: Shallow merge, where the object key of a high weight prop overwrites the key of the same name of a low weight prop, without nested objects
- `false`: No merging, direct overwriting, objects of high weight prop will directly overwrite objects of low weight prop, consistent with the behavior of value types

#### config.mergeObjectCustomizer

The `customizer` argument of [mergeWith](https://lodash.com/docs#mergeWith) (`mergeObject: 'deep'`) or [assignInWith](https://lodash.com/docs#assignInWith) (`mergeObject: 'shallow'`) for customizing assigned values.

#### config.mergeObjectApplyOnlyToDefault

Off by default, only valid when mergeObject is on.
Expand Down Expand Up @@ -342,9 +341,9 @@ conclude([
default: () => {
console.log('I am default option')
},
mergeFunction: (accumulator, item) => (...args) => {
mergeFunction: (accumulator, currentValue) => (...args) => {
accumulator(...args)
item?.(...args)
currentValue?.(...args)
},
mergeFunctionApplyOnlyToDefault: false,
})()
Expand Down
6 changes: 4 additions & 2 deletions commitlint.config.ts → commitlint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// Default Config See https://github.com/conventional-changelog/commitlint/tree/master/@commitlint/config-conventional
import { rules } from '@commitlint/config-conventional'
import config from '@commitlint/config-conventional'

const { rules } = config

// See https://github.com/vuejs/core/blob/main/scripts/verifyCommit.js
rules['type-enum'][2].push('wip', 'types', 'release', 'workflow', 'dx')
rules['header-max-length'][2] = 200
rules['header-max-length'][2] = 300
rules['subject-case'][0] = 0

export default {
Expand Down
5 changes: 3 additions & 2 deletions demo/vue2.6/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import Vue from 'vue'
import VueCompositionAPI from '@vue/composition-api'
import 'element-ui/lib/theme-chalk/index.css'
import ElementUI from 'element-ui'
import { FaFormDialog, FaImage, FaImageUpload, FaPopButton, FaPopSwitch, FaSelect } from 'faim'
import Vue from 'vue'
import App from './App.vue'
import YourComponent from './YourComponent.vue'
import 'element-ui/lib/theme-chalk/index.css'

Vue.use(VueCompositionAPI)
Vue.use(ElementUI)
Vue.use(FaFormDialog, {
// 全局配置
width: `${window.outerWidth / 2}px`,
})
Vue.use(FaImage, {
// 全局配置
Expand Down
4 changes: 2 additions & 2 deletions demo/vue2.7/YourComponent/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Plugin, install } from 'vue-demi'
import type { install, Plugin } from 'vue-demi'
import { resolveConfig } from '../../../src'
import Component from './Component.vue'

Expand Down Expand Up @@ -37,5 +37,5 @@ ComponentWithInstall.install = (app: any, options = {}) => {
app.component(ComponentWithInstall.name, ComponentWithInstall)
}

export { globalProps, globalAttrs, globalListeners, globalHooks, globalSlots }
export { globalAttrs, globalHooks, globalListeners, globalProps, globalSlots }
export default ComponentWithInstall
5 changes: 3 additions & 2 deletions demo/vue2.7/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import Vue from 'vue'
import 'element-ui/lib/theme-chalk/index.css'
import ElementUI from 'element-ui'
import { FaFormDialog, FaImage, FaImageUpload, FaPopButton, FaPopSwitch, FaSelect } from 'faim'
import Vue from 'vue'
import App from './App.vue'
import YourComponent from './YourComponent'
import 'element-ui/lib/theme-chalk/index.css'

Vue.use(ElementUI)
Vue.use(FaFormDialog, {
// 全局配置
width: `${window.outerWidth / 2}px`,
})
Vue.use(FaImage, {
// 全局配置
Expand Down
4 changes: 2 additions & 2 deletions demo/vue3/YourComponent/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Plugin, install } from 'vue-demi'
import type { install, Plugin } from 'vue-demi'
import { resolveConfig } from '../../../src'
import Component from './Component.vue'

Expand Down Expand Up @@ -37,5 +37,5 @@ ComponentWithInstall.install = (app: any, options = {}) => {
app.component(ComponentWithInstall.name, ComponentWithInstall)
}

export { globalProps, globalAttrs, globalListeners, globalHooks, globalSlots }
export { globalAttrs, globalHooks, globalListeners, globalProps, globalSlots }
export default ComponentWithInstall
7 changes: 4 additions & 3 deletions demo/vue3/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { createApp, h } from 'vue'
import 'element-plus/dist/index.css'
import ElementPlus from 'element-plus'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import ElementPlus from 'element-plus'
import { FaFormDialog, FaImage, FaImageUpload, FaPopButton, FaPopSwitch, FaSelect } from 'faim'
import { createApp } from 'vue'
import App from './App.vue'
import YourComponent from './YourComponent'
import 'element-plus/dist/index.css'

const app = createApp(App)
.use(ElementPlus)
.use(FaFormDialog, {
// 全局配置
width: `${window.outerWidth / 2}px`,
})
.use(FaImage, {
// 全局配置
Expand Down
File renamed without changes.
55 changes: 28 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@
"scripts": {
"dev": "esno ./scripts/dev.mts",
"doc": "vitepress dev --open /README",
"test-unit": "vitest run",
"test": "vitest run",
"test:watch": "vitest",
"test:coverage": "vitest run --coverage",
"test:ui": "vitest --ui",
"build": "vite build",
"serve": "vite preview",
"release": "esno ./scripts/release.mts",
Expand All @@ -64,46 +67,44 @@
}
},
"dependencies": {
"vue-demi": "^0.14.7"
"vue-demi": "^0.14.10"
},
"devDependencies": {
"@antfu/eslint-config": "^2.15.0",
"@commitlint/cli": "^19.3.0",
"@commitlint/config-conventional": "^19.2.2",
"@element-plus/icons-vue": "^2.3.1",
"@antfu/eslint-config": "^3.5.0",
"@commitlint/cli": "^19.4.1",
"@commitlint/config-conventional": "^19.4.1",
"@element-plus/icons-vue": "latest",
"@types/lodash-es": "^4.17.12",
"@types/node": "^20.12.7",
"@vitejs/plugin-vue": "^5.0.4",
"@vue/compiler-sfc": "^3.4.25",
"@vue/test-utils": "^2.4.5",
"case-police": "^0.6.1",
"@types/node": "^22.5.4",
"@vitejs/plugin-vue": "latest",
"@vue/compiler-sfc": "latest",
"@vue/test-utils": "latest",
"case-police": "^0.7.0",
"change-case": "^5.4.4",
"cross-spawn": "^7.0.3",
"del": "^7.1.0",
"element-plus": "^2.7.1",
"eslint": "npm:eslint-ts-patch@8.57.0-0",
"eslint-plugin-format": "^0.1.1",
"eslint-ts-patch": "8.57.0-0",
"element-plus": "latest",
"eslint-plugin-format": "^0.1.2",
"esno": "^4.7.0",
"faim": "^0.8.1",
"faim": "^0.9.5",
"kolorist": "^1.8.0",
"lint-staged": "^15.2.2",
"lint-staged": "^15.2.10",
"lodash-es": "^4.17.21",
"magicast": "^0.3.4",
"magicast": "^0.3.5",
"only-allow": "^1.2.1",
"open": "^10.1.0",
"prompts": "^2.4.2",
"rollup-plugin-visualizer": "^5.12.0",
"semver": "^7.6.0",
"semver": "^7.6.3",
"simple-git-hooks": "^2.11.1",
"typescript": "^5.4.5",
"unplugin-auto-import": "^0.17.5",
"unplugin-vue-components": "^0.26.0",
"vite": "^5.2.10",
"vite-plugin-dts": "^3.9.0",
"vitepress": "^1.1.3",
"vitest": "^1.5.2",
"vue": "^3.4.25",
"typescript": "^5.6.2",
"unplugin-auto-import": "^0.18.2",
"unplugin-vue-components": "^0.27.4",
"vite": "^5.4.3",
"vite-plugin-dts": "^4.2.1",
"vitepress": "^1.3.4",
"vitest": "^2.0.5",
"vue": "latest",
"vue-global-config": "workspace:*"
},
"simple-git-hooks": {
Expand Down
Loading

0 comments on commit ebe5149

Please sign in to comment.