Git Product home page Git Product logo

cycle-mouse-driver's Introduction

Deprecated

Cycle DOM now supports selecting on document and body, so this driver is unnecessary.

A driver for Cycle.js to help you deal with mouse events in your application

Installation

$ npm install cycle-mouse-driver --save

Cycle Mouse Driver is stream library agnostic. You should be able to use it with RxJs, xstream, or whatever you like. Please open an issue if you have any troubles, and note which stream library you are using.

Usage

  • Install Cycle Mouse Driver with npm (see above)

  • Import the driver

import {makeMouseDriver} from 'cycle-mouse-driver';
  • Initialise the driver by calling makeMouseDriver() in your drivers object
const drivers = {
  Mouse: makeMouseDriver()
}
  • Add it to your main function's sources
function main({Mouse}) { /* Your amazing main function */ }

Methods

  • up(): returns a stream of mouseup events

  • down(): returns a stream of mousedown events

  • click(): returns a stream of click events

  • positions(): returns a stream of all mousemove events as a vector with an x and a y position.

const mousePosition$ = Mouse.positions();
const mouseUp$ = Mouse.up();

Example

Try this example online

import {run} from '@cycle/xstream-run';
import {makeDOMDriver, div, h1, h3} from '@cycle/dom';
import {makeMouseDriver} from 'cycle-mouse-position'
import xs from 'xstream';

export default function main({DOM, Mouse}){
  const mousePosition$ = Mouse.positions();

  return {
    DOM: mousePosition$.map(pos =>
      div(
        '.container', [
          h1('Where\'s my mouse at? ๐Ÿญ'),
          h3(`X: ${pos.x}, Y: ${pos.y}`)
        ]
      )
    )
  }
}

const drivers = {
  DOM: makeDOMDriver('.app'),
  Mouse: makeMouseDriver()
};

run(app, drivers);

We would love to hear from you if you have ideas for features we haven't implemented yet, feedback on the API and documentation, or would like to contribute. Feel free to write your ideas here, or open an issue. Thanks!

cycle-mouse-driver's People

Contributors

raquelxmoss avatar vladimirbuskin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

urkr

cycle-mouse-driver's Issues

Ideas and Feedback

Users, contributors, collaborators, please let us know your thoughts this driver! We would love feedback about the api, ideas for features we haven't implemented yet, or any compliments you'd like to send our way ๐Ÿ˜‰

Thanks for using Cycle Mouse Driver, and for taking the time to give feedback, it's appreciated!

Add TypeScript support

Would help people writing cycle.js apps with TypeScript (like me).
I could take this up.

Deprecate this driver

Hey folks. Here's the good news: Cycle DOM now supports selecting document and body. Awesome! Users can now do things like:

DOM.select('document').events('mouseup');

Since this is now supported, we don't need to use a driver to do this.

What shall we do with Cycle Mouse Driver? Keep it, or deprecate it?

My preference would be to deprecate it, and encourage users to go ahead and use the new DOM feature.

Does anyone see a reason not to deprecate this driver?

Is cycle-mouse taken?

cycle-mouse sounds better than cycle-mouse-driver to me, and is also in line with other drivers like cycle dom and cycle http :)

Your thoughts, please?

Become a mouse driver instead

It would be great to have streams for mouseup, mousedown and click for the whole document. It can be useful in some components who want to know about mouse events in the outside world.

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.