<commit_before>let deviceService = require( '../../services/device.service' ),
  publisher = require( '../../components/publisher/publisher' );

function DeviceController() {
  let self = this;

	//Public methods and attributes
  Object.assign( self, {
    link: link,
    unlink: unlink,
    init: init
  } );

  return self;

	// //PUBLIC FUNCTIONS
	// To bind elements
  function link( sammyContext ) {
    $( '.js-card' )
      .deviceCard( {} )
      .on( 'click', function redirect() {
        sammyContext.redirect( '#/notes' );
      } );
  }

	// To make calls to apis. It may returns a promise.
  function init() {

    publisher.subscribe( 'button.back', function event_handler( ) {
      let res = confirm( 'Are you sure you want to go back?' );
      return new Promise( function promise_handler( resolve, reject ) {
        if ( res ) {
          resolve( 'user accept.' );
        } else {
          reject( 'user reject.' );
        }
      } );
    } );

    // Temporary call to create devices.
    deviceService
      .post( {
        brand: 'Motorola',
        id: '1234',
        model: 'G3',
        status: 'locked',
        reservedBy: {
          id: '992',
          lastName: 'Smith',
          name: 'John',
          username: 'jsmith'
        }
      } );

    return deviceService
      .get()
      .then( function show_devices( devices ) {
        self.list = devices;
      } );
  }

  function unlink() {
    // eslint-disable-next-line no-console
    console.log( 'Unlink device!!' );
  }
}

module.exports = DeviceController;<commit_msg>Controller unsubscribe navbar click event when the controller is release.<commit_after>let deviceService = require( '../../services/device.service' ),
  publisher = require( '../../components/publisher/publisher' );

function DeviceController() {
  let self = this,
    subscribed = [];

	//Public methods and attributes
  Object.assign( self, {
    link: link,
    unlink: unlink,
    init: init
  } );

  return self;

	// //PUBLIC FUNCTIONS
	// To bind elements
  function link( sammyContext ) {
    $( '.js-card' )
      .deviceCard( {} )
      .on( 'click', function redirect() {
        sammyContext.redirect( '#/notes' );
      } );
  }

	// To make calls to apis. It may returns a promise.
  function init() {

    subscribed.push(
      publisher.subscribe( 'button.back', function event_handler( ) {
        let res = confirm( 'Are you sure you want to go back?' );
        return new Promise( function promise_handler( resolve, reject ) {
          if ( res ) {
            resolve( 'user accept.' );
          } else {
            reject( 'user reject.' );
          }
        } );
      } )
    );

    // Temporary call to create devices.
    deviceService
      .post( {
        brand: 'Motorola',
        id: '1234',
        model: 'G3',
        status: 'locked',
        reservedBy: {
          id: '992',
          lastName: 'Smith',
          name: 'John',
          username: 'jsmith'
        }
      } );

    return deviceService
      .get()
      .then( function show_devices( devices ) {
        self.list = devices;
      } );
  }

  function unlink() {
    // Unsubscribe handlers
    subscribed.map( function unsubscribe( id ) {
      publisher.unsubscribe( id );
    } )
  }
}

module.exports = DeviceController;
{'fraction_non_alphanumeric': 0.13725490196078433, 'fraction_numerical': 0.0048265460030165915, 'mean_word_length': 1.931918656056587, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4539087', 'n_tokens_mistral': 997, 'n_tokens_neox': 969, 'n_words': 267}