Skip to content

Instantly share code, notes, and snippets.

View mikebridge's full-sized avatar
🤔
Thinking

Mike Bridge mikebridge

🤔
Thinking
View GitHub Profile
@mikebridge
mikebridge / homepage.tsx
Created September 12, 2017 21:00
Sharing Typescript example....
import * as React from "react";
import * as ReactRedux from "react-redux";
interface ICity {
cityName: string;
img: string;
}
// Action Creator
export const getCityInformation = () => ({
@mikebridge
mikebridge / mouseOverComponent.tsx
Created June 26, 2017 03:42
listen to react mouseover events with rxjs
class MouseOverComponent extends React.Component {
componentDidMount() {
this.mouseMove$ = Rx.Observable.fromEvent(this.mouseDiv, "mousemove")
.throttleTime(1000)
.subscribe(() => console.log("throttled mouse move"));
}
componentWillUnmount() {
this.mouseMove$.unsubscribe();
@mikebridge
mikebridge / EventAggregatorTests.cs
Created June 7, 2017 19:39
xUnit tests for EventAggregator.cs
using System;
using System.Collections.Generic;
using Xunit;
// Tests for EventAggregator.cs (https://gist.github.com/mikebridge/f6799ebed20160f72a3daf62f584d2ff)
namespace Messaging.Tests.Unit
{
public class EventAggregatorTests : IDisposable
{
@mikebridge
mikebridge / EventAggregator.cs
Last active March 10, 2021 02:28
A simple Event Aggregator that allows multiple subscribers per message type.
using System;
using System.Reactive.Linq;
using System.Reactive.Subjects;
// inspired by https://github.com/shiftkey/Reactive.EventAggregator/blob/master/src/Reactive.EventAggregator/EventAggregator.cs
namespace Messaging
{
public interface IEventAggregator : IDisposable
{
@mikebridge
mikebridge / reduxTemplate.test.tsx
Last active May 17, 2017 21:15
An Intellij Live template to generate a Redux component test.
//
// A TypeScript template for generating a Redux Test in IntelliJ.
// (accompanies https://gist.github.com/mikebridge/c75835cda361c5967de301995894bf30)
//
// Create: Settings -> Editor => Live Templates -> Add.
// - give it an abbreviation (e.g. "reduxtest") and a Description, and
// - Make it available in JavaScript "JSX HTML", JavaScript "Statement" and TypeScript
//
// Usage: create a file, e.g. "myTemplate.test.tsx", then type "Ctrl-J", and the abbreviation, e.g. "reduxtest".
//
@mikebridge
mikebridge / reduxTemplate.tsx
Last active September 12, 2017 16:20
A redux component template for intellij
//
// A TypeScript template for generating a Redux Component in IntelliJ.
//
// Create: Settings -> Editor => Live Templates -> Add.
// - give it an abbreviation (e.g. "redux") and a Description, and
// - set FILENAME_PASCAL to capitalize(fileNameWithoutExtension()) in "Edit Variables"
// - Make it available in JavaScript "JSX HTML", JavaScript "Statement" and TypeScript
//
// Usage: create a file, e.g. "myTemplate.tsx", then type "Ctrl-J", and the abbreviation, e.g. "redux".
//
import * as React from "react";
import {shallow, mount} from "enzyme";
import withQueryString from "./withQueryString";
import {IQueryStringProps} from "./withQueryString";
import {MemoryRouter} from "react-router";
interface ITestComponentOwnProps {}
class TestComponent extends React.Component<IQueryStringProps & ITestComponentOwnProps, {}> {
@mikebridge
mikebridge / withQueryString.tsx
Created May 16, 2017 19:17
query string HOC for react-router 4
import * as React from "react";
type HOCWrapped<PWrapped, PHoc> = React.ComponentClass<PWrapped & PHoc> | React.SFC<PWrapped & PHoc>;
const queryString = require("query-string");
import {RouteComponentProps, withRouter} from "react-router";
export interface IQueryStringProps {
params: any;
@mikebridge
mikebridge / package.json
Created May 15, 2017 21:53
JSON to add to package.json to enable Jest/Typescript debugging in IntelliJ
{
"jest": {
"transform": {
"^.+\\.css$": "react-scripts-ts/config/jest/cssTransform.js",
".(ts|tsx)": "react-scripts-ts/config/jest/typescriptTransform.js",
"^(?!.*\\.(css|json)$)": "react-scripts-ts/config/jest/fileTransform.js"
},
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
"moduleFileExtensions": [
"ts",
@mikebridge
mikebridge / welcome3.tsx
Created May 5, 2017 02:25
TypeScript control with stacked HOCs
import * as React from "react";
import {IWithPersonalizationProps, withPersonalization} from "./withPersonalization2";
import {IWithNavigationProps, withNavigation} from "./withNavigation";
// This empty declaration is required
interface IWelcomeOwnProps {}
type IWelcomeProps = IWelcomeOwnProps & IWithNavigationProps & IWithPersonalizationProps;
class Welcome extends React.Component<IWelcomeProps, {}> {