npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fashion-model-action

v1.0.0

Published

fashion-model Oja Action

Downloads

4

Readme

fashion-model-action

codecov Build Status NPM

A fashion-model wrapper for oja allowing data that is being defined and consumed to be a fashion-model.

Installation

npm install fashion-model-action --save

Usage

const Model = require('fashion-model/Model')
const Enum = require('fashion-model/Enum')
const FashionModelAction = require('fashion-model-action')

const Person = Model.extend({
  // The oja "topic" to defines
  typeName: 'person',
  properties: {
    name: String,
    height: Number,
    weight: Number
  }
})

class PersonSearchAction extends FashionModelAction {
  execute() {
    this.define(Person, {
      name: 'John',
      height: 100,
      weight: 100
    })
  }
}

;(async function () {
  // { name: 'John', height: 100, weight: 100 }
  const person = await new PersonSearchAction()
    .activate()
    .consume(Person)
})()

How it works

A fashion-model's typeName property is used to define the producing oja topic.

const Person = require('fashion-model/Model').extend({
  // The oja "topic" to defines
  typeName: 'person',
  properties: {
    ...
  }
})

Consuming also uses the same fashion-model typeName property:

const Person = require('./models/Person')

const person = await new PersonSearchAction()
  .activate()
  .consume(Person)

API

  • FashionModelAction() is a oja Action constructor

  • consume(topics | Model [, callback]) adds a consumer to the flow for the given fashion-model typeName topic or standard oja topic(s).

    • topics is one or more topics to capture by the handler

    • Model is a fashion-model whose typeName property is used to determine the topic to capture by the handler

    • callback((data|map), flow) is a handler, if provided, it will be called once all topics are resolved

      • data resolved for the single topic
      • map of resolved data mapped to corresponding topics
      • flow is an instance of the flow for convenience
    • returns promise or a list of promises if callback is not provided;

      • promise for single topic
      • promises mapped to the provided topics
  • consumeStream(topic | Model [, callback]) returns a readable stream of events for the given topic

    • topic is a topic to capture by the handler
    • Model is a fashion-model whose typeName property is used to determine the topic to capture by the handler
    • Note: if callback is provided, it will return a stream to the callback(stream) and continue cascading flow by returning 'this' reference;
  • define(topics | Model [, data|promise|function]) defines a producer for the given topic or an array of topics

    • topics is a single topic or an array of topics to broadcast the data with.
    • Model is a fashion-model whose typeName property is used to determine the topic to broadcast the data with
    • data will be immediately published under the given topics into the flow; in case an error object is passed, the flow will be stopped and an 'error' event will be broadcasted into the flow.
    • promise will publish data once resolved; in case of reject, the flow will be stopped and an 'error' event will be broadcasted into the flow.
    • function(publisher, flow) will be called immediately
      • publisher is a convenience object to publish events for the assigned topic in async use-case
      • flow is an instance of the current flow.
      • if function returns a non-undefined value, it will be published under the assigned topic immediately; this is useful in a sync flow.