npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@fruits-chain/upload

v1.6.0

Published

A component for upload

Downloads

56

Readme

upload

后台上传公共组件, 相比@fruits-chain/react-native-upload组件, 内部增加了后台上传功能, 用户在上传图片时, 不需要等待上传完成即可退出操作界面, 下次进入该页面时, 本地数据(上传中和上传完成的图片)会自动同步到组件内部

使用

yarn add @fruits-chain/upload
import React, { useEffect } from 'react'
import { useBackUploadManager, init } from '@fruits-chain/upload'

const App = () => {
  // 获取run方法
  const { run } = useBackUploadManager(state => ({
    run: state.run,
  }))

  // 注意: 需要用户决定init和run方法的调用时机, 下面仅作为示例
  useEffect(() => {
    // 初始化上传API, useBackUploadManager内部会执行此回调函数上传文件
    init(async file => {
      return await yourUploadAPI(file)
    })
    // 继续执行未完成的任务
    run()
  }, [run])

  return <YourAppContent />
}

请确保项目安装了上述包中peerDependencies列出的所有三方包,并仔细检查版本。

API

Upload

上传组件, 支持@fruits-chain/react-native-upload上传组件的所有属性配置, 但是目前仅支持作为受控组件使用

使用

import React from 'react'
import Upload from '@fruits-chain/upload'

const Demo = () => {
  return <Upload groupUuid={'所属分组唯一id'} uuid={'当前上传组件的唯一id'} />
}

为什么会有的概念, 主要是方便内部做资源管理, 比如按清除缓存等

uuid 的作用, 组件内部在同步缓存的数据到组件状态时, 需要通过groupUuiduuid对资源进行匹配

init

初始化后台上传, 其参数为执行上传 API 的回调函数

使用

import { init } from '@fruits-chain/upload'

init(async file => {
  return await yourUploadAPI(file)
})

useBackUploadManager

一个zustand store, 内部负责整个后台上传的调度, 也暴露了诸如runsetFinishedTaskclear等方法供外部使用

由于useBackUploadManager是一个React hook, 所以他只能在组件内部使用

run

开始处理未完成的任务

使用

const { run } = useBackUploadManager(state => ({
  run: state.run,
}))

run()

setFinishedTask

清理已完成的任务

使用

const { setFinishedTask } = useBackUploadManager(state => ({
  setFinishedTask: state.setFinishedTask,
}))

// 清除某个组已完成的任务
setFinishedTask(groupUuid)
// 清除某个组下某个上传组件已完成的任务
setFinishedTask(groupUuid, uploadUuid)

clear

清理所有任务

使用

const { clear } = useBackUploadManager(state => ({
  clear: state.clear,
}))

clear()