-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: store to use loader for storyfn
- Loading branch information
1 parent
839ae3e
commit 25adfb7
Showing
22 changed files
with
126 additions
and
409 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
node_modules/ | ||
.eslintcache | ||
dist | ||
docs | ||
.cache | ||
.rpt2_cache | ||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,51 @@ | ||
import { store } from './store'; | ||
|
||
module.exports = function() { | ||
const newContent = `export default ${JSON.stringify(store)};`; | ||
let imports = 'const imports = {};'; | ||
store.stores.forEach((store, storeIdx) => { | ||
imports = `${imports} ${Object.keys(store.kinds).map( | ||
(key, kindIdx) => | ||
`imports['i_${storeIdx}_${kindIdx}'] = require('${store.kinds[key].fileName}');\n`, | ||
)}`; | ||
}); | ||
const storeConst = `const store = ${JSON.stringify(store)};\n`; | ||
let loadStories = ` | ||
for (let i = 0; i < store.stores.length; i+= 1) { | ||
const s = store.stores[i]; | ||
const kinds = Object.keys(s.kinds); | ||
for (let j=0; j < kinds.length; j += 1) { | ||
const exports = imports[\`i_\${i}_\${j}\`]; | ||
const kind = s.kinds[kinds[j]]; | ||
try { | ||
Object.keys(exports).forEach(key => { | ||
const exported = exports[key]; | ||
if (key === 'default') { | ||
const { storySource, ...rest } = exported; | ||
Object.assign(kind, rest); | ||
} else { | ||
const story = s.stories[key]; | ||
if (story) { | ||
story.renderFn = exported; | ||
if (exported.story) { | ||
Object.assign(story, exported.story); | ||
} | ||
} | ||
} | ||
}); | ||
} catch (e) { | ||
console.error(\`unable to load module \${kind.moduleId}\`, e); | ||
} | ||
} | ||
} | ||
`; | ||
const exports = `export default store;\n`; | ||
const newContent = ` | ||
${imports} | ||
${storeConst} | ||
${loadStories} | ||
${exports} | ||
`; | ||
return newContent; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const merge = require('deepmerge'); | ||
|
||
const concatMerge = (dest: any[], src: any[]) => [...dest, ...src]; | ||
|
||
export const deepMerge = (a: any, b: any) => | ||
merge(a, b, { arrayMerge: concatMerge }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.