2016-11-17 20:00:20 +01:00
import { compose } from 'react-apollo' ; // note: at the moment, compose@react-apollo === compose@redux ; see https://github.com/apollostack/react-apollo/blob/master/src/index.ts#L4-L7
2016-02-17 14:39:56 +09:00
/ * *
2016-04-09 09:41:20 +09:00
* @ summary Kick off the global namespace for Telescope .
2016-02-17 14:39:56 +09:00
* @ namespace Telescope
* /
2016-11-17 20:00:20 +01:00
const Telescope = { } ;
2016-02-17 14:39:56 +09:00
2016-11-15 10:44:01 +01:00
Telescope . VERSION = '0.27.4-nova' ;
2016-02-17 14:39:56 +09:00
2016-02-16 15:08:30 +09:00
// ------------------------------------- Config -------------------------------- //
2015-04-22 07:50:11 +09:00
/ * *
2016-04-09 09:41:20 +09:00
* @ summary Telescope configuration namespace
2015-05-10 13:37:42 +09:00
* @ namespace Telescope . config
2015-04-22 07:50:11 +09:00
* /
2016-02-16 15:08:30 +09:00
Telescope . config = { } ;
2016-06-15 11:07:30 +09:00
2016-02-16 15:08:30 +09:00
// ------------------------------------- Schemas -------------------------------- //
SimpleSchema . extendOptions ( {
private : Match . Optional ( Boolean ) ,
editable : Match . Optional ( Boolean ) , // editable: true means the field can be edited by the document's owner
hidden : Match . Optional ( Boolean ) , // hidden: true means the field is never shown in a form no matter what
required : Match . Optional ( Boolean ) , // required: true means the field is required to have a complete profile
profile : Match . Optional ( Boolean ) , // profile: true means the field is shown on user profiles
template : Match . Optional ( String ) , // template used to display the field
2016-10-05 08:43:13 +02:00
form : Match . Optional ( Object ) , // form placeholder
2016-10-14 11:55:47 +02:00
autoform : Match . Optional ( Object ) , // legacy form placeholder; backward compatibility
2016-04-04 16:50:07 +09:00
control : Match . Optional ( Match . Any ) , // NovaForm control (String or React component)
2016-06-03 11:03:36 +09:00
order : Match . Optional ( Number ) , // position in the form
group : Match . Optional ( Object ) // form fieldset group
2016-02-16 15:08:30 +09:00
} ) ;
// ------------------------------------- Components -------------------------------- //
Telescope . components = { } ;
2016-11-17 20:00:20 +01:00
/ * *
* Register a Telescope component with a name , a raw component than can be extended
* and one or more optional higher order components .
*
* @ param { String } name The name of the component to register .
* @ param { React Component } rawComponent Interchangeable / extendable component .
* @ param { ... Function } hocs The HOCs to compose with the raw component .
* @ returns { Function | React Component } A component callable with Telescope . components [ name ]
*
* Note : when a component is registered without higher order component , ` hocs ` will be
* an empty array , and it ' s ok !
* See https : //github.com/reactjs/redux/blob/master/src/compose.js#L13-L15
* /
Telescope . registerComponent = ( name , rawComponent , ... hocs ) => {
// console.log('// registering component');
// console.log(name);
// console.log('raw component', rawComponent);
// console.log('higher order components', hocs);
// note: maybe do something to replace connect at the right place, see https://github.com/apollostack/react-apollo/issues/315
// compose the raw component with the HOCs given in option
Telescope . components [ name ] = compose ( ... hocs ) ( rawComponent ) ;
// keep track of the raw component & hocs, so we can extend the component if necessary
Telescope . components [ name ] . rawComponent = rawComponent ;
Telescope . components [ name ] . hocs = hocs ;
return Telescope . components [ name ] ;
2016-02-16 15:08:30 +09:00
} ;
2016-11-17 20:00:20 +01:00
/ * *
* Get a component registered with Telescope . registerComponent ( name , component , ... hocs ) .
*
* @ param { String } name The name of the component to get .
* @ returns { Function | React Component } A ( wrapped ) React component
* /
2016-02-16 15:08:30 +09:00
Telescope . getComponent = ( name ) => {
return Telescope . components [ name ] ;
} ;
2016-11-17 20:00:20 +01:00
/ * *
* Get the * * raw * * ( original ) component registered with Telescope . registerComponent
* without the possible HOCs wrapping it .
*
* @ param { String } name The name of the component to get .
* @ returns { Function | React Component } An interchangeable / extendable React component
* /
Telescope . getRawComponent = ( name ) => {
return Telescope . components [ name ] . rawComponent ;
} ;
/ * *
* Replace a Telescope component with the same name with a new component or
* an extension of the raw component and one or more optional higher order components .
* This function keeps track of the previous HOCs and wrap the new HOCs around previous ones
*
* @ param { String } name The name of the component to register .
* @ param { React Component } rawComponent Interchangeable / extendable component .
* @ param { ... Function } hocs The HOCs to compose with the raw component .
* @ returns { Function | React Component } A component callable with Telescope . components [ name ]
*
* Note : when a component is registered without higher order component , ` hocs ` will be
* an empty array , and it ' s ok !
* See https : //github.com/reactjs/redux/blob/master/src/compose.js#L13-L15
* /
Telescope . replaceComponent = ( name , newComponent , ... newHocs ) => {
const previousComponent = Telescope . components [ name ] ;
// xxx : throw an error if the previous component doesn't exist
// console.log('// replacing component');
// console.log(name);
// console.log(newComponent);
// console.log('new hocs', newHocs);
// console.log('previous hocs', previousComponent.hocs);
return Telescope . registerComponent ( name , newComponent , ... newHocs , ... previousComponent . hocs ) ;
}
2016-02-16 15:08:30 +09:00
// ------------------------------------- Subscriptions -------------------------------- //
/ * *
2016-04-09 09:41:20 +09:00
* @ summary Subscriptions namespace
2016-02-16 15:08:30 +09:00
* @ namespace Telescope . subscriptions
* /
Telescope . subscriptions = [ ] ;
/ * *
2016-04-09 09:41:20 +09:00
* @ summary Add a subscription to be preloaded
2016-02-16 15:08:30 +09:00
* @ param { string } subscription - The name of the subscription
* /
Telescope . subscriptions . preload = function ( subscription , args ) {
Telescope . subscriptions . push ( { name : subscription , arguments : args } ) ;
2016-06-09 17:42:20 +09:00
} ;
2016-06-15 11:07:30 +09:00
// ------------------------------------- Strings -------------------------------- //
2016-06-09 17:42:20 +09:00
Telescope . strings = { } ;
2016-06-15 11:07:30 +09:00
// ------------------------------------- Routes -------------------------------- //
Telescope . routes = {
routes : [ ] ,
add ( routeOrRouteArray ) {
const addedRoutes = Array . isArray ( routeOrRouteArray ) ? routeOrRouteArray : [ routeOrRouteArray ] ;
this . routes = this . routes . concat ( addedRoutes ) ;
}
2016-07-06 10:21:58 +09:00
}
// ------------------------------------- Head Tags -------------------------------- //
Telescope . headtags = {
meta : [ ] ,
link : [ ]
2016-08-08 11:18:21 +09:00
}
2016-08-10 10:40:17 +09:00
// ------------------------------------- Statuses -------------------------------- //
Telescope . statuses = [
{
value : 1 ,
label : 'pending'
} ,
{
value : 2 ,
label : 'approved'
} ,
{
value : 3 ,
label : 'rejected'
} ,
{
value : 4 ,
label : 'spam'
} ,
{
value : 5 ,
label : 'deleted'
}
] ;
2016-10-19 10:32:24 +02:00
// ---------------------------------- Redux ------------------------------------ //
Telescope . actions = { } ;
Telescope . reducers = { } ;
2016-08-08 11:18:21 +09:00
export default Telescope ;