All Projects → YurkaninRyan → React Sentinel

YurkaninRyan / React Sentinel

Licence: mit
React Component that abstracts away requestAnimationFrame, allowing you to set props by monitoring anything in the document!

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Sentinel

Callmon
CallMon is an experimental system call monitoring tool that works on Windows 10 versions 2004+ using PsAltSystemCallHandlers
Stars: ✭ 83 (-12.63%)
Mutual labels:  monitoring
Homer App
HOMER 7.x Front-End and API Server
Stars: ✭ 88 (-7.37%)
Mutual labels:  monitoring
Es Stats
ElasticSearch cluster metrics -> Graphite
Stars: ✭ 91 (-4.21%)
Mutual labels:  monitoring
Sampler
Tool for shell commands execution, visualization and alerting. Configured with a simple YAML file.
Stars: ✭ 9,203 (+9587.37%)
Mutual labels:  monitoring
Influxgraph
Graphite InfluxDB backend. InfluxDB storage finder / plugin for Graphite API.
Stars: ✭ 87 (-8.42%)
Mutual labels:  monitoring
Cronmon
定时任务执行状态监控
Stars: ✭ 90 (-5.26%)
Mutual labels:  monitoring
Beamium
Prometheus to Warp10 metrics forwarder
Stars: ✭ 82 (-13.68%)
Mutual labels:  monitoring
Kubernetes Oom Event Generator
Generate a Kubernetes Event when a Pod's container has been OOMKilled
Stars: ✭ 93 (-2.11%)
Mutual labels:  monitoring
Kamon
Distributed Tracing, Metrics and Context Propagation for application running on the JVM
Stars: ✭ 1,280 (+1247.37%)
Mutual labels:  monitoring
Stackdriver Prometheus Sidecar
A sidecar for the Prometheus server that can send metrics to Stackdriver.
Stars: ✭ 91 (-4.21%)
Mutual labels:  monitoring
Maze
Maze Applied Reinforcement Learning Framework
Stars: ✭ 85 (-10.53%)
Mutual labels:  monitoring
Shynet
Modern, privacy-friendly, and detailed web analytics that works without cookies or JS.
Stars: ✭ 1,273 (+1240%)
Mutual labels:  monitoring
Xsrv
[mirror] Install and manage self-hosted services/applications, on your own server(s) - ansible collection and utilities
Stars: ✭ 89 (-6.32%)
Mutual labels:  monitoring
Chronograf
Open source monitoring and visualization UI for the TICK stack
Stars: ✭ 1,245 (+1210.53%)
Mutual labels:  monitoring
Profiling Nodejs
🌌 Collection of articles and tools to efficiently profile Node.js
Stars: ✭ 93 (-2.11%)
Mutual labels:  monitoring
Wazuh Documentation
Wazuh - Project documentation
Stars: ✭ 82 (-13.68%)
Mutual labels:  monitoring
React Paginating
Simple, lightweight, flexible pagination ReactJS component ⏮⏪1️⃣2️⃣3️⃣⏩⏭
Stars: ✭ 89 (-6.32%)
Mutual labels:  render-props
Kubenurse
Kubernetes network monitoring
Stars: ✭ 94 (-1.05%)
Mutual labels:  monitoring
Ciao
HTTP checks & tests (private & public) monitoring - check the status of your URL
Stars: ✭ 1,322 (+1291.58%)
Mutual labels:  monitoring
Vpndemon
Monitor a VPN connection on Linux and kill a process upon disconnect
Stars: ✭ 90 (-5.26%)
Mutual labels:  monitoring

React Sentinel - 0.2.0


<Sentinel> is a component that abstracts away the recursive looping of requestAnimationFrame and requestIdleCallback to allow developers to efficently observe the dom and make changes to state accordingly.

Take for example the common usecase of element queries. In CSS Media Queries are only so useful because they monitor only the size of the page, but what if you wanted to monitor only an element?

Example

import React, { PureComponent, } from "react";
import Sentinel from "react-sentinel";
import DumbCard from "./DumbCard"

class ResponsiveTextCard extends PureComponent {
  getSize = () => {
    if (this.container.offSetWidth < 450) return { size: "small" }
    if (this.container.offsetWidth < 950) return { size: "medium" }

    return { size: "large" }
  }

  renderCard = ({ size, }) => <DumbCard size={size}>Hello!</DumbCard>
  render() {
    return (
      <div className="centered-and-half-of-page" ref={(el) => this.container = el}>
        <Sentinel observe={this.getSize} render={this.renderCard} />
      <div>
    )
  }
}

In this simple example, you can design a dumb card that takes a size property, and do whatever you want based off what gets passed into it. Then with Sentinel, you can intelligently figure out when that prop needs to be changed!

Props

render - A function that returns JSX. It get's passed in Sentinel's state, which is just whatever object you return in the observe function.

observe - Your chance to update Sentinel's state. Attempts to run once every 15ms. Returning a shallowly equal object doesn't cause a re-render. In here you recieve the previous return value, so you can do incremental updates.

lowPriority - Defaults to false. If set to true it switches from using requestAnimationFrame to using requestIdleCallback. For browsers that don't support requestIdleCallback this is basically a no-op.

initial - Defaults to an empty object. This is what the first value of Sentinel should be.

interval - Defaults to being instant. Determines the time between observe checks. Use this if you don't think you will be updating often and want to increase performance.

Instance Functions

If you want finer control over when the polling should actually be happening, you can use some function exposed on each Sentinel Instance by adding a ref to each one. Once you have the ref, you can use the following functions:

Sentinel.watch - Begins polling
Sentinel.stop - Stops polling

Similar Alternatives

  • eq.js - Designed to solve purely the element query problem. Allows you to set data properties for the sizes, and read from an attribute to see the current size.

  • react-element-query - Designed to solve purely the element query problem. You supply sizes and it allows you to make class names out of them.

  • CSS Element Queries Designed to solve purely the element query problem. Allows you to write element queries directly into your css!

If you know of any other libraries that are similar to this one, feel free to submit a PR!

Contributing

First run yarn to install the project's dependencies. Here are a list of commands for different scenarios.

I want to fix an issue, or add a feature what do I do?

  1. Fork the project!
  2. Make your branch with git flow feature start <NAME_OF_FEATURE>
  3. Spin up the example using yarn develop
  4. When you're all done, run yarn test && yarn lint
  5. Open a PR!
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].