Skip to content

Commit

Permalink
docs: Update defer signature
Browse files Browse the repository at this point in the history
  • Loading branch information
skryukov committed Oct 19, 2024
1 parent b3da64f commit cd93fd3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
20 changes: 15 additions & 5 deletions docs/guide/deferred-props.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ class UsersController < ApplicationController
render inertia: 'Users/Index', props: {
users: -> { User.all },
roles: -> { Role.all },
permissions: InertiaRails.defer(-> { Permission.all }),
permissions: InertiaRails.defer { Permission.all },

# Also works with a lambda:
# permissions: InertiaRails.defer(-> { Permission.all }),

# Also works with a simple value,
# but this way the prop is always evaluated,
# even if not included:
# permissions: InertiaRails.defer(Permission.all),
}
end
end
Expand All @@ -28,10 +36,12 @@ class UsersController < ApplicationController
render inertia: 'Users/Index', props: {
users: -> { User.all },
roles: -> { Role.all },
permissions: InertiaRails.defer(-> { Permission.all }),
teams: InertiaRails.defer(-> { Team.all }, 'attributes'),
projects: InertiaRails.defer(-> { Project.all }, 'attributes'),
tasks: InertiaRails.defer(-> { Task.all }, 'attributes'),
permissions: InertiaRails.defer { Permission.all },
# using block:
teams: InertiaRails.defer(group: 'attributes') { Team.all },
# using lambda:
projects: InertiaRails.defer(-> { Project.all }, group: 'attributes'),
tasks: InertiaRails.defer(-> { Task.all }, group: 'attributes'),
}
end
end
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/merging-props.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class UsersController < ApplicationController

def index
render inertia: 'Users/Index', props: {
results: InertiaRails.defer(-> { pagy(User.all)[1] }).merge,
results: InertiaRails.defer { pagy(User.all)[1] }.merge,
}
end
end
Expand Down
18 changes: 16 additions & 2 deletions docs/guide/partial-reloads.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,15 @@ Additionally, Inertia provides an `InertiaRails.optional` method to specify that
class UsersController < ApplicationController
def index
render inertia: 'Users/Index', props: {
users: InertiaRails.optional(-> { User.all }),
users: InertiaRails.optional { User.all },

# Also works with a lambda:
# users: InertiaRails.optional(-> { User.all }),

# Also works with a simple value,
# but this way the prop is always evaluated,
# even if not included:
# users: InertiaRails.optional(User.all),
}
end
end
Expand All @@ -186,6 +194,12 @@ class UsersController < ApplicationController
def index
render inertia: 'Users/Index', props: {
users: InertiaRails.always(User.all),

# Also works with block:
# users: InertiaRails.optional { User.all },

# Also works with a lambda:
# users: InertiaRails.optional(-> { User.all }),
}
end
end
Expand All @@ -210,7 +224,7 @@ class UsersController < ApplicationController
# NEVER included on standard visits
# OPTIONALLY included on partial reloads
# ONLY evaluated when needed
users: InertiaRails.optional(-> { User.all }),
users: InertiaRails.optional { User.all },

# ALWAYS included on standard visits
# ALWAYS included on partial reloads
Expand Down

0 comments on commit cd93fd3

Please sign in to comment.