fusionjs / fusion-plugin-react-redux Goto Github PK
View Code? Open in Web Editor NEWMigrated to https://github.com/fusionjs/fusionjs
License: MIT License
Migrated to https://github.com/fusionjs/fusionjs
License: MIT License
Needs to skip cleanup
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.
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:
fusion-plugin-react-redux/src/browser.js
Line 49 in a465f71
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.
Redux stores are created per request, however, enhancers have no reference to ctx
currently.
Some benefits/use-cases:
ctx
may have meta information useful for logging, analytics...etc.example: fusion-redux-action-emitter-enhancer
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.
A tad backwards for this, but the PR should be self explanatory:
TL;DR - Running Redux Dev Tools in Chrome caused other enhancers to not run.
Redux store enhancers dont have a way to access Context.
Feature request
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).
Currently enhancers (besides ctxEnhancer
) are not passed ctx
, code here:
fusion-plugin-react-redux/src/browser.js
Line 44 in 593de8e
Enhancers are changed to be returned from a function that is passed Context.
Documentation regarding Fusion API is out of date given recent changes to leverage new Dependency Injection architecture.
Update documentation
If there is no preloadedState and no server side render to create the REDUX_STATE element, the plugin with throw an exception. Instead, we should just allow an initial state of undefined
.
None of these tokens should be required, since you can use redux without using any of them
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.
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.