Giter Site home page Giter Site logo

seorsum's Introduction

Hey! I'm Kalvin

I am a software developer working at @SpatialMedia on high detail interactive applications.

For work I mainly use Unity but in my spare time I am always trying out new things and experimenting with various technologies. I am currently really enjoying playing with Rust ๐Ÿ˜„

What I usually use

seorsum's People

Contributors

jamesyfc avatar kalvinpearce avatar

Watchers

 avatar

Forkers

jamesyfc

seorsum's Issues

Typescript update breaks useStateValue typings

I am trying to update deps to fix audit issues.

When updating with npm audit fix --force it updated jest which resulted in a bunce of new errors. tsc was checking files inside node_modules so I found a potential solution was to use skipLibChecks: true in the tsconfig.json. However this fix needed typescript to be upgraded to >=3.7.3. When upgrading typescript to anything over 3.7.2 it breaks the following code, specifically line 100: statePath

seorsum/src/index.ts

Lines 93 to 103 in 6c8ce7c

const useStateValue = <PPath extends Path<S, PPath>, S extends State = State>(
statePath: PPath,
) => {
const [value, setValue] = React.useState(
getFromPath<S, PPath>(state as S, statePath),
);
React.useEffect(() => {
return subscribe(statePath, setValue);
}, []);
return value;
};

Rework subscribe function to add more typesafety

Need to look into if theres a better way of subscribing to state pieces. At the moment there is little safety around what gets put in the stateValue param. Would be good to rework to make it more typesafe if possible?

This would remove the need for branching statement and broken subscribes.

seorsum/src/index.ts

Lines 44 to 60 in 446d28f

const subscribe = <T>(
stateValue: (state: State) => T,
callback: (state: T) => void,
) => {
// Little messy way of grabbing the state path from the params
const res = stateValue.toString().match(/\.(.*);/);
// This should always pass but is needed for intellisense
if (res && res.length > 1) {
const key = res[1];
const fn = () => callback(stateValue(state));
// Add to event bus
bus.addListener(key, fn);
// Return function to remove from event bus
return () => {
bus.removeListener(key, fn);
};
}

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.