-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stories are loaded the same as Storybooks (#7)
# Problem The `loadStorybookModule` function works a bit differently from `loadStory` in that it will throw on any issues. `loadStory` should do the same for consistency # Solution I've updated the API to remove `loadStory` in favor of `loadStoryModule` which functions the same as `loadStorybookModule` I also was given a vision that made it clear how to handle Hoarcekat stories, so those work now in our e2e suite too
- Loading branch information
Showing
7 changed files
with
47 additions
and
98 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
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 |
---|---|---|
|
@@ -8,7 +8,7 @@ rojo = "rojo-rbx/[email protected]" | |
selene = "Kampfkarren/[email protected]" | ||
StyLua = "JohnnyMorganz/[email protected]" | ||
wally = "UpliftGames/[email protected]" | ||
luau-lsp = "JohnnyMorganz/luau-lsp@1.33.1" | ||
luau-lsp = "JohnnyMorganz/luau-lsp@1.34.0" | ||
wally-package-types = "JohnnyMorganz/[email protected]" | ||
lune = "lune-org/[email protected]" | ||
darklua = "seaofvoices/[email protected]" | ||
|
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 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,53 +1,49 @@ | ||
local ModuleLoader = require("@pkg/ModuleLoader") | ||
local Sift = require("@pkg/Sift") | ||
|
||
local constants = require("@root/constants") | ||
local types = require("@root/types") | ||
|
||
local Errors = { | ||
MalformedStory = "Story is malformed. Check the source of %q and make sure its properties are correct", | ||
Generic = "Failed to load story %q. Error: %s", | ||
} | ||
type Storybook = types.Storybook | ||
type Story<T> = types.Story<T> | ||
|
||
local function loadStoryModule<T>( | ||
loader: ModuleLoader.ModuleLoader, | ||
storyModule: ModuleScript, | ||
storybook: types.Storybook | ||
): (types.Story<T>?, string?) | ||
storybook: Storybook | ||
): Story<T> | ||
local success, result = pcall(function() | ||
return loader:require(storyModule) | ||
end) | ||
|
||
if not success then | ||
return nil, Errors.Generic:format(storyModule:GetFullName(), tostring(result)) | ||
error(`Failed to load story {storyModule:GetFullName()}. Error: {result})`) | ||
end | ||
|
||
local story: types.Story<T> | ||
-- Support for Hoarcekat stories | ||
if typeof(result) == "function" then | ||
story = { | ||
name = storyModule.Name, | ||
story = result, | ||
storybook = storybook, | ||
source = storyModule, | ||
local callback = result | ||
result = { | ||
story = function(props) | ||
return callback(props.container, props) | ||
end, | ||
} | ||
else | ||
local isValid, message = types.IStory(result) | ||
|
||
if isValid then | ||
story = Sift.Dictionary.merge({ | ||
name = storyModule.Name, | ||
storybook = storybook, | ||
source = storyModule, | ||
}, result) | ||
else | ||
return nil, Errors.Generic:format(storyModule:GetFullName(), message) | ||
end | ||
end | ||
|
||
if story then | ||
return story, nil | ||
else | ||
return nil, Errors.MalformedStory:format(storyModule:GetFullName()) | ||
local isValid, message = types.IStory(result) | ||
|
||
if not isValid then | ||
error( | ||
`Story is malformed. Check the source of {storyModule:GetFullName()} and make sure its properties are ` | ||
.. `correct. Error: {message}` | ||
) | ||
end | ||
|
||
return Sift.Dictionary.merge({ | ||
name = storyModule.Name:gsub(constants.STORY_NAME_PATTERN, ""), | ||
storybook = storybook, | ||
source = storyModule, | ||
}, result) | ||
end | ||
|
||
return loadStoryModule |
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