Code Monkey home page Code Monkey logo

vue-adaptive-utils's Introduction

vue-adaptive-utils

Deliver empathetic experiences to your users by adapting to their capabilities

codecov Build Status Codacy Badge npm npm Average time to resolve an issue Percentage of issues still open


What is this

Inspired by react-adaptive-hooks, and a continuation of my work in vue-use-web.

This is a collection of Vue 3.0 composition API functions and utilties to allow your apps to adapt your user's:

  • Network conditions.
  • Battery Status.
  • CPU Cores.
  • Device Memory.

I have iterated on this idea multiple times, once in my article: Resource-Adaptive Vue Apps which discussed this idea prior to the introduction of the composition API, I have enhanced the idea even more in my work in vue-use-web.

With the Vue 3.0 composition API introduction, this is a perfect way to consume such functionalities into your components. This library is aimed to Vue 3.0 and already working with the Alpha releases.

Why

This is not "yet another web APIs wrappers for Vue's upcoming composition API", this project aims to focus on only the APIs that allow you to tailor your website experience based on various factors like network status, device memory and more. It allows you to build "adaptive" vue applications that are aware of your users devices limitation and to be more empathetic towards them.

This library aims to bring value with those composition functions, not only mirroring the native web APIs that's underneath.

Install

yarn add vue-adaptive-utils

# or

npm i vue-adaptive-utils --save

Usage

Import the composition function(s) that you will use:

import { useNetworkStatus } from 'vue-adaptive-utils';
import { useBattery } from 'vue-adaptive-utils';
import { useHardwareConcurrency } from 'vue-adaptive-utils';
import { useMemoryStatus } from 'vue-adaptive-utils';

All of the composition functions return an isSupported boolean ref to indicate if the API is supported or not.

⚠ All the values exposed are read only and cannot be mutated.

Network Status

This is a compounded API, meaning it collects various information from multiple APIs, them being the Connection API and online/offline events.

Partial Compatibility: The isSupported flag here refers to the availability of the Connection API, the isOnline and offlineAt properties should be available in all browsers.

import { useNetworkStatus } from 'vue-adaptive-utils';

const {
  isOnline,
  saveData,
  offlineAt,
  downlink,
  downlinkMax,
  effectiveConnectionType,
  networkType,
  isSupported
} = useNetworkStatus();

Battery Status

This is an experimental API and is only available on Chrome at the moment.

import { useBattery } from 'vue-adaptive-utils';

const { charging, chargingTime, dischargingTime, level, isSupported } = useBattery();

Hardware Concurrency (CPU Cores)

import { useHardwareConcurrency } from 'vue-adaptive-utils';

const { concurrency, isSupported } = useHardwareConcurrency();

Memory Status

This is a compounded API, meaning it collects various information from multiple APIs, mainly the navigator.deviceMemory and navigator.performance.

import { useHardwareConcurrency } from 'vue-adaptive-utils';

const { deviceMemory, totalJSHeapSize, usedJSHeapSize, jsHeapSizeLimit, isSupported } = useMemoryStatus();

Browser Support

  • Battery API is only available on Chrome.
  • Connection API is available on Chrome 61+ and Firefox.
  • Device Memory is available on Chrome 63+.
  • Performance memory API is a non-standard and only available in Chrome 7+, Opera, Chrome for Android 18+, Opera for Android.

πŸ“š Documentation

You can find the docs here.

πŸ“œ License

Licensed under the MIT license.

vue-adaptive-utils's People

Contributors

dependabot[bot] avatar logaretm avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

Forkers

yuttasakcom

vue-adaptive-utils's Issues

Setup a VuePress doc site

Should add Vuepress documentation containing the details of each API and their caveats, probably also demos created by #4

Consistent "is" prefix for booleans

Hey πŸ‘‹

First of all, thanks for the library ☺️

One thing that I noticed when checking out the README is that booleans are often prefixed with an "is" (e.g. isOnline) which is a great way to have readable flags/booleans. Unfortunately, the unsupported flag does not have that prefix.
Would it be worth to change that before the v1 to keep it consistent? πŸ˜‹

WDYT?

import { useNetworkStatus } from 'vue-adaptive-utils';

const {
  isOnline,
  saveData,
  offlineAt,
  downlink,
  downlinkMax,
  effectiveConnectionType,
  networkType,
  unsupported
} = useNetworkStatus();

Add support for initial values

So far the composition functions try to read the values as soon as possible, but that might cause unexpected issues in-case of unsupported APIs.

Ideally, you should be able to provide initial values for the composition functions, that way you know that even if the API is unsupported, you could still assume certain aspects about the user device. As fallback values.

For example, you can assume that they have 3GB of RAM as long as the API is not supported:

import { useMemoryStatus } from 'vue-adaptive-utils';

useMemoryStatus({ deviceMemory: 3 });

This should be optional, the react-adaptive-hooks libraries already have this mechanism.

An interesting idea is that you can set "performance budgets" per component with this approach, by setting the initial values to what you expect to be.

Add Demos

Some demos should be created to showcase this library's use-cases.

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.