Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom.js no longer triggering on app_initialized.NotebookApp #2403

Closed
andyneff opened this issue Apr 12, 2017 · 8 comments
Closed

custom.js no longer triggering on app_initialized.NotebookApp #2403

andyneff opened this issue Apr 12, 2017 · 8 comments

Comments

@andyneff
Copy link

Using notebook 5.0.0, my custom.js files is no longer triggering app_initialized.NotebookApp.

  1. Add the following to custom.js
define(['base/js/events'], function(events) {
    events.on('app_initialized.NotebookApp', function () {
        console.log('app_initialized.NotebookApp');
    });
});
  1. Open a notebook and 'app_initialized.NotebookApp' is never logged. However, code outside the 'app_initialized.NotebookApp' callback will be called.
@AndreWin
Copy link

Hello!

I have a similar problem. My code has stoped to work in notebook 5.0.0:

define([
    'base/js/namespace',
    'codemirror/keymap/sublime', // Это тоже js файл!
    'base/js/events'
    ], 
    function(IPython, sublime_keymap, events) {
        events.on("app_initialized.NotebookApp", 
            function () {
                console.log("Load settings for codemirror cells")
                var cell = require("notebook/js/cell").Cell;
                cell.options_default.cm_config.lineNumbers = true;
                cell.options_default.cm_config.keyMap = 'sublime';
                cell.options_default.cm_config.lineWrapping = true;
                cell.options_default.cm_config.autoCloseBrackets = true;
            }
        );
    }
);

How can I fix this?

@AndreWin
Copy link

Outside of events.on() my code will be run, but too late...

@takluyver
Copy link
Member

We should really have a promise for one-time events like this, so you can easily have code that waits for it, without worrying whether it already fired.

@scott-vsi
Copy link

Is there any workaround for this issue?

@takluyver
Copy link
Member

This is kind-of fixed by #2710 (coming in notebook 5.1). The idea is that code that was previously using the app_initialized event can now use a promise instead:

define([
        'base/js/namespace',
        'base/js/promises'
     ], function(Jupyter, promises) {
         promises.app_initialized.then(function(appname) {
             if (appname === 'NotebookApp') {
                 do_stuff()
             }
         });
     });

Unlike events, if the promise has already been resolved before you do this, then your code is run immediately. With events, it sits waiting for the event to fire again, which this one never does.

I think that's as solved as this is likely to get, so I'm going to close the issue.

@takluyver takluyver added this to the 5.1 milestone Aug 20, 2017
@didiercrunch
Copy link

It would be nice to update the documentation: https://github.com/jupyter/notebook/blob/4.0.x/notebook/static/custom/custom.js

@jason-s
Copy link

jason-s commented May 4, 2018

Is there a workaround for Jupyter 5.0? Anaconda doesn't seem to have anything newer.

You are using Jupyter notebook.

The version of the notebook server is 5.0.0 and is running on:
Python 2.7.14 |Anaconda, Inc.| (default, Oct 15 2017, 03:34:40) [MSC v.1500 64 bit (AMD64)]

@takluyver
Copy link
Member

It definitely should have newer versions that 5.0; we're up to 5.4.1 now, and Anaconda usually packages a new version within a few days of a release.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants