Giter Club home page Giter Club logo

fusion-plugin-react-redux's Introduction

Modern framework for fast, powerful React apps

Build status fusion-core Downloads

What is it?

fu·sionnoun

The process or result of joining two or more things together to form a single entity.

Fusion.js, Uber’s open source universal web framework, represents the fusion of the client and the server. It's geared for server-side rendering out of the box, and its plugin-driven architecture allows for complex frontend and backend logic to be encapsulated in a single plugin:

import App from 'fusion-react';
import Router from 'fusion-plugin-react-router';

export default () => {
  const app = new App(<div>...</div>);

  /*
  One line of code sets up everything you need for routing:
  - Server rendering
  - React Providers on both server and browser
  - Bundle splitting integration
  - Hot module reloading support
  */
  app.register(Router);

  return app;
}

We initially built Fusion.js to make our own websites easier to maintain, but were so impressed with the benefits that we decided to offer it to the community as an open source project!

Try it out

If you're interested in giving Fusion.js a shot, Overview and Core Concepts are great places to start.

Contributing

This is a monorepo of all open source Fusion.js packages maintained using Yarn v2. Take a look at CONTRIBUTING.md for info on how to develop in this repo.

License

MIT

fusion-plugin-react-redux's People

Contributors

alexmsmithca avatar chirgjn avatar chrisdothtml avatar codalife avatar dennisgl avatar derekjuber avatar ganemone avatar kahwee avatar kevingrandon avatar lhorie avatar nadiia avatar rajeshsegu avatar renovate-bot avatar renovate[bot] avatar rtsao avatar sagiavinash avatar sblotner avatar uberopensourcebot avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

fusion-plugin-react-redux's Issues

Add Token dependencies to readme

Problem/Rationale

Documentation regarding Fusion API is out of date given recent changes to leverage new Dependency Injection architecture.

Solution/Change/Deliverable

Update documentation

Dependency deprecation warning: @types/redux (npm)

On registry https://registry.npmjs.org/, the "latest" version (v3.6.0) of dependency @types/redux has the following deprecation notice:

This is a stub types definition for Redux (https://github.com/reactjs/redux). Redux provides its own type definitions, so you don't need @types/redux installed!

Marking the latest version of an npm package as deprecated results in the entire package being considered deprecated, so contact the package author you think this is a mistake.

Please take the actions necessary to rename or substitute this deprecated package and commit to your base branch. If you wish to ignore this deprecation warning and continue using @types/redux as-is, please add it to your ignoreDeps array in Renovate config before closing this issue, otherwise another issue will be recreated the next time Renovate runs.

Date objects do not survive across node and browser boundaries.

In fusion js the redux store is stringified and parsed to be passed between client and server. This creates an issue where high level types, including built-in's like Date break on this line:

preloadedState = JSON.parse(unescape(stateElement.textContent));

Normal parse doesn't work correctly for ISO8601 date strings, and there is a good example of a workaround I'll reference from here and a robust regex from here

// Problem
const body = `{
    "date": "2016-04-26T18:09:16Z"
}`;

const obj = JSON.parse(body);

const { date } = obj;
console.log(typeof date);
// "string"

But we can add a revive function that fixes this issue.

// Solution

function isIso8601(value: string): boolean {
  const dateFormat = /^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;
  return dateFormat.test(value)
}


function reviver(key, value) {
    if (typeof value === "string" && isIso8601(value)) {
        return new Date(value);
    }

    return value;
}

const text = '{ "date": "2016-04-26T18:09:16Z" }';
const obj = JSON.parse(text, reviver);

console.log(typeof obj.date);
// "object"

I'd like to open a PR to implement this reviver.

Linter errors in master

image

These errors already existed in master, but were exposed when we started running linters in buildkite.

Throw if context is not provided

In the browser we can currently call .of() on this plugin which would return a new store. We should enforce that we only ever have a single store, so let's throw if context is not provided.

Add workaround for hotreloading when there are no store changes

When any file is hotloaded in the browser, for example a react component, fusion will re-run the middleware stack. This is the correct behavior as that is what sets up context providers and eventually renders the application. However, in the case of redux, we don't want to recreate the store as it will result in warnings and potential loss of state. This adds a cache in the browser to ensure that you only create your store once.

Rename InitialStateToken to GetInitialStateToken

InitialStateToken is confusing especially with how similar it
sounds to PreloadedStateToken. It is more clear to be named GetInitialStateToken as
it implies that the registration is a function rather than a value for the state.

Pass Context to enhancers

Redux store enhancers dont have a way to access Context.

Type of issue

Feature request

Description

I created a plugin to allow cookie manipulation on the browser and server and would like to be able to access that plugin in a redux middleware. The use case is to set a cookie when a certain action is fired. Unless I'm missing something I would need to have access to the Context when creating that middleware (in order to get the cookie plugin via dep/token).

Current behavior

Currently enhancers (besides ctxEnhancer) are not passed ctx, code here:

const enhancers = [enhancer, ctxEnhancer(ctx), devTool].filter(

Expected behavior

Enhancers are changed to be returned from a function that is passed Context.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.