Last active
          July 30, 2021 05:53 
        
      - 
      
- 
        Save wobsoriano/cade0fe86441eaa5a47b7562d94e153e to your computer and use it in GitHub Desktop. 
    Make h function working with Vue 2 and 3
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // https://github.com/vueuse/vue-demi/issues/65 | |
| import { h as hDemi, isVue2 } from 'vue-demi' | |
| interface Options { | |
| props?: Record<any, any>, | |
| domProps?: Record<any, any> | |
| on?: Record<any, any> | |
| } | |
| const adaptOnsV3 = (ons: Object) => { | |
| if (!ons) return null | |
| return Object.entries(ons).reduce((ret, [key, handler]) => { | |
| key = key.charAt(0).toUpperCase() + key.slice(1) | |
| key = `on${key}` | |
| return { ...ret, [key]: handler } | |
| }, {}) | |
| } | |
| const h = (type: String | Record<any, any>, options: Options & any = {}, chidren?: any) => { | |
| if (isVue2) | |
| return hDemi(type, options, chidren) | |
| const { props, domProps, on, ...extraOptions } = options | |
| let ons = adaptOnsV3(on) | |
| const params = { ...extraOptions, ...props, ...domProps, ...ons } | |
| return hDemi(type, params, chidren) | |
| } | |
| export default h | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment