Coder Social home page Coder Social logo

Comments (3)

mako-taco avatar mako-taco commented on May 21, 2024

I do eventually want to support custom types. For now, I will probably just add SetOf, MapOf.

I will think on the API for a custom type checker afterwards. I could just expose Validator and ValidatorResult which I use internally, but they are a little confusing, and usually overkill for simple types.

from decoratethis.

mako-taco avatar mako-taco commented on May 21, 2024

I think this will get us by.

const ImmutableMap = KeyedCollection(Immutable.Map, map => map.toObject());
const ImmutableListOf = TypedCollection(Immutable.List, list => list.toArray());

class T {
    @param(ImmutableMap({key: String, val: String}))
    doThing() {
    }

    @param(ImmutableListOf(Number))
    doOtherThing() {
    }
}

KeyedCollection takes two arguments, a constructor/class and a transformation function. It returns a function which takes a type.

  • The transformation function must return a plain Object

TypedCollection takes two arguments, a constructor/class and a transformation function. It returns a function which takes a type.

  • The transformation function must return either an Array or an Object.
  • The returned value will be iterated over with a for...of loop
  • Each member of the value will be validated against the type

@callumlocke any comments?

from decoratethis.

callumlocke avatar callumlocke commented on May 21, 2024

looks great

from decoratethis.

Related Issues (11)

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.