You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

hyperc

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hyperc

hyperc ===

0.3.0
Source
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

hyperc

State driven high performance canvas graphics framework based on EaselJS and JSON Patch.

Currently, hyperc is in alpha stage, things may change.

Highly inspired from choojs/choo.

Example

const Hyperc = require('hyperc')
const consecutive = require('hyperc/consecutive')
var app = new Hyperc('#stage')

function circleStore(state, emitter) {
  var nextId = consecutive()
  
  // store should add a unique container to state
  // this key will be used to bind renderer
  state.circles = {}

  // adds a new item to store
  // items should be id keyed objects
  // here, provided consecutive helper is used to create sequential ids
  function addItem(item) {
    const id = nextId()
    state.circles[id] = Object.assign({}, item, {id})
  }

  addItem({x: 100, y: 100, radius: 100, color: 'DeepSkyBlue'})

  emitter.on('circle:add', item => {
    addItem(item)
    emitter.emit('render')
  })

  emitter.on('circle:moveItem', ({id, x, y}) => {
    state.circles[id].x = x
    state.circles[id].y = y
    emitter.emit('render')
  })
}

function circlesRenderer(state, emit) {
  return {
    add(container, item) {
      var circle = new createjs.Shape()
      circle.graphics.beginFill(item.color).drawCircle(0, 0, item.radius).endFill()
      circle.id = item.id
      circle.x = item.x
      circle.y = item.y
      container.addChild(circle)

      circle.on('pressmove', e => {
        emit('circle:moveItem', {
          id: e.target.id,
          x: e.stageX,
          y: e.stageY
        })
      })
    },
    replace(container, item) {
      const [circle] = container.children
      circle.x = item.x
      circle.y = item.y
      circle.graphics.clear().beginFill(item.color).drawCircle(0, 0, item.radius).endFill()
    }
  }
}

// add store
app.use(circleStore)

// add renderer with store key to bind it
app.render('circles', circlesRenderer)

FAQs

Package last updated on 28 Nov 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts