Git Product home page Git Product logo

Comments (7)

fregante avatar fregante commented on June 18, 2024 1

Ah yeah because _applyToForm is a static method. You can changed it to be a regular method and change its calls from OptionsSync._applyToForm to this._applyToForm

Also

- _log(method, list = []) {
+ _log(method, ...args) {

And

- this._log("info", ["Current options:", options]);
+ this._log('info', 'Current options:', options);

from webext-options-sync.

fregante avatar fregante commented on June 18, 2024

Makes sense! It can be added as an option to new OptionSync(key, {logging: false}) so it's shared across all the methods.

from webext-options-sync.

plibither8 avatar plibither8 commented on June 18, 2024

Yeah, that can be done too!

Should I create a PR for this? I have looked at code and I'm guessing it's a simple if (logging === true) check that we need to add before logging any info/warning to the console.

from webext-options-sync.

fregante avatar fregante commented on June 18, 2024

It's probably best to have an overridable logging function so we don't have to use if every time. Something like:

constructor(options) {
	this.storageName = options.storageName || 'options';
	if (options.logging === false) {
		this._log = () => {};
	}
}
_log() {
	console.log(...arguments);
}

from webext-options-sync.

plibither8 avatar plibither8 commented on June 18, 2024

Yes of course, much neater.

from webext-options-sync.

plibither8 avatar plibither8 commented on June 18, 2024

Hey, I'm having some trouble getting the _log function correctly called from other methods in the class. The constructor and log function:

constructor(options = {}) {
	this.storageName = options.storageName || 'options';
	if (options.logging === false) {
		this._log = () => {};
	}
}
	
_log(method, list = []) {
	console[method](...list);
}

and it should be called like so:

this._log("info", ["Current options:", options]);

However, I'm getting the following TypeError when trying it on an extension of my own locally:

Uncaught (in promise) TypeError: this._log is not a function
    at Function._applyToForm (content.js:188)

I'm guessing it's got to do with the scope of this changing, but I'm not sure.

from webext-options-sync.

plibither8 avatar plibither8 commented on June 18, 2024

Thanks! Please publish to npm too ☺️

from webext-options-sync.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.