saberland/saber

Do you want to work on this issue?

You can request for a bounty in order to promote it!

Query data from any file #72

egoist posted onGitHub

<!-- Please don't delete this template or we'll close your issue -->

<!-- Before creating an issue please make sure you are using the latest version of Saber. -->

Feature request

<!-- Please ask questions via following several ways. -->

<!-- https://chat.saber.land/ -->

<!-- https://stackoverflow.com/questions/ask?tags=saberjs -->

What problem does this feature solve?

Allow users to pull data in components when they actually need it.

What does the proposed API look like?

Introducing the saber-data.js (supported in project-level and theme-level):

exports.allTagNames = () => ['foo', 'bar']

In a component:

<script>
import { allTagNames } from 'saber/data'

export default {
  data() {
    return { allTagNames }
  }
}
</script>

How should this be implemented in your opinion?

Convert this with a babel plugin:

import { allTagNames } from 'saber/data'

to:

import allTagNames from '#cache/data.js?name=allTagNames'

The content of #cache/data.js:

const saberData = Object.assign(
  require('/path/to/project/saber-data.js'),
  require('/path/to/theme/saber-data.js')
)

module.exports = name => {
  return saberData[name] && saberData[name]()
}

Add a webpack loader just for #cache/data.js:

const devalue = require('devalue')

module.exports = async function(source) {
    const done = this.async()
    const mod = runCodeInSandbox(source, this.resourcePath)
    const result = await mod(this.resourceQuery.name)
    return `export default ${devalue(result)}`
}

Are you willing to work on this yourself?

Yes.


@issuehunt has funded $80.00 to this issue.


posted by IssueHuntBot almost 6 years ago

Maybe close this in favor of #183

posted by egoist almost 6 years ago

@egoist Yes #183 seems much better if I am not mistaken you can simply do

exports.handler = { allTagNames: someValue }

inside ./functions/sharedData.js then requesting the data with

import { embedFunction } from 'saber/functions'

const posts = embedFunction('/sharedData.js')
posted by MarchWorks almost 6 years ago

@MarchWorks should be embedFunction('/sharedData') 😄, and exports.handler should be a function that returns the data.

#183 will also make #191 possible.

posted by egoist almost 6 years ago

@egoist It's absolutely great just need to be implemented 🎉

posted by MarchWorks almost 6 years ago

moved to #183

posted by krmax44 almost 6 years ago

Fund this Issue

$80.00
Funded
Only logged in users can fund an issue

Pull requests

Recent activities

marchworks submitted an output to  saberland/ saber# 72
almost 6 years ago
issuehunt funded 80.00 for egoist/saber# 72
almost 6 years ago