GithubHelp home page GithubHelp logo

asbjornh / view-models Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 281 KB

Tools for converting type definitions in client side apps to type definitions in server-side languages.

License: MIT License

TypeScript 30.40% JavaScript 65.30% C# 4.30%

view-models's People

Contributors

asbjornh avatar

Stargazers

 avatar

Watchers

 avatar

view-models's Issues

Feature: name validation in eslint plugin

Sometimes things don't build because of inconsistent naming, such as naming a file youtube-player but naming the component YouTubePlayer. In this case, the output import statements would be:

import { YouTubePlayer } from './YoutubePlayer';

This would fail, since YoutubePlayer.d.ts exports YoutubePlayer (lowercase t)

There should be an eslint rule to validate that identifier names match the pascal case version of file names

Feature: Possibility to generate a manifest/map/lookup

I'll use C#/Razor as an example here.

After generating the classes, one still has to stringly type the path to the component in the global scope:

@Html.React("Components.Header", model.Header)

It would be nice to be able to generate something to remove this, where the something generator would receive a list of the metadata for all processed components.

We could then generate a static class

public static class ComponentPaths
{
   public static string Header => "Components.Header";
}

and do:

@Html.React(ComponentPaths.Header, model.Header)

This will give us compile time safety for the now stringly typed component paths.

Silently fails when using HOCs

When a components uses a HOC in the export declaration (export default someHoc(MyComponent); a class isn't generated for the component and no errors are thrown. An error should be thrown when using HOCs.

Issue using @babel/eslint-parser

When running Linter and using syntax like this
https://gyazo.com/6bcf845196aedf7900ae71c4e8eb29f7 I get such errors
https://gyazo.com/f334f03a3669c988924abf1f1c569efe . For some models, I exclude properties from the generated models (using 'ignore' attribute), however, the @babel/eslint-parser highlights this syntax with an error, what can be the reason for such a behavior?

Just run the 'yarn run lint:fix' in the root folder of the example attached in order to reproduce the problem.

I would appreciate any help from your side, thanks in advance
ESLint-issue.zip

Eslint plugin: Warn when not spreading props

If props are passed manually, fewer guarantees can be made about generated viewmodels.

const Parent = ({ childProps }) => (
  <Child propA={childProps.propA} propB={childProps.propB} />
);

Parent.propTypes = {
  childProps: PropTypes.shape(Child.propTypes)
};

In this example, there is no guarantee that a valid Parent model will result in valid data being passed to Child because Parent contains a manual mapping from props to Child props. In the next example, we can guarantee that a valid Parent model will result in a valid Child model as well:

const Parent = ({ childProps }) => <Child {...childProps} />;

Parent.propTypes = {
  childProps: PropTypes.shape(Child.propTypes)
};

It would help a lot if the eslint plugin could warn about cases such as the first one. This would probably have to be pretty naive in order to keep complexity and scope down. The simplest heuristic seems to be checking whether a prop is a reference to another component (shape(SomeComponent.propTypes)) and also check whether that prop is being spread or not

Feature: adding docs to view models

There should be a way for the parsed file to provide prose that is output in generated files. Maybe a JSDoc comment connected to the type definition or a .viewModelDoc property for react components.

Double Star in Globs

It seems that using double stars in globs to match an arbitrary number of directories is unsupported.

Given f.ex. client/**/*.jsx as input, I would expect both client/contexts/cool-context.jsx and client/components/cool-component/cool-component.jsx to be processed.

There doesn't seem to be any documentation for the CLI, but using a single star to match filenames works fine. Using double stars matches a single directory, but not an arbitrary number of directories.

Feature: dynamic types

In some rare cases, stuff can't be typed without the use of any/PropTypes.any. C# and Kotlin support this through the dynamic type, and typescript with any.

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.