
Security News
AGENTS.md Gains Traction as an Open Format for AI Coding Agents
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
riot-opt-types-mixin
Advanced tools
This mixin will monitor the opts being passed to your tags. If your tag is passed opts it doesn't expect, this mixin will warn you via a console error.
npm install riot-opt-types-mixin --save-dev
Define this.optTypes = {}
in your riotjs tag, then include riot-opt-types-mixin as a mixin like so:
index.js
:
import riotOptTypesMixin from 'riot-opt-types-mixin';
riot.mixin(riotOptTypesMixin); // apply mixin to all tags
app.tag
:
import { optTypes } from 'riot-opt-types-mixin';
<app>
<script>
// define expected opts (attributes) for your tag
this.optTypes = {
name: optTypes.string.isRequired
};
</script>
<h1>Hello, {opts.name}</h1>
</app>
Now, if you pass name
incorrectly to <my-tag>
you get a nice descriptive error in your browser's console
<my-tag name={100}/> = Invalid opt 'name' of type 'number' supplied to 'my-tag', expected 'string'.
You can also nest opt validation which can be useful when combined state management tools such as Redux
this.optTypes = {
state: optTypes.shape({
data: optTypes.shape({
name: optTypes.string.isRequired
})
}),
dispatch: optTypes.func.isRequired
};
Please refer to React's PropTypes Documentation for more info on how to use these optTypes.
optTypes
Please refer to React's PropTypes Documentation if you have any questions about how each of these function.
This mixin feature all the same optTypes
listed in React's documentation except for element
and node
which validates React components. I plan on appending a "tag" checker soon for Riot.
I'm a big fan of this functionality in React and wanted to be able to utilize it in Riot apps.
This mixin isn't really benefitial to small projects, but it can help while developing larger applications because it forces your tags to strictly define what inputs they expect from their parent tags, or application state (redux, flux, etc).
This mixin, when compressed, clocks in at about 5kb BUT, really it is only benefitial for local development, so you can (and probably should) trim it out for deployment builds.
If using webpack, strip-loader and NormalModuleReplacementPlugin are good places to start. (TODO: add more documentation about how to do this...)
Using Riot in conjunction with TypeScript allows for setting of expected prop types. RiotTS looks like a good option if you're interested in using TypeScript for your Riot app.
PRs welcome! Please contact me if you have any questions, suggestions, or issues too!
Most of the functionality is a direct port of React's PropTypes.
FAQs
Like React component PropTypes, but for Riot tags
The npm package riot-opt-types-mixin receives a total of 0 weekly downloads. As such, riot-opt-types-mixin popularity was classified as not popular.
We found that riot-opt-types-mixin demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.