Created
May 1, 2016 23:20
-
-
Save postspectacular/9de41cb7d9d6c4f264715b7d2fc966c0 to your computer and use it in GitHub Desktop.
Reagent canvas component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns canvas | |
(:require | |
[thi.ng.geom.gl.webgl.animator :as anim] | |
[reagent.core :as reagent])) | |
(defn canvas-component | |
[props] | |
(reagent/create-class | |
{:component-did-mount | |
(fn [this] | |
(reagent/set-state this {:active true}) | |
((:init props) this) | |
(anim/animate ((:loop props) this))) | |
:component-will-unmount | |
(fn [this] | |
(reagent/set-state this {:active false})) | |
:reagent-render | |
(fn [_] | |
[:canvas | |
(merge | |
{:width (.-innerWidth js/window) | |
:height (.-innerHeight js/window)} | |
props)])})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment