cf-section-extrapolator

0.0.1 • Public • Published

cf-section-extrapolator

This module supercedes cf-sectionizer.

Take a list describing a set of sections and callback with a list of actual section ids.

Installation

npm install --save cf-section-extrapolator

API

var extrapolate = require('cf-section-extrapolator')

extrapolate(sectionService, currentSectionId, desiredSections, cb)

  • sectionService is a service that has a findPublic(query, cb) method
  • currentSectionId is the stringy id of the current section
  • desiredSections is a list describing which sections are desired, in the format: [ { id: 'section-id-123', includeSubSections: true|false } ]. Using the special case of id='-1' the currentSectionId will be used.

If this doesn't make sense, read the usage notes below. Hopefully all will become clear.

Usage

var desiredSections =
  [ { id: '123', includeSubSections: true }
  , { id: '456', includeSubSections: false }
  ]

Given the section hierarchy:

Sport(id:123)
- Football(id:123a)
-- Premier League(id:123ai)
-- World Cup(id:123aii)
- Tennis(id:123b)
-- Wimbledon(id:123bi)
-- French Open(id:123bii)
Entertainment(id:456)
- Theatre(id:456a)
- TV(id:456b)
- Film(id:456c)

Will callback with an array:

sectionize(sectionService, currentSectionId, desiredSections, function (err, ids) {
  // ids == [ '123', '123a', '123ai', '123aii'
  //        , '123b' , '123bi', '123bii', '456' ]
})

Special case

The section id of -1 is treated as a {CURRENT} section mapping. Rather than knowing the section id at the time of list creation, the 'current' section can be injected when the list is being aggregated so that it can include contextual content based on where it is used.

var currentSectionId = '789'
  , desiredSections = [ { id: '-1', includeSubSections: false } ]
sectionize(sectionService, currentSectionId, desiredSections, function (err, ids) {
  // ids == [ '789' ]
})

Credits

Built by developers at Clock.

Licence

Licensed under the New BSD License

Readme

Keywords

none

Package Sidebar

Install

npm i cf-section-extrapolator

Weekly Downloads

63

Version

0.0.1

License

none

Last publish

Collaborators

  • bengourley
  • serby