Git Product home page Git Product logo

composition's Introduction

Hi there 👋

Anurag's GitHub stats

composition's People

Contributors

currypaste avatar duex-long avatar github-beijixin avatar givemehappiness avatar gthdweb avatar phpjavac avatar yinzhenyu-su avatar zhaoiii avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

composition's Issues

[feat]: useEffect 无副作用的执行某个函数

使用场景

某些函数需要手动清除副作用
eg: setInterval、setTimeout、addEventListener...
这些函数在组件销毁后,需要手动在 destroy或onUnmounted钩子中清除副作用

使用useEffect时,就可以只在一个函数中直接处理这些副作用,而不需要再手动调用组件销毁钩子
eg:

// 需要处理副效应
useEffect(()=>{
    const i = setInterval(()=>{
        console.log('this is interval, when Unmounted I`m destroy');
    }, 2000);
    return () => {
        clearInterval(i);
    }
})
// 不需要处理副效应
useEffect(()=>{
    const ii = setInterval(()=>{
        console.log('I`m interavl, but always')
    }, 2000)
})

类型

新钩子 (之前没有,新加的功能)

参数、回调或其他补充

参考了React的useEffect方法

两个关键点

  • 可以选择性的执行一个无副作用的函数
    • 如果不 return 则表示不需要清除副作用
  • 调用函数的机制
    • 初始调用
    • 当依赖项的值发生了变化时,也去触发对应的函数

用vue实现该钩子,初版先能够实现第一个关键点: 能够无副作用的执行一个函数

Interface

type UseEffectVoid = () => void; // 不需要处理副效应
type UseEffectFunVoid = () => () => void; // 需要处理副效应

Option

参数 说明 类型 默认值
method 需要执行的函数(如果需要清除副效应,则在要执行的函数中return一个函数,并在函数中清除副效应) UseEffectVoid / UseEffectFunVoid -

[feat]: 打包

使用场景

新特性使用场景

类型

新钩子 (之前没有,新加的功能)

参数、回调或其他补充

esbuild打包

[feat]: useKeyPress 监听键盘事件

使用场景

当需要监听键盘,并触发某些代码的时候调用

类型

新钩子 (之前没有,新加的功能)

参数、回调或其他补充

// 键码
type KeyType = KeyboardEvent['key'] | KeyboardEvent['key'][];
// 触发类型
type keyEvent = 'keydown' | 'keyup' | 'keypress';
// 执行的函数类型
type EventMethod = (event?: KeyboardEvent) => void;
// option选项
interface EventOption {
    events?: Array<keyEvent>,
}
参数 说明 类型 默认值
keyCode 要监听的key/是否全部监听 KeyType / true -
method 要执行的方法 EventMethod -
option 配置项 EventOption {event: ['keydown']}

[feat]: nav增加查询功能

使用场景

  • 文档右上角增加内容搜索功能
  • 增加 github 跳转链接

类型

新功能 (在原有的功能上拓展新功能)

参数、回调或其他补充

暂时为本地索引,待@vuepress/plugin-docsearch@next 通过后,替换为docsearch🤔

[feat]: vite按需引入

使用场景

新特性使用场景

类型

新功能 (在原有的功能上拓展新功能)

参数、回调或其他补充

1

[feat]: 更方便的使用事件总线(Event Bus)

使用场景

新特性使用场景
跨组件传递消息

类型

新钩子 (之前没有,新加的功能)

参数、回调或其他补充

const bus = useBus() 
or
const { emit , on } = useBus()

bus.emit('',value) 
or 
emit('',value)


bus.on('',(value)=>void) 
or 
on('',(value)=>void)

[feat]: 添加useAnimation

使用场景

新特性使用场景

类型

新钩子 (之前没有,新加的功能)

参数、回调或其他补充

添加useAnimation

[feat]: useEffect增加第二个参数

使用场景

目前useEffect可以满足

  • 立即执行某个函数 fun
  • 如果函数 fun 有返回值,则在页面销毁时清除其副作用

新特性

  • 传入第二个参数 arr 数组
  • 当数组 arr 中的变量发生变化,再次执行函数 fun

已用 vue 还原 react 的useEffect方法

类型

新功能 (在原有的功能上拓展新功能)

参数、回调或其他补充

第二个参数 arr 数组

const refData = ref(1)
const reactiveData = reactive({a: 1})
// 需要监听变量并重新执行函数
useEffect(()=>{
    console.log('需要监听变量并重新执行函数', refData.value, reactiveData.a)
}, [refData, reactiveData])

[feat]: add useTitle

使用场景

import { useTitle } from 'zcomposition'

const title = useTitle()
console.log(title.value) // print current title
title.value = 'Hello' // change current title

类型

新钩子 (之前没有,新加的功能)

参数、回调或其他补充

import { useTitle } from 'zcomposition'

const messages = ref(0)

const title = computed(() => {
return !messages.value ? 'No message' : ${messages.value} new messages
})

useTitle(title)

[Bug]: 修改错误

bug描述

bug描述 不小心删除文件 直接注释该文件的引用

版本号

0.0.1 (Default)

在哪些浏览器上看到这个问题?

Chrome

相关日志输出

No response

Contact Details

No response

[feat]: useWebSocket

使用场景

新特性使用场景
创建ws链接,并自带断线重连

类型

新钩子 (之前没有,新加的功能)

参数、回调或其他补充

入参:ws配置项
返回值:ws的各种回调(error、message...)

[feat]: :docs: 增加二级目录

使用场景

  • 增加分类目录
  • 修复点击链接,左菜单未激活

类型

新功能 (在原有的功能上拓展新功能)

参数、回调或其他补充

[feat]: 大于某个时间执行函数

使用场景

新特性使用场景
�页面加载时,设置了apiLoading,如果网速快,loading就会很快关闭。
设置一个最小时间,如果要执行的函数 funAsync 的执行时间小于设定时间 time 则等待执行时间满足 time 时,再去执行函数 funThen (当funAsync执行完毕后要执行的函数)

类型

新钩子 (之前没有,新加的功能)

参数、回调或其他补充

参数

  funAsync: () => void, // 想要执行的异步函数 比如api请求
  time: number, // 最小时间
  funThen: () => void, // 满足最小时间后,要执行的函数 比如设置loading状态

[Bug]: useTitle打包异常

bug描述

构建失败

版本号

0.0.1 (Default)

在哪些浏览器上看到这个问题?

Firefox, Chrome, Safari, Microsoft Edge

相关日志输出

No response

Contact Details

No response

[feat]: 元素是否在浏览器视图内

使用场景

新特性使用场景
元素出现或消失在浏览器视图内触发

类型

新钩子 (之前没有,新加的功能)

参数、回调或其他补充

参数 targetDom (Ref<HTMLElement | null>)
const finalResult = useObserver(targetDom);

[Bug]:修复bug

bug描述

useHover事情触发失败
useAwaitDom模块导入失败
usePermission模块导入失败
useClipboard模块导入失败
useTitle模块导入失败

版本号

0.0.1 (Default)

在哪些浏览器上看到这个问题?

Chrome

相关日志输出

No response

Contact Details

[email protected]

[feat]: useFocus

使用场景

实现鼠标聚焦触发事件,失焦触发事件

类型

新钩子 (之前没有,新加的功能)

参数、回调或其他补充

入参:需要使用的节点dom, 回调函数
回调:聚焦/失焦时触发
异常:可能出现dom挂载问题(解决)

[feat]: useAwaitDom

使用场景

新特性使用场景

等待一个dom或 ref 出现然后执行回调

可用于搭建引导系统

类型

新功能 (在原有的功能上拓展新功能)

参数、回调或其他补充

interface IUseAwaitDomOptions {
  /**
   * dom 获取器
   */
  domSelector: (() => HTMLElement | null) | Ref<HTMLElement | null>
  /**
   * 最大等待时间(单位:ms)
   */
  maxWait?: number
}

[feat]: useGlobalStore

使用场景

新特性使用场景

一个简单的全局单例仓库

类型

新功能 (在原有的功能上拓展新功能)

参数、回调或其他补充

const store = useGlobalStore({ count: 0 })

const store2 = useGlobalStore()

store === store2 // true

[feat]: useDebounceFn & useThrottleFn

使用场景

新特性使用场景[feat]: useDebounceFn & useThrottleFn

类型

新钩子 (之前没有,新加的功能)

参数、回调或其他补充

[feat]: useDebounceFn & useThrottleFn

[feat]: useAsync 新功能

使用场景

新特性使用场景
目前 useAsync 可以更新异步函数的 状态loading数据response

想法 再新增一个可选参数 minTime 最小执行时间

  • useWaitTime类似,给异步函数设置一个最小执行时间
  • 使用场景和和 useWaitTime 相同,控制loading的最小展示时间

不算是解决痛点,只是拓展了功能

类型

新功能 (在原有的功能上拓展新功能)

参数、回调或其他补充

demo 这个例子,只做展示用,所以只处理了loading
export const useWaitAsync = <T>(fun: ()=>Promise<T>, minTime: number) => {
/** 这个函数是为了保证首页不会loading太快 */
  const data = ref< T | undefined>();
  const loading = ref(true);
  const error: {code?: string, message?: string} = {};
  let loadingTemp = true;
  const promise = () => new Promise<void>((reslove, reject) => {
    fun().then((res: T) => {
      // 这里不再直接赋值,而是先暂存
      data.value = res;
      error.code = '0';
      error.message = '';
      //   loading.value = false;
      loadingTemp = false;
      reslove();
    }).catch((err: string) => {
      data.value = undefined;
      error.code = '999999';
      error.message = err;
      //   loading.value = false;
      loadingTemp = false;
      reject();
    });
  });
  useWaitTime(() => promise(), minTime, () => {
    // 满足最小时间后,再进行赋值,保证最小执行时间
    loading.value = loadingTemp;
  });
  return {
    data,
    loading,
    error,
  };
};

[feat]: useObserver新增回调函数

使用场景

新特性使用场景
进入视图/移除视图 需要有回调参数


### 类型

新功能 (在原有的功能上拓展新功能)

### 参数、回调或其他补充

import { useObserver } from 'zcomposition';

const targetDom = ref(null);
const finalResult = useObserver(targetDom,(val)=>{
// 为true则是可视
if(val){
}
},);

[feat]: 添加 commitlint

使用场景

新特性使用场景

类型

新功能 (在原有的功能上拓展新功能)

参数、回调或其他补充

添加 commitlint 支持

[feat]: 元素是否在浏览器视图内

使用场景

新特性使用场景
元素出现或消失在浏览器视图内触发

类型

新钩子 (之前没有,新加的功能)

参数、回调或其他补充

参数 targetDom (Ref<HTMLElement | null>)
const finalResult = useObserver(targetDom);

[Bug]: useSize切换到其他页面会报错

bug描述

useSize切换到其他页面会报错

版本号

0.0.1 (Default)

在哪些浏览器上看到这个问题?

Chrome, Microsoft Edge

相关日志输出

v-db21e3ae.b5c0538d.js:1 Uncaught TypeError: Cannot read properties of null (reading 'clientHeight')
    at ResizeObserver.<anonymous> (v-db21e3ae.b5c0538d.js:1)

Contact Details

No response

[feat]: useAsync

使用场景

新特性使用场景
接受一个异步函数 返回 err,loadging,data

类型

新钩子 (之前没有,新加的功能)

参数、回调或其他补充

promise回调事件

[feat]: 配置eslint 和 lint-staged

使用场景

规范代码风格

类型

新功能 (在原有的功能上拓展新功能)

参数、回调或其他补充

  1. 在 commit 时自动执行 eslint 格式化代码
  2. 可以手动执行 npm run lint:fix 格式化 src 目录下的文件

[feat]: 配置md导入代码文件,修复useEventBus部分问题

使用场景

配置md导入代码文件,修复useEventBus部分问题

类型

新功能 (在原有的功能上拓展新功能)

参数、回调或其他补充

  1. 可以在 md 中使用 @[code](@/src/index.ts) 导入代码文件内容
  2. 修复 useEventBus 部分问题,更新 useEventBus 文档
  3. 更新 tsconfig
  4. 添加 NpmBadage 组件

[feat]: chore: vuePress-import别名替换

使用场景

import { useDownloader } from "zcomposition";
替换为
import { useDownloader } from "@lib";

类型

新功能 (在原有的功能上拓展新功能)

参数、回调或其他补充

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.