-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
this.visit is not a function (latest 0.8.4) #2
Comments
Might not be strange, it sounds like a plugin is being called on an object that isn't an instance of base. can you share more of your config? |
Sounds, but not or I can't see it here Docks.prototype.initDocks = function initApp () {
this.use(require('base-plugins')())
this.use(function extractComments (app) {
this.define('parse', function parse (input, options) {
if (typeof input === 'object') {
this.options = extend(this.options, input)
input = null
}
this.cache = extend({}, this.cache)
this.cache.input = input || this.input
this.options = extend({
preserve: false,
block: true,
line: false
}, this.options, options, {
locations: true,
unwrap: true
})
this.cache.comments = extract(this.cache.input, this.options).comments
var len = this.cache.comments.length
var idx = -1
while (++idx < len) {
// not so cool workaround,
// but we can't pass different than object currently
// waiting `use` PR
this.run({
current: this.cache.comments[idx],
index: idx,
next: this.cache.comments[idx + 1]
})
}
return this.cache.comments
})
})
return this
} |
try doing this: Docks.prototype.initDocks = function initApp () {
console.log(this.isApp)
this.use(require('base-plugins')())
this.use(function extractComments (app) {
console.log(this.isApp) |
It is |
Try doing the same with |
Actually, what's the case of these |
If this doesn't make sense, it's not you. it's hard to explain in words. But trust me it's worth the effort, I'd be happy to show other examples if it would help. Also, in your code, you should be able to move the Docks.prototype.initDocks = function initApp () {
this.use(require('base-plugins')())
this.define('parse', function parse (input, options) {
if (typeof input === 'object') {
this.options = extend(this.options, input)
input = null
}
this.cache = extend({}, this.cache)
this.cache.input = input || this.input
this.options = extend({
preserve: false,
block: true,
line: false
}, this.options, options, {
locations: true,
unwrap: true
})
this.cache.comments = extract(this.cache.input, this.options).comments
var len = this.cache.comments.length
var idx = -1
while (++idx < len) {
// not so cool workaround,
// but we can't pass different than object currently
// waiting `use` PR
this.run({
current: this.cache.comments[idx],
index: idx,
next: this.cache.comments[idx + 1]
})
}
return this.cache.comments
})
return this
} Hmm, I also see why you want to use If the |
ok so here is an example that might explain better in visuals (I can add to docs if you think this helps): function appPlugin(app) {
if (!isValid(app, 'plugin-name', ['app', 'collection'])) return;
// ^ ^
// isRegistered? | checks `isApp` and `isCollection`, e.g. is "this" a
// | valid "app" or "collection" instance?
}
function viewPlugin(view) {
if (!isValid(view, 'plugin-name', ['view'])) return;
// ^ ^
// isRegistered? | checks `isView`, e.g. is "this" a valid "view" instance?
} |
So, it seems i understand it correctly and it make sense, yea, definitely. Yea, I can define it directly with I can try to push something to repo in github this night. index.js var utils = require('./utils')
module.exports = function baseExtractComments (opts) {
return function extractComments (app) {
// i tried both is-valid-app and is-registered here as `isValid`
if (!utils.isValid(app, 'base-extract-comments')) return
this.use(utils.plugins())
this.define('extractComments', function parse (input, options) {
if (typeof input === 'object') {
this.options = utils.extend({}, this.options, input)
input = null
}
this.cache = utils.extend({}, this.cache)
this.cache.input = input || this.cache.input
this.options = utils.extend({
preserve: false,
block: true,
line: false
}, opts, this.options, options, {
locations: true,
unwrap: true
})
this.cache.comments = utils.extract(this.cache.input, this.options).comments
var len = this.cache.comments.length
var idx = -1
while (++idx < len) {
// not so cool workaround,
// but we can't pass different than object currently
// waiting `use` PR
this.run({
current: this.cache.comments[idx],
index: idx,
next: this.cache.comments[idx + 1]
})
}
return this.cache.comments
})
}
} and the test.js var Base = require('base')
var plugin = require('./index')
var app = new Base()
app.use(plugin())
app.use(function (app) {
return function (comment) {
comment = comment.current // workaround
console.log('comment:', comment)
}
})
// throws error if use `isValid` (no matter if it is `is-valid-app` or `is-registered`)
// if comment out the first if in plugin it works
app.extractComments(fs.readFileSync('./fixture.js', 'utf8'))
Yea make sense. |
Strange but L24 is empty, but yea, it is L29 currently.
That's strange, cuz there's
visit
method onbase
.The text was updated successfully, but these errors were encountered: