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

core-os

v0.1.10

Published

Awesome event oriented javascript framework

Downloads

20

Readme

CORE for JS - write code close to how you think

Write less, do more

This framework is the simple JS implementation of CORE design pattern (acronym: Contexts, Objects, Requests and Events)

This design pattern and the framework provide you ability to easily design and implement well structured, high cohesioned, and low coupled modular systems using Events and Requests. The benefit of that approach is a semantic which is highly close to Business Logic, which allows to write less code doing more, and have less bugs and debugging with it.

The ideas in the base of it are similar to following approaches, and it collects the best benefits of them:

  • automata-based programming
  • actor model
  • system of signals and slots
  • event-oriented programming

Event is a complex object, that means that something has already happend.

Request is a complex object, that means that something asks to perform its request.

Other objects of the system can subscribe to Events and Requests. Subscription is a static process (which is different to usual obj.fire('event') and obj.on('event) dynamic-style subscriptions).

During initialization CORE framework parses the code of methods and subscribes objects on Events and Requests statically.

Note that 99% of real-world cases don't need a dynamic behaviour, which is a good base to simplify this process

Static approach also offers you an ability to build a map how objects/methods are connected, and analyse it, which can extend your Static Code Analysis Tool benefits of your project.

High-level description: https://medium.com/@i_am_os/core-design-pattern-the-way-out-from-overly-complicated-code-b8804449941

How to help the project: https://medium.com/ux-of-programming-languages/lets-build-a-community-around-core-701eb8ebb02c

Installing

API

Events

Description

There are three steps for using Events: initialization, firing, catching.

You can pass some data with Event.

Example

Initialization

To initialize Event object call Core.registerEventPoint with Event name. Event name consists of Object name that has this Event and action name.

  Core.registerEventPoint('Player_Started');

Firing

To fire Event call FireEvent function with created Event.

  var Player = {
      mediaTag: document.getElementById('audio')

    , start: function() {
      this.mediaTag.play();
      
      FireEvent(new Player_Started({data: 'some-data'}));
    }
  }

Catching

The main twist is that you can catch the fired Event at any spaces of your code.

So this can cut your code several times.

Also you can dinamically subscribe to the event. It is useful in different cases, for example, in angular directives.

Single Event Catching
var GoogleTrackingObject = {
  sendPlayerEvent: function() {
    var event = CatchEvent(Player_Started);
    
    /* event.data === 'some-data'  //true    */
    
    ga('send', 'event', 'player', 'start');
  }
}
Multiple Event Catching
var GoogleTrackingObject = {
  sendPlayerEvents: function() {
    var event = CatchEvent(Player_Started, Player_Paused);
    
    ga('send', 'event', 'player', 'player_event', event.type);
  }
}

Requests

Description

There are three steps for using them: initialization, firing, catching. You can pass some data with the Request.

Example

Initialization

Just create Request object.

  Core.registerRequestPoint('PlayerUI_StartRequest')

Firing

Fire it and ask something to perform your request.

  var PlayerUi = {
    startPlaying: function() {
      FireRequest(
          new PlayerUI_StartRequest({data: 'some-data'})
        , function() {} // success callback
        , function() {} // error callback
        , {} // context
      )
    }
  }

Catching

Catch the Request and perform it.

var PlayerAudio = {
  startPlaying: function() {
    var request = CatchRequest(PlayerUI_StartRequest);
    
    /* request.data === 'some-data'  //true    */
    
    return function(cb, eb) {
      /* start playing audio player logic */
      cb();
    }
  }
}

There can be several objects that can resolve Requests. When one of them can't process Request it call error callback function and next object start processing.

var PlayerAudio = {
    mediaTag: null
  
  , startPlaying: function() {
    CatchRequest(PlayerUI_StartRequest);
    
    return function(cb, eb) {
      if( !PlayerAudio.mediaTag ) {
        return eb();
      }
      
      /* start playing audio player logic */
      cb();
    }
  }
}

var Player = {
  start: function() {
    CatchRequest(PlayerUI_StartRequest);
    
    return function(cb, eb) {
      /* start playing audio player logic */
      cb();
    }
  }
}

States

It's an example how we can implement more complicated object's behaviour and use it in CORE-style.

Description

Usage

 Core.state(state1, state2, ...)

Params

  (String) '' // name of the state

Returns

 (Object) {
    value: (String)    // current state value
  , go   : (Function)  // method to change state
 }

Examples

Initialization

 var Object = {
   mainState: Core.state('Idle', 'Running', 'Stopped')
 }

When the object has been inited, its state goes to the first value of the set.

Changing State

  Object.mainState.go('Running');

When state has been changed, the Event Object.mainState.GoRunning fires. And it can be catched at any space of the application.

 var MiddleObject = {
  getState: function() {
    Core.CatchEvent(Object.mainState.GoRunning, Object.mainState.GoStopped);
    
    if( Object.mainState.value === 'Running' ) {
      // your code here
    }
  }
 }