A guard that represents a central point of control in your application

Overview

Refraction

Build Status npm version npm downloads Coverage Status Join the chat at https://gitter.im/mbasso/refraction

A guard that represents a central point of control in your application.

Modern javascript applications are often organized into modules, which are awesome but have some problems that we can't avoid. When we are writing an application in this way, we must consider that all our modules must be independent, testable, instantly reusable and secure. Refraction's purpose is to make these concerns take care of themselves by using some design patterns. Since modules might be independent, with no inter-module dependencies, Refraction adds an intermediate layer that handles all messages that an application uses, allowing communication between modules. This way, modules don't need to know each other, only the layer that is responsible for managaging communication. If we want to change a module, we can do so without worrying about how other modules use it. Modules have a very limited knowledge of what's going in the rest of the system. For this reason, we can define refraction as a guard, a central point of control.

Installation

You can install Refraction using npm:

npm install --save refraction

If you aren't using npm in your project, you can include Refraction using UMD build in the dist folder with <script> tag.

Usage

Refraction exposes only a small set of APIs. What is important to know is it's concept. A complete guide about usage can be found here. However, here is the gist:

import Refraction from 'refraction';

class CustomRefraction extends Refraction {

  routeChange(route) {
    this.publish('routeChange', {
      type: 'route',
      payload: route,
    });
  }
}

class RouteManager {

  routeChange({ payload }) {
    window.location.href = payload;
  }
}

class ConsoleManager {

  routeChange({ payload }) {
    console.log(`New location = ${payload}`);
  }
}

const routeMiddleware = (param) => {
  const result = Object.assign({}, param);
  if (result && result.type === 'route') {
    // build complete url
    result.payload = `${window.location.protocol}//${window.location.host}${result.payload}`;
  }
  return result;
}

const refractionInstance = new CustomRefraction([ routeMiddleware ]);
const routeManager = new RouteManager();
const consoleManager = new ConsoleManager();

refractionInstance.subscribe(routeManager);
refractionInstance.subscribe(consoleManager);

// change route and log
refractionInstance.routeChange('home');

Documentation

Examples

You can find a series of examples in this repository under the examples folder. Alternatively, you can check awesome-refraction.

If you want to run examples, check out the instructions here.

Chat

This project has an official chat channel on gitter. This is the right place to talk about Refraction with us and others developers. Feel free to participate.

Join chat here.

Change Log

This project adheres to Semantic Versioning.
Every release, along with the migration instructions, is documented on the Github Releases page.

Inspiration

Refraction is inspired by different articles and tools:

  • Its architecture is inspired by this article based on Addy Osmani's talk of the same name, presented at LondonJS.
  • Its style is inspired by Redux

Authors

Matteo Basso

Adriano Buscema

Copyright and License

Copyright (c) 2016, Matteo Basso.

Refraction source code is licensed under the MIT License.

You might also like...

Hey Selam, Ben Spanker. Buraya İşinize Yarayacağına İnandığım Discord Owner Guard Botu Bırakıyorum.

Hey Selam, Ben Spanker. Buraya İşinize Yarayacağına İnandığım Discord Owner Guard Botu Bırakıyorum.

GİTHUB HESABIM KAPANDI AÇILANA KADAR BURDAYIM Lütfen Projeyi Hızlı Almak İçin Bot Basmayınız. Spanker Discord Owner Guard Botu Selam, Ben Spanker. Bu

Mar 10, 2022

Herkese selamlar buraya 800 satır güçlü bir guard botu bırakıyorum rol + kanal backup alma özelliği bulunan bu bot sizlerin sunucularını koruyacağına inanıyorum :)

Herkese selamlar buraya 800 satır güçlü bir guard botu bırakıyorum rol + kanal backup alma özelliği bulunan bu bot sizlerin sunucularını koruyacağına inanıyorum :)

null Guard Bot Botun alt yapısı Yashinu yani Yasin arkadaşımıza aittir. bot editlemeyi seven birisiyim yazma taraftarı değilim. Spankere inat paylaşıy

Sep 24, 2022

Discord Role Guard Backup Bot

Bot Ne Zaman Paylaşılacak? Bot 30 Star 10 Fork Olduğunda Paylaşılacaktır! Paylaşımdan Anında Haber Almak İçin Takip Edebilirsin 30 Star 10 Fork Olduğu

Oct 27, 2022

Discord Guard Bot for private servers.

Welcome to Discord Guard Bot Discord Guard Bot for private servers. Usage Clone repo and enter config.ts settings. (NOTE: Minumum 2 tokens.) Install t

Dec 14, 2022

This is a little script that shows how to ddos a website. Can bypass cloudfare & ddos-guard. Ip switcher and random user agent

This is a little script that shows how to ddos a website. Can bypass cloudfare & ddos-guard. Ip switcher and random user agent

Dec 17, 2022

V13 kullanılarak yapılmış slash destekli guard botu. Basit bir şekilde yapılıp geliştirmesi size bırakılmıştır.

V13 kullanılarak yapılmış slash destekli guard botu. Basit bir şekilde yapılıp geliştirmesi size bırakılmıştır.

V13 Slash Guard V13 kullanılarak yapılmış slash destekli guard botu. Basit bir şekilde yapılıp geliştirmesi size bırakılmıştır. Config dosyasını doldu

Dec 10, 2022

Şu ana kadar Github'da paylaşılan en sağlam database ve guard botları!

Şu ana kadar Github'da paylaşılan en sağlam database ve guard botları!

Database'yi paylaştım, 40 stara da guardı atıyorum! GITHUB'DAKI EN IYI BOTLAR! Dostlar selam, biliyorsunuz ki v13 geldiğinden ve heroku bittiğinden be

Jan 3, 2023

The Guard helps developers shield the details of the underlying authentication and tedious UI development

The Guard helps developers shield the details of the underlying authentication and tedious UI development

The Guard helps developers shield the details of the underlying authentication and tedious UI development. It enables enterprises and developers to quickly launch a secure, customizable UI unified login form.

Dec 19, 2022

Add focal point alignment of images to your Alpine 3.x components with a custom directive.

Alpine Focal Add focal point alignment of images to your Alpine 3.x components with a custom directive. This package only supports Alpine v3.x. About

Oct 12, 2021

This repository contains an Advanced Zoom Apps Sample. It should serve as a starting point for you to build and test your own Zoom App in development.

Advanced Zoom Apps Sample Advanced Sample covers most complex scenarios that you might be needed in apps. App has reference implementation for: Authen

Dec 17, 2022

The Aurelia 1 framework entry point, bringing together all the required sub-modules of Aurelia.

aurelia-framework Aurelia is a modern, front-end JavaScript framework for building browser, mobile, and desktop applications. It focuses on aligning c

Jan 7, 2023

A very fast geospatial point clustering library for browsers and Node.

A very fast geospatial point clustering library for browsers and Node.

supercluster A very fast JavaScript library for geospatial point clustering for browsers and Node. script src="https://unpkg.com/[email protected]/d

Jan 7, 2023

Alternatively called Yet Another Enhancement Point Tracker

Alternatively called Yet Another Enhancement Point Tracker

Yet Another Talent Tracker Alternatively called Yet Another Enhancement Point Tracker, but that name doesn't sound as cool in an acronym, so let's cal

Oct 17, 2022

A free and open-source point-of-sale (POS) system for retail and wholesale businesses with support for multiple branches, stockkeeping locations, POS profiles and price lists.

Note: This is a beta version of the software. You are advised to proceed with caution! Overview A free and open-source point-of-sale (POS) system for

Jan 27, 2022

A string of four operations of the library, can solve the js digital calculation accuracy of scientific notation and formatting problems, support for thousands of decimal point formatting output operations

A string of four operations of the library, can solve the js digital calculation accuracy of scientific notation and formatting problems, support for thousands of decimal point formatting output operations

Apr 6, 2022

Screeps Typescript Starter is a starting point for a Screeps AI written in Typescript.

Screeps Typescript Starter Screeps Typescript Starter is a starting point for a Screeps AI written in Typescript. It provides everything you need to s

Jan 27, 2022

We are creating a Library that would ensure developers do not reinvent the wheel anymore as far as Authentication is concerned. Developers can easily register and download authentication codes that suits their need at any point.

We are creating a Library that would ensure developers do not reinvent the wheel anymore as far as Authentication is concerned. Developers can easily register and download authentication codes that suits their need at any point.

#AuthWiki Resource Product Documentation Figma Database Schema First Presentation Live Link API Documentation Individual Contributions User Activity U

Dec 2, 2022

A lightweight jQuery custom scrollbar plugin, that triggers event when reached the defined point.

Scrollbox A lightweight jQuery custom scrollbar plugin, that triggers event when reached the defined point. Demo Page Table of contents Browser compat

Jul 22, 2022

Starting point for total web3.0 beginners.

Web3.0 for total beginners Things to begin with First read this Medium article about web3.0 How does Ethereum work, anyway? Then take a look to this v

Aug 30, 2022
Comments
  • Improve grammar of README

    Improve grammar of README

    Hey Matteo, I like this project. I just wanted to help you out and improve the English in the readme file so it sounds more like what a native speaker would say.

    • [x] Pull request has tests / docs demo, and is linted.
    • [x] Description explains the issue / use-case resolved, and auto-closes the related issue(s) (https://help.github.com/articles/closing-issues-via-commit-messages/).
    opened by jvandyke 3
  • (feature/core) use es class instance fields

    (feature/core) use es class instance fields

    • [x] Pull request has tests / docs demo, and is linted.
    • [x] Description explains the issue / use-case resolved, and auto-closes the related issue(s) (https://help.github.com/articles/closing-issues-via-commit-messages/).

    Since you're using stage-0, you can use the es class properties transform to auto bind instance methods.

    References: https://babeljs.io/docs/plugins/transform-class-properties/ https://github.com/jeffmo/es-class-fields-and-static-properties

    This also adds names to classes for better stack traces... Great job on this lib. 💯

    opened by justingreenberg 2
  • Create CNAME

    Create CNAME

    • [x] Pull request has tests / docs demo, and is linted.
    • [x] Description explains the issue / use-case resolved, and auto-closes the related issue(s) (https://help.github.com/articles/closing-issues-via-commit-messages/).
    opened by adribusc 1
  • Add a Gitter chat badge to README.md

    Add a Gitter chat badge to README.md

    mbasso/refraction now has a Chat Room on Gitter

    @mbasso has just created a chat room. You can visit it here: https://gitter.im/mbasso/refraction.

    This pull-request adds this badge to your README.md:

    Gitter

    If my aim is a little off, please let me know.

    Happy chatting.

    PS: Click here if you would prefer not to receive automatic pull-requests from Gitter in future.

    opened by gitter-badger 0
Releases(1.2.0)
Owner
Matteo Basso
Software developer :computer:, Open Sourcerer :unlock:, love experimenting with WebAssembly to make the web better :microscope:
Matteo Basso
Web based application that uses playerctl in it backend to control remotely your audio using the frontend as remote control.

Linux Remote This is a web based application that uses playerctl in it backend to control remotely your audio using the frontend as remote control. Do

Gabriel Guerra 4 Jul 6, 2022
Fluent UI web represents a collection of utilities, React components, and web components for building web applications.

Fluent UI Web ?? ?? ?? Version 8 of @fluentui/react is now available on npm! ?? ?? ?? See the release notes for more info, and please file an issue if

Microsoft 14.5k Jan 4, 2023
This example represents SCORM-compliant question set (aka quiz)

HTML&JS SCORM 2004 Compliant Quiz This example represents SCORM-compliant question set (aka quiz) and was made with Bootstrap 5 and Vanilla JS. You ma

null 1 Dec 25, 2021
Central repository for the Glimmer.js project

Glimmer.js Welcome to Glimmer.js! Glimmer.js is actually a made up of lots of small packages, so this meta-repo exists to help you find what you're lo

Glimmer.js 731 Dec 10, 2022
Central service used for management of CodeSupport user generated content.

CodeSupport API About This repository contains the code for the CodeSupport API. The project is written in TypeScript using the NestJS framework with

CodeSupport 2 Oct 14, 2022
Clinton Mbonu 20 Jun 30, 2022
The completed Codelab for GDG Central Florida - Ionic/Capacitor wizardry with Angular

GDG Central Florida - Ionic/Capacitor wizardry with Angular This is the completed code for Building an Ionic Application with Angular The App It is a

Javier 2 Oct 10, 2022
A three.js and roslibjs powered web-control for zju fast-drone-250 for laptop-free flight control

Web Control for ZJU Fast-Drone-250 A three.js and roslibjs powered web-control for zju fast-drone-250 for laptop-free flight control (tested on Xiaomi

null 6 Nov 11, 2022
Chat guard 2.0

Kurulum Node.JS Cihazınıda Node kurulu olduğuna emin olun. Yeşil Code butonuna basın ve Downland zip seçeneğine tıklayın indirme işlemini bekleyin. İn

Klanter 43 Dec 7, 2022
A simple Discord chat guard bot.

Discord Chat Guard Bot Kurulum İlk olarak bilgisayarına Node JS indir. Daha sonra bir MongoDB hesabı oluştur ve connection linki al. Eğer bunu yapmayı

Theark 38 Sep 17, 2022