Skip to content

Instantly share code, notes, and snippets.

View scq000's full-sized avatar

Chason scq000

  • Bytedance
  • Shenzhen
View GitHub Profile
@learncodeacademy
learncodeacademy / pubsub.js
Created July 29, 2015 02:54
Basic Javascript PubSub Pattern
//events - a super-basic Javascript (publish subscribe) pattern
var events = {
events: {},
on: function (eventName, fn) {
this.events[eventName] = this.events[eventName] || [];
this.events[eventName].push(fn);
},
off: function(eventName, fn) {
if (this.events[eventName]) {
@mikkel
mikkel / svgImage.js
Last active September 12, 2019 05:16
Import an SVG file into your DOM with React and ES6. Useful for manipulating internal path elements. Only use trusted sources.
var React = require('react');
class SvgImage extends React.Component {
constructor(props) {
super(props);
this.state = {};
}
componentDidMount() {
$.get(this.props.url, (svg) => {
this.setState({icon: svg.documentElement.outerHTML});
});